GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [SYSTEMDS-418] Performance improvements lineage reuse probing/spilling · apache/systemds@1abe9cb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/org/apache/sysds/runtime
    • controlprogram
      • ProgramBlock.java
    • lineage
      • LineageCache.java
      • LineageCacheConfig.java
      • LineageCacheEntry.java
      • LineageCacheEviction.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/org/apache/sysds/runtime/controlprogram/ProgramBlock.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/apache/sysds/runtime/controlprogram/ProgramBlock.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private void executeSingleInstruction( Instruction currInst, ExecutionContext ec
247247
tmp.processInstruction(ec);
248248

249249
// cache result
250-
LineageCache.putValue(tmp, ec, System.nanoTime()-et0);
250+
LineageCache.putValue(tmp, ec, et0);
251251

252252
// post-process instruction (debug)
253253
tmp.postprocessInstruction( ec );
Collapse file

‎src/main/java/org/apache/sysds/runtime/lineage/LineageCache.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/apache/sysds/runtime/lineage/LineageCache.java
+28-20Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.apache.sysds.runtime.lineage;
2121

22+
import org.apache.commons.lang3.tuple.MutablePair;
23+
import org.apache.commons.lang3.tuple.Pair;
2224
import org.apache.sysds.api.DMLScript;
2325
import org.apache.sysds.common.Types.DataType;
2426
import org.apache.sysds.common.Types.FileFormat;
@@ -45,6 +47,8 @@
4547
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
4648
import org.apache.sysds.runtime.meta.MetaDataFormat;
4749

50+
import java.util.ArrayList;
51+
import java.util.Arrays;
4852
import java.util.HashMap;
4953
import java.util.List;
5054
import java.util.Map;
@@ -81,39 +85,40 @@ public static boolean reuse(Instruction inst, ExecutionContext ec) {
8185
if (LineageCacheConfig.isReusable(inst, ec)) {
8286
ComputationCPInstruction cinst = (ComputationCPInstruction) inst;
8387
LineageItem instLI = cinst.getLineageItem(ec).getValue();
84-
HashMap<LineageItem, LineageCacheEntry> liMap = new HashMap<>();
88+
List<MutablePair<LineageItem, LineageCacheEntry>> liList = null;
8589
if (inst instanceof MultiReturnBuiltinCPInstruction) {
90+
liList = new ArrayList<>();
8691
MultiReturnBuiltinCPInstruction mrInst = (MultiReturnBuiltinCPInstruction)inst;
8792
for (int i=0; i<mrInst.getNumOutputs(); i++) {
8893
String opcode = instLI.getOpcode() + String.valueOf(i);
89-
liMap.put(new LineageItem(opcode, instLI.getInputs()), null);
94+
liList.add(MutablePair.of(new LineageItem(opcode, instLI.getInputs()), null));
9095
}
9196
}
9297
else
93-
liMap.put(instLI, null);
98+
liList = Arrays.asList(MutablePair.of(instLI, null));
9499

95100
//atomic try reuse full/partial and set placeholder, without
96101
//obtaining value to avoid blocking in critical section
97102
LineageCacheEntry e = null;
98103
boolean reuseAll = true;
99104
synchronized( _cache ) {
100105
//try to reuse full or partial intermediates
101-
for (LineageItem item : liMap.keySet()) {
106+
for (MutablePair<LineageItem,LineageCacheEntry> item : liList) {
102107
if (LineageCacheConfig.getCacheType().isFullReuse())
103-
e = LineageCache.probe(item) ? getIntern(item) : null;
108+
e = LineageCache.probe(item.getKey()) ? getIntern(item.getKey()) : null;
104109
//TODO need to also move execution of compensation plan out of here
105110
//(create lazily evaluated entry)
106111
if (e == null && LineageCacheConfig.getCacheType().isPartialReuse())
107112
if( LineageRewriteReuse.executeRewrites(inst, ec) )
108-
e = getIntern(item);
113+
e = getIntern(item.getKey());
109114
//TODO: MultiReturnBuiltin and partial rewrites
110115
reuseAll &= (e != null);
111-
liMap.put(item, e);
116+
item.setValue(e);
112117

113118
//create a placeholder if no reuse to avoid redundancy
114119
//(e.g., concurrent threads that try to start the computation)
115120
if(e == null && isMarkedForCaching(inst, ec)) {
116-
putIntern(item, cinst.output.getDataType(), null, null, 0);
121+
putIntern(item.getKey(), cinst.output.getDataType(), null, null, 0);
117122
//FIXME: different o/p datatypes for MultiReturnBuiltins.
118123
}
119124
}
@@ -122,7 +127,7 @@ public static boolean reuse(Instruction inst, ExecutionContext ec) {
122127

123128
if(reuse) { //reuse
124129
//put reuse value into symbol table (w/ blocking on placeholders)
125-
for (Map.Entry<LineageItem, LineageCacheEntry> entry : liMap.entrySet()) {
130+
for (MutablePair<LineageItem, LineageCacheEntry> entry : liList) {
126131
e = entry.getValue();
127132
String outName = null;
128133
if (inst instanceof MultiReturnBuiltinCPInstruction)
@@ -243,39 +248,42 @@ public static void putMatrix(Instruction inst, ExecutionContext ec, long compute
243248
}
244249
}
245250

246-
public static void putValue(Instruction inst, ExecutionContext ec, long computetime) {
251+
public static void putValue(Instruction inst, ExecutionContext ec, long starttime) {
247252
if (ReuseCacheType.isNone())
248253
return;
254+
long computetime = System.nanoTime() - starttime;
249255
if (LineageCacheConfig.isReusable(inst, ec) ) {
250256
//if (!isMarkedForCaching(inst, ec)) return;
251-
HashMap<LineageItem, Data> liDataMap = new HashMap<>();
257+
List<Pair<LineageItem, Data>> liData = null;
252258
LineageItem instLI = ((LineageTraceable) inst).getLineageItem(ec).getValue();
253259
if (inst instanceof MultiReturnBuiltinCPInstruction) {
260+
liData = new ArrayList<>();
254261
MultiReturnBuiltinCPInstruction mrInst = (MultiReturnBuiltinCPInstruction)inst;
255262
for (int i=0; i<mrInst.getNumOutputs(); i++) {
256263
String opcode = instLI.getOpcode() + String.valueOf(i);
257264
LineageItem li = new LineageItem(opcode, instLI.getInputs());
258265
Data value = ec.getVariable(mrInst.getOutput(i));
259-
liDataMap.put(li, value);
266+
liData.add(Pair.of(li, value));
260267
}
261268
}
262269
else
263-
liDataMap.put(instLI, ec.getVariable(((ComputationCPInstruction) inst).output));
270+
liData = Arrays.asList(Pair.of(instLI, ec.getVariable(((ComputationCPInstruction) inst).output)));
264271
synchronized( _cache ) {
265-
for (Map.Entry<LineageItem, Data> entry : liDataMap.entrySet()) {
272+
for (Pair<LineageItem, Data> entry : liData) {
266273
LineageItem item = entry.getKey();
267274
Data data = entry.getValue();
275+
LineageCacheEntry centry = _cache.get(item);
268276
if (data instanceof MatrixObject)
269-
_cache.get(item).setValue(((MatrixObject)data).acquireReadAndRelease(), computetime);
277+
centry.setValue(((MatrixObject)data).acquireReadAndRelease(), computetime);
270278
else if (data instanceof ScalarObject)
271-
_cache.get(item).setValue((ScalarObject)data, computetime);
279+
centry.setValue((ScalarObject)data, computetime);
272280
else
273281
throw new DMLRuntimeException("Lineage Cache: unsupported data: "+data.getDataType());
274282

275283
//maintain order for eviction
276-
LineageCacheEviction.addEntry(_cache.get(item));
284+
LineageCacheEviction.addEntry(centry);
277285

278-
long size = _cache.get(item).getSize();
286+
long size = centry.getSize();
279287
if (!LineageCacheEviction.isBelowThreshold(size))
280288
LineageCacheEviction.makeSpace(_cache, size);
281289
LineageCacheEviction.updateSize(size, true);
@@ -284,8 +292,8 @@ else if (data instanceof ScalarObject)
284292
}
285293
}
286294

287-
public static void putValue(List<DataIdentifier> outputs, LineageItem[] liInputs,
288-
String name, ExecutionContext ec, long computetime)
295+
public static void putValue(List<DataIdentifier> outputs,
296+
LineageItem[] liInputs, String name, ExecutionContext ec, long computetime)
289297
{
290298
if (!LineageCacheConfig.isMultiLevelReuse())
291299
return;
Collapse file

‎src/main/java/org/apache/sysds/runtime/lineage/LineageCacheConfig.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/apache/sysds/runtime/lineage/LineageCacheConfig.java
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private enum CachedItemTail {
9999

100100
private static LineageCachePolicy _cachepolicy = null;
101101
// Weights for scoring components (computeTime/size, LRU timestamp)
102-
private static double[] WEIGHTS = {0, 1};
102+
protected static double[] WEIGHTS = {0, 1};
103103

104104
protected enum LineageCacheStatus {
105105
EMPTY, //Placeholder with no data. Cannot be evicted.
@@ -121,14 +121,9 @@ public enum LineageCachePolicy {
121121
}
122122

123123
protected static Comparator<LineageCacheEntry> LineageCacheComparator = (e1, e2) -> {
124-
// Gather the weights for scoring components
125-
double w1 = LineageCacheConfig.WEIGHTS[0];
126-
double w2 = LineageCacheConfig.WEIGHTS[1];
127-
// Generate scores
128-
double score1 = w1*(((double)e1._computeTime)/e1.getSize()) + w2*e1.getTimestamp();
129-
double score2 = w1*((double)e2._computeTime)/e2.getSize() + w2*e2.getTimestamp();
130-
// Generate order. If scores are same, order by LineageItem ID.
131-
return score1 == score2 ? Long.compare(e1._key.getId(), e2._key.getId()) : score1 < score2 ? -1 : 1;
124+
return e1.score == e2.score ?
125+
Long.compare(e1._key.getId(), e2._key.getId()) :
126+
e1.score < e2.score ? -1 : 1;
132127
};
133128

134129
//----------------------------------------------------------------//
Collapse file

‎src/main/java/org/apache/sysds/runtime/lineage/LineageCacheEntry.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/apache/sysds/runtime/lineage/LineageCacheEntry.java
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class LineageCacheEntry {
3535
protected LineageCacheStatus _status;
3636
protected LineageCacheEntry _nextEntry;
3737
protected LineageItem _origItem;
38+
protected double score;
3839

3940
public LineageCacheEntry(LineageItem key, DataType dt, MatrixBlock Mval, ScalarObject Sval, long computetime) {
4041
_key = key;
@@ -123,9 +124,18 @@ protected synchronized void setNullValues() {
123124

124125
protected synchronized void setTimestamp() {
125126
_timestamp = System.currentTimeMillis();
127+
recomputeScore();
126128
}
127129

128130
protected synchronized long getTimestamp() {
129131
return _timestamp;
130132
}
133+
134+
private void recomputeScore() {
135+
// Gather the weights for scoring components
136+
double w1 = LineageCacheConfig.WEIGHTS[0];
137+
double w2 = LineageCacheConfig.WEIGHTS[1];
138+
// Generate scores
139+
score = w1*(((double)_computeTime)/getSize()) + w2*getTimestamp();
140+
}
131141
}
Collapse file

‎src/main/java/org/apache/sysds/runtime/lineage/LineageCacheEviction.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/apache/sysds/runtime/lineage/LineageCacheEviction.java
+7-13Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.HashSet;
2525
import java.util.Map;
26+
import java.util.Set;
2627
import java.util.TreeSet;
2728

2829
import org.apache.sysds.api.DMLScript;
@@ -36,7 +37,7 @@ public class LineageCacheEviction
3637
{
3738
private static long _cachesize = 0;
3839
private static long CACHE_LIMIT; //limit in bytes
39-
protected static final HashSet<LineageItem> _removelist = new HashSet<>();
40+
protected static final Set<LineageItem> _removelist = new HashSet<>();
4041
private static final Map<LineageItem, SpilledItem> _spillList = new HashMap<>();
4142
private static String _outdir = null;
4243
private static TreeSet<LineageCacheEntry> weightedQueue = new TreeSet<>(LineageCacheConfig.LineageCacheComparator);
@@ -202,8 +203,6 @@ protected static void makeSpace(Map<LineageItem, LineageCacheEntry> cache, long
202203
//TODO: Graceful handling of status.
203204
}
204205

205-
double exectime = ((double) e._computeTime) / 1000000; // in milliseconds
206-
207206
if (!e.isMatrixValue()) {
208207
// No spilling for scalar entries. Just delete those.
209208
// Note: scalar entries with higher computation time are pinned.
@@ -213,6 +212,7 @@ protected static void makeSpace(Map<LineageItem, LineageCacheEntry> cache, long
213212

214213
// Estimate time to write to FS + read from FS.
215214
double spilltime = getDiskSpillEstimate(e) * 1000; // in milliseconds
215+
double exectime = ((double) e._computeTime) / 1000000; // in milliseconds
216216

217217
if (LineageCache.DEBUG) {
218218
if (exectime > LineageCacheConfig.MIN_SPILL_TIME_ESTIMATE) {
@@ -227,19 +227,13 @@ protected static void makeSpace(Map<LineageItem, LineageCacheEntry> cache, long
227227
if (spilltime < LineageCacheConfig.MIN_SPILL_TIME_ESTIMATE) {
228228
// Can't trust the estimate if less than 100ms.
229229
// Spill if it takes longer to recompute.
230-
if (exectime >= LineageCacheConfig.MIN_SPILL_TIME_ESTIMATE)
231-
//spillToLocalFS(e);
232-
removeOrSpillEntry(cache, e, true); //spill
233-
else
234-
removeOrSpillEntry(cache, e, false); //delete
230+
removeOrSpillEntry(cache, e, //spill or delete
231+
exectime >= LineageCacheConfig.MIN_SPILL_TIME_ESTIMATE);
235232
}
236233
else {
237234
// Spill if it takes longer to recompute than spilling.
238-
if (exectime > spilltime)
239-
//spillToLocalFS(e);
240-
removeOrSpillEntry(cache, e, true); //spill
241-
else
242-
removeOrSpillEntry(cache, e, false); //delete
235+
removeOrSpillEntry(cache, e, //spill or delete
236+
exectime > spilltime);
243237
}
244238
}
245239
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.