Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.sysds.runtime.lineage.Lineage;
import org.apache.sysds.runtime.lineage.LineageCacheConfig;
import org.apache.sysds.runtime.lineage.LineageCacheConfig.ReuseCacheType;
import org.apache.sysds.runtime.lineage.LineageCacheEviction;
import org.apache.sysds.runtime.lineage.LineageCacheStatistics;
import org.apache.sysds.runtime.matrix.data.MatrixValue;
import org.apache.sysds.test.TestConfiguration;
Expand All @@ -42,7 +41,7 @@
public class CacheEvictionTest extends LineageBase {

protected static final String TEST_DIR = "functions/lineage/";
protected static final String TEST_NAME1 = "CacheEviction1";
protected static final String TEST_NAME1 = "CacheEviction2";

protected String TEST_CLASS_DIR = TEST_DIR + CacheEvictionTest.class.getSimpleName() + "/";

Expand Down Expand Up @@ -84,8 +83,9 @@ public void runTest(String testname) {
getAndLoadTestConfiguration(testname);
fullDMLScriptName = getScript();
Lineage.resetInternalState();
long cacheSize = LineageCacheEviction.getCacheLimit();
LineageCacheConfig.setReusableOpcodes("exp", "+", "round");
//long cacheSize = LineageCacheEviction.getCacheLimit();
//LineageCacheConfig.setReusableOpcodes("exp", "+", "round");
LineageCacheConfig.setSpill(false);

// LRU based eviction
List<String> proArgs = new ArrayList<>();
Expand All @@ -94,14 +94,15 @@ public void runTest(String testname) {
proArgs.add(ReuseCacheType.REUSE_FULL.name().toLowerCase());
proArgs.add("policy_lru");
proArgs.add("-args");
proArgs.add(String.valueOf(cacheSize));
//proArgs.add(String.valueOf(cacheSize));
proArgs.add(output("R"));
programArgs = proArgs.toArray(new String[proArgs.size()]);
runTest(true, EXCEPTION_NOT_EXPECTED, null, -1);
HashMap<MatrixValue.CellIndex, Double> R_lru = readDMLMatrixFromOutputDir("R");
long expCount_lru = Statistics.getCPHeavyHitterCount("exp");
//long expCount_lru = Statistics.getCPHeavyHitterCount("exp");
long hitCount_lru = LineageCacheStatistics.getInstHits();
long evictedCount_lru = LineageCacheStatistics.getMemDeletes();
//long evictedCount_lru = LineageCacheStatistics.getMemDeletes();
long colmeanCount_lru = Statistics.getCPHeavyHitterCount("uacmean");

// costnsize scheme (computationTime/Size)
proArgs.clear();
Expand All @@ -110,35 +111,41 @@ public void runTest(String testname) {
proArgs.add(ReuseCacheType.REUSE_FULL.name().toLowerCase());
proArgs.add("policy_costnsize");
proArgs.add("-args");
proArgs.add(String.valueOf(cacheSize));
//proArgs.add(String.valueOf(cacheSize));
proArgs.add(output("R"));
programArgs = proArgs.toArray(new String[proArgs.size()]);
Lineage.resetInternalState();
runTest(true, EXCEPTION_NOT_EXPECTED, null, -1);
HashMap<MatrixValue.CellIndex, Double> R_costnsize= readDMLMatrixFromOutputDir("R");
long expCount_wt = Statistics.getCPHeavyHitterCount("exp");
long hitCount_wt = LineageCacheStatistics.getInstHits();
long evictedCount_wt = LineageCacheStatistics.getMemDeletes();
LineageCacheConfig.resetReusableOpcodes();
//long expCount_wt = Statistics.getCPHeavyHitterCount("exp");
long hitCount_cs = LineageCacheStatistics.getInstHits();
//long evictedCount_wt = LineageCacheStatistics.getMemDeletes();
//LineageCacheConfig.resetReusableOpcodes();
long colmeanCount_cs = Statistics.getCPHeavyHitterCount("uacmean");

// Compare results
Lineage.setLinReuseNone();
TestUtils.compareMatrices(R_lru, R_costnsize, 1e-6, "LRU", "costnsize");

// Compare reused instructions
Assert.assertTrue(expCount_lru >= expCount_wt);
//Assert.assertTrue(expCount_lru >= expCount_wt);
// Compare counts of evicted items
// LRU tends to evict more entries to recover equal amount of memory
// Note: changed to equals to fix flaky tests where both are not evicted at all
// (e.g., due to high execution time as sometimes observed through github actions)
Assert.assertTrue(("Violated expected evictions: "+evictedCount_lru+" >= "+evictedCount_wt),
evictedCount_lru >= evictedCount_wt);
//Assert.assertTrue(("Violated expected evictions: "+evictedCount_lru+" >= "+evictedCount_wt),
// evictedCount_lru >= evictedCount_wt);
// Compare cache hits
Assert.assertTrue(hitCount_lru < hitCount_wt);
Assert.assertTrue("Violated cache hit count: "+hitCount_lru+" < "+hitCount_cs,
hitCount_lru < hitCount_cs);
//Assert.assertTrue(hitCount_lru < hitCount_dh);
Assert.assertTrue("Violated uacmean count: "+colmeanCount_cs+" < "+colmeanCount_lru,
colmeanCount_cs < colmeanCount_lru);
}
finally {
OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = old_simplification;
OptimizerUtils.ALLOW_SUM_PRODUCT_REWRITES = old_sum_product;
LineageCacheConfig.setSpill(true);
Recompiler.reinitRecompiler();
}
}
Expand Down
61 changes: 61 additions & 0 deletions src/test/scripts/functions/lineage/CacheEviction2.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#-------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#-------------------------------------------------------------

D = rand(rows=6400, cols=784, min=0, max=20, seed=42)
bs = 32;
ep = 10;
iter_ep = ceil(nrow(D)/bs);
maxiter = ep * iter_ep;
beg = 1;
iter = 0;
i = 1;

while (iter < maxiter) {
end = beg + bs - 1;
if (end>nrow(D))
end = nrow(D);
X = D[beg:end,]

#reusable OP across epochs
X = scale(X, TRUE, TRUE);
#pollute cache with not reusable OPs
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)
X = ((X + X) * i - X) / (i+1)

iter = iter + 1;
if (end == nrow(D))
beg = 1;
else
beg = end + 1;
i = i + 1;

}
R = X;
write(R, $1, format="text");