-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYSTEMDS-3805] Rewrite and runtime for scalar right indexing
This patch adds a new rewrite, as well as modifies existing rewrites and runtime instructions in order to perform scalar right indexing for operations like as.scalar(X[i,1]) which avoids unnecessary createvar and cast instructions. On a scenario of running the baseline (non-vectorized) exponential smoothing on 10M data points, the patch improved end-to-end performance from from 22.3s to 12.2s (6.7s without statistics time measurements). alpha = 0.05 r = as.scalar(X[1, 1]) for(i in 2:nrow(X)) { r = alpha * as.scalar(X[i, 1]) + (1-alpha) * r } Total elapsed time: 22.348 sec. Total compilation time: 0.516 sec. Total execution time: 21.832 sec. Cache hits (Mem/Li/WB/FS/HDFS): 20000000/0/0/0/0. Cache writes (Li/WB/FS/HDFS): 1/0/0/0. Cache times (ACQr/m, RLS, EXP): 0.777/0.432/1.124/0.000 sec. HOP DAGs recompiled (PRED, SB): 0/0. HOP DAGs recompile time: 0.300 sec. Functions recompiled: 1. Functions recompile time: 0.002 sec. Total JIT compile time: 2.608 sec. Total JVM GC count: 1. Total JVM GC time: 0.018 sec. Heavy hitter instructions: 1 rightIndex 4.894 10000000 2 createvar 3.585 10000001 3 rmvar 2.848 30000000 4 castdts 2.242 10000000 5 * 1.742 19999998 6 + 0.898 9999999 7 mvvar 0.751 10000002 8 rand 0.213 1 9 - 0.016 1 10 print 0.000 1 11 assignvar 0.000 2 Total elapsed time: 12.589 sec. Total compilation time: 0.520 sec. Total execution time: 12.069 sec. Cache hits (Mem/Li/WB/FS/HDFS): 10000000/0/0/0/0. Cache writes (Li/WB/FS/HDFS): 1/0/0/0. Cache times (ACQr/m, RLS, EXP): 0.455/0.000/0.463/0.000 sec. HOP DAGs recompiled (PRED, SB): 0/0. HOP DAGs recompile time: 0.313 sec. Functions recompiled: 1. Functions recompile time: 0.002 sec. Total JIT compile time: 1.923 sec. Total JVM GC count: 1. Total JVM GC time: 0.011 sec. Heavy hitter instructions: 1 rightIndex 3.046 10000000 2 * 1.876 19999998 3 rmvar 1.450 20000000 4 + 0.954 9999999 5 mvvar 0.801 10000002 6 rand 0.213 1 7 - 0.018 1 8 print 0.000 1 9 createvar 0.000 1 10 assignvar 0.000 2
- Loading branch information
Showing
11 changed files
with
220 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/test/java/org/apache/sysds/test/functions/rewrite/RewriteScalarRightIndexingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.sysds.test.functions.rewrite; | ||
|
||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import org.apache.sysds.common.Types.ExecMode; | ||
import org.apache.sysds.common.Types.ExecType; | ||
import org.apache.sysds.hops.OptimizerUtils; | ||
import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex; | ||
import org.apache.sysds.test.AutomatedTestBase; | ||
import org.apache.sysds.test.TestConfiguration; | ||
import org.apache.sysds.utils.Statistics; | ||
|
||
public class RewriteScalarRightIndexingTest extends AutomatedTestBase | ||
{ | ||
private final static String TEST_DIR = "functions/rewrite/"; | ||
private final static String TEST_NAME = "RewriteScalarRightIndexing"; | ||
|
||
private final static String TEST_CLASS_DIR = TEST_DIR + RewriteScalarRightIndexingTest.class.getSimpleName() + "/"; | ||
|
||
private final static int rows = 122; | ||
|
||
@Override | ||
public void setUp() { | ||
addTestConfiguration(TEST_NAME, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] {"A"})); | ||
} | ||
|
||
@Test | ||
public void testScalarRightIndexingCP() { | ||
runScalarRightIndexing(true, ExecType.CP); | ||
} | ||
|
||
@Test | ||
public void testScalarRightIndexingNoRewriteCP() { | ||
runScalarRightIndexing(false, ExecType.CP); | ||
} | ||
|
||
@Test | ||
public void testScalarRightIndexingSpark() { | ||
runScalarRightIndexing(true, ExecType.SPARK); | ||
} | ||
|
||
@Test | ||
public void testScalarRightIndexingNoRewriteSpark() { | ||
runScalarRightIndexing(false, ExecType.SPARK); | ||
} | ||
|
||
private void runScalarRightIndexing(boolean rewrite, ExecType instType) { | ||
ExecMode platformOld = setExecMode(instType); | ||
boolean flagOld = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION; | ||
try { | ||
TestConfiguration config = getTestConfiguration(TEST_NAME); | ||
loadTestConfiguration(config); | ||
OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrite; | ||
|
||
String HOME = SCRIPT_DIR + TEST_DIR; | ||
fullDMLScriptName = HOME + TEST_NAME + ".dml"; | ||
programArgs = new String[]{"-explain", "-stats", "-args", | ||
Long.toString(rows), output("A")}; | ||
runTest(true, false, null, -1); | ||
|
||
Double ret = readDMLScalarFromOutputDir("A").get(new CellIndex(1,1)); | ||
Assert.assertEquals(Double.valueOf(103.0383), ret, 1e-4); | ||
if(rewrite) //w/o rewrite 122 casts | ||
Assert.assertTrue(Statistics.getCPHeavyHitterCount("castdts")<=1); | ||
} | ||
finally { | ||
resetExecMode(platformOld); | ||
OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = flagOld; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/scripts/functions/rewrite/RewriteScalarRightIndexing.dml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#------------------------------------------------------------- | ||
# | ||
# 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. | ||
# | ||
#------------------------------------------------------------- | ||
|
||
|
||
nrow = $1; | ||
X = seq(1, nrow); | ||
|
||
alpha = 0.05 | ||
|
||
r = as.scalar(X[1, 1]) | ||
for(i in 2:nrow(X)) { | ||
r = alpha * as.scalar(X[i, 1]) + (1-alpha) * r | ||
} | ||
|
||
write(r, $2); | ||
|