Repository: incubator-systemml Updated Branches: refs/heads/master 48a7267f8 -> 4cbb02819
[SYSTEMML-845] Improved dynamic recompile size propagation (mod, intdiv) Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/4cbb0281 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/4cbb0281 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/4cbb0281 Branch: refs/heads/master Commit: 4cbb028190b1fc67565d6ddd71dcd71a51df1d30 Parents: 48a7267 Author: Matthias Boehm <[email protected]> Authored: Sun Aug 28 21:11:27 2016 +0200 Committer: Matthias Boehm <[email protected]> Committed: Sun Aug 28 22:20:14 2016 +0200 ---------------------------------------------------------------------- .../java/org/apache/sysml/hops/OptimizerUtils.java | 8 ++++++++ .../runtime/functionobjects/IntegerDivide.java | 2 +- .../sysml/runtime/functionobjects/Modulus.java | 4 ++-- .../runtime/instructions/InstructionUtils.java | 16 ++++++++-------- .../binary/matrix/ElementwiseModulusTest.java | 6 +++--- .../functions/binary/matrix/ScalarModulusTest.java | 12 ++++++------ 6 files changed, 28 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4cbb0281/src/main/java/org/apache/sysml/hops/OptimizerUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/OptimizerUtils.java b/src/main/java/org/apache/sysml/hops/OptimizerUtils.java index 52ee378..6111830 100644 --- a/src/main/java/org/apache/sysml/hops/OptimizerUtils.java +++ b/src/main/java/org/apache/sysml/hops/OptimizerUtils.java @@ -41,6 +41,8 @@ import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.controlprogram.LocalVariableMap; import org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext; import org.apache.sysml.runtime.controlprogram.parfor.stat.InfrastructureAnalyzer; +import org.apache.sysml.runtime.functionobjects.IntegerDivide; +import org.apache.sysml.runtime.functionobjects.Modulus; import org.apache.sysml.runtime.instructions.cp.Data; import org.apache.sysml.runtime.instructions.cp.ScalarObject; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; @@ -1423,6 +1425,9 @@ public class OptimizerUtils case MIN: ret = Math.min(lret, rret); break; case MAX: ret = Math.max(lret, rret); break; case POW: ret = Math.pow(lret, rret); break; + //special mod / inddiv for runtime consistency + case MODULUS: ret = Modulus.getFnObject().execute(lret, rret); break; + case INTDIV: ret = IntegerDivide.getFnObject().execute(lret, rret); break; default: ret = Double.MAX_VALUE; } } @@ -1464,6 +1469,9 @@ public class OptimizerUtils case MIN: ret = Math.min(lret, rret); break; case MAX: ret = Math.max(lret, rret); break; case POW: ret = Math.pow(lret, rret); break; + //special mod / inddiv for runtime consistency + case MODULUS: ret = Modulus.getFnObject().execute(lret, rret); break; + case INTDIV: ret = IntegerDivide.getFnObject().execute(lret, rret); break; default: ret = Double.MAX_VALUE; } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4cbb0281/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java b/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java index 03b8d57..e3806f4 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java @@ -32,7 +32,7 @@ public class IntegerDivide extends ValueFunction // nothing to do here } - public static IntegerDivide getIntegerDivideFnObject() { + public static IntegerDivide getFnObject() { if ( singleObj == null ) singleObj = new IntegerDivide(); return singleObj; http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4cbb0281/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java index e86e2ff..2dc134a 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java @@ -36,10 +36,10 @@ public class Modulus extends ValueFunction private IntegerDivide _intdiv = null; private Modulus() { - _intdiv = IntegerDivide.getIntegerDivideFnObject(); + _intdiv = IntegerDivide.getFnObject(); } - public static Modulus getModulusFnObject() { + public static Modulus getFnObject() { if ( singleObj == null ) singleObj = new Modulus(); return singleObj; http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4cbb0281/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java b/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java index a3a7c08..1e40b93 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java @@ -617,9 +617,9 @@ public class InstructionUtils else if(opcode.equalsIgnoreCase("/")) return new BinaryOperator(Divide.getDivideFnObject()); else if(opcode.equalsIgnoreCase("%%")) - return new BinaryOperator(Modulus.getModulusFnObject()); + return new BinaryOperator(Modulus.getFnObject()); else if(opcode.equalsIgnoreCase("%/%")) - return new BinaryOperator(IntegerDivide.getIntegerDivideFnObject()); + return new BinaryOperator(IntegerDivide.getFnObject()); else if(opcode.equalsIgnoreCase("^")) return new BinaryOperator(Power.getPowerFnObject()); else if ( opcode.equalsIgnoreCase("^2") ) @@ -689,13 +689,13 @@ public class InstructionUtils } else if ( opcode.equalsIgnoreCase("%%") ) { if(arg1IsScalar) - return new LeftScalarOperator(Modulus.getModulusFnObject(), constant); - else return new RightScalarOperator(Modulus.getModulusFnObject(), constant); + return new LeftScalarOperator(Modulus.getFnObject(), constant); + else return new RightScalarOperator(Modulus.getFnObject(), constant); } else if ( opcode.equalsIgnoreCase("%/%") ) { if(arg1IsScalar) - return new LeftScalarOperator(IntegerDivide.getIntegerDivideFnObject(), constant); - else return new RightScalarOperator(IntegerDivide.getIntegerDivideFnObject(), constant); + return new LeftScalarOperator(IntegerDivide.getFnObject(), constant); + else return new RightScalarOperator(IntegerDivide.getFnObject(), constant); } else if ( opcode.equalsIgnoreCase("^") ){ if(arg1IsScalar) @@ -805,9 +805,9 @@ public class InstructionUtils else if(opcode.equalsIgnoreCase("/") || opcode.equalsIgnoreCase("map/")) return new BinaryOperator(Divide.getDivideFnObject()); else if(opcode.equalsIgnoreCase("%%") || opcode.equalsIgnoreCase("map%%")) - return new BinaryOperator(Modulus.getModulusFnObject()); + return new BinaryOperator(Modulus.getFnObject()); else if(opcode.equalsIgnoreCase("%/%") || opcode.equalsIgnoreCase("map%/%")) - return new BinaryOperator(IntegerDivide.getIntegerDivideFnObject()); + return new BinaryOperator(IntegerDivide.getFnObject()); else if(opcode.equalsIgnoreCase("^") || opcode.equalsIgnoreCase("map^")) return new BinaryOperator(Power.getPowerFnObject()); else if ( opcode.equalsIgnoreCase("^2") ) http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4cbb0281/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseModulusTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseModulusTest.java b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseModulusTest.java index 49b8367..4213b43 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseModulusTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseModulusTest.java @@ -77,7 +77,7 @@ public class ElementwiseModulusTest extends AutomatedTestBase double[][] a = getRandomMatrix(rows, cols, -5, 5, 1, -1); double[][] b = getNonZeroRandomMatrix(rows, cols, -20, 20, -1); double[][] c = new double[rows][cols]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { c[i][j] = fnmod.execute(a[i][j], b[i][j]); @@ -106,7 +106,7 @@ public class ElementwiseModulusTest extends AutomatedTestBase double[][] a = getRandomMatrix(rows, cols, -5, 5, 0.05, -1); double[][] b = getNonZeroRandomMatrix(rows, cols, -20, 20, -1); double[][] c = new double[rows][cols]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { c[i][j] = fnmod.execute(a[i][j], b[i][j]); @@ -279,7 +279,7 @@ public class ElementwiseModulusTest extends AutomatedTestBase double[][] a = getRandomMatrix(rows, cols, -1, 1, 0.5, -1); double[][] b = getRandomMatrix(rows, cols, -1, 1, 0.5, -1); double[][] c = new double[rows][cols]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { c[i][j] = fnmod.execute(a[i][j], b[i][j]); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/4cbb0281/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ScalarModulusTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ScalarModulusTest.java b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ScalarModulusTest.java index 8b32fd1..1f9924b 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ScalarModulusTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ScalarModulusTest.java @@ -73,7 +73,7 @@ public class ScalarModulusTest extends AutomatedTestBase double[][] vector = getNonZeroRandomMatrix(rows, 1, 1, 5, -1); double[][] computedVectorLeft = new double[rows][1]; double[][] computedVectorRight = new double[rows][1]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor); computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]); @@ -119,7 +119,7 @@ public class ScalarModulusTest extends AutomatedTestBase double[][] vector = getNonZeroRandomMatrix(rows, 1, 1, 5, -1); double[][] computedVectorLeft = new double[rows][1]; double[][] computedVectorRight = new double[rows][1]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor); computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]); @@ -165,7 +165,7 @@ public class ScalarModulusTest extends AutomatedTestBase double[][] vector = getNonZeroRandomMatrix(rows, 1, 1, 5, -1); double[][] computedVectorLeft = new double[rows][1]; double[][] computedVectorRight = new double[rows][1]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor); computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]); @@ -211,7 +211,7 @@ public class ScalarModulusTest extends AutomatedTestBase double[][] vector = getNonZeroRandomMatrix(rows, 1, 1, 5, -1); double[][] computedVectorLeft = new double[rows][1]; double[][] computedVectorRight = new double[rows][1]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor); computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]); @@ -257,7 +257,7 @@ public class ScalarModulusTest extends AutomatedTestBase double[][] vector = getRandomMatrix(rows, 1, 1, 5, 0.05, -1); double[][] computedVectorLeft = new double[rows][1]; double[][] computedVectorRight = new double[rows][1]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor); computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]); @@ -303,7 +303,7 @@ public class ScalarModulusTest extends AutomatedTestBase double[][] vector = getRandomMatrix(rows, 1, 1, 5, 0.5, -1); double[][] computedVectorLeft = new double[rows][1]; double[][] computedVectorRight = new double[rows][1]; - Modulus fnmod = Modulus.getModulusFnObject(); + Modulus fnmod = Modulus.getFnObject(); for(int i = 0; i < rows; i++) { computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor); computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]);
