Repository: systemml
Updated Branches:
  refs/heads/master 5e7e57774 -> 6b25b3bf2


[SYSTEMML-1294] Improved codegen compiler (dot products, single-ops)

This patch makes two improvements to the existing codegen compiler in
order to avoid unnecessary performance degradation in the default
optimization level 2, where rewrites and existing fused operators are
already applied to HOP DAGs before the codegen compiler is invoked.

(1) Handling of dot products: So far, we did not include transpose
operations of dot products into partial fusion plans, which led to wrong
cost estimates and thus suboptimal plan choices. 

(2) Handling of special single-operation fused operators. We now allow
ternary and expensive unary operations (such as exp or log) in fused
operators because these are automatically multi-threaded whereas our
default unary or binary operations are not.


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/6a4aa1d6
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/6a4aa1d6
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/6a4aa1d6

Branch: refs/heads/master
Commit: 6a4aa1d6a07c09b00fe87a775d7bd40993a91214
Parents: 5e7e577
Author: Matthias Boehm <[email protected]>
Authored: Tue Jun 27 19:13:38 2017 -0700
Committer: Matthias Boehm <[email protected]>
Committed: Thu Jun 29 23:14:04 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/codegen/SpoofCompiler.java       |  2 +-
 .../hops/codegen/template/TemplateCell.java     | 11 ++++--
 .../hops/codegen/template/TemplateUtils.java    |  6 ++-
 .../functions/codegen/RowAggTmplTest.java       | 20 +++++++++-
 .../scripts/functions/codegen/rowAggPattern23.R | 40 ++++++++++++++++++++
 .../functions/codegen/rowAggPattern23.dml       | 37 ++++++++++++++++++
 6 files changed, 108 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/6a4aa1d6/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java 
b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
index fc3ecde..fede282 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
@@ -717,7 +717,7 @@ public class SpoofCompiler
                        
                        //remove cplan w/ single op and w/o agg
                        if( (tpl instanceof CNodeCell && 
((((CNodeCell)tpl).getCellType()==CellType.NO_AGG
-                               && TemplateUtils.hasSingleOperation(tpl))|| 
TemplateUtils.hasNoOperation(tpl)))
+                               && TemplateUtils.hasSingleOperation(tpl)) || 
TemplateUtils.hasNoOperation(tpl)))
                                || tpl instanceof CNodeRow && 
TemplateUtils.hasSingleOperation(tpl)) 
                                cplans2.remove(e.getKey());
                                

http://git-wip-us.apache.org/repos/asf/systemml/blob/6a4aa1d6/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java 
b/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
index e94d9a5..c73216e 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
@@ -84,14 +84,19 @@ public class TemplateCell extends TemplateBase
                return !isClosed() && (isValidOperation(hop) 
                        || (HopRewriteUtils.isAggUnaryOp(hop, SUPPORTED_AGG) 
                                && ((AggUnaryOp) hop).getDirection()!= 
Direction.Col)
-                       || (HopRewriteUtils.isMatrixMultiply(hop) && 
hop.getDim1()==1 && hop.getDim2()==1)
-                               && 
HopRewriteUtils.isTransposeOperation(hop.getInput().get(0)));
+                       || (HopRewriteUtils.isMatrixMultiply(hop)
+                               && hop.getDim1()==1 && hop.getDim2()==1)
+                               && 
HopRewriteUtils.isTransposeOperation(hop.getInput().get(0))
+                       || (HopRewriteUtils.isTransposeOperation(hop) 
+                               && hop.getDim1()==1 && hop.getDim2()>1));
        }
 
        @Override
        public boolean merge(Hop hop, Hop input) {
                //merge of other cell tpl possible
-               return (!isClosed() && isValidOperation(hop));
+               return (!isClosed() && (isValidOperation(hop) 
+                       || (hop instanceof AggBinaryOp && 
hop.getInput().indexOf(input)==0 
+                               && 
HopRewriteUtils.isTransposeOperation(input))));
        }
 
        @Override

http://git-wip-us.apache.org/repos/asf/systemml/blob/6a4aa1d6/src/main/java/org/apache/sysml/hops/codegen/template/TemplateUtils.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/hops/codegen/template/TemplateUtils.java 
b/src/main/java/org/apache/sysml/hops/codegen/template/TemplateUtils.java
index fca203d..da803cd 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/template/TemplateUtils.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/template/TemplateUtils.java
@@ -331,8 +331,10 @@ public class TemplateUtils
 
        public static boolean hasSingleOperation(CNodeTpl tpl) {
                CNode output = tpl.getOutput();
-               return (output instanceof CNodeUnary || output instanceof 
CNodeBinary
-                               || output instanceof CNodeTernary) && 
hasOnlyDataNodeOrLookupInputs(output);
+               return ((output instanceof CNodeUnary 
+                               && !TemplateUtils.isUnary(output, 
UnaryType.EXP, UnaryType.LOG)) 
+                       || output instanceof CNodeBinary) 
+                       && hasOnlyDataNodeOrLookupInputs(output);
        }
        
        public static boolean hasNoOperation(CNodeTpl tpl) {

http://git-wip-us.apache.org/repos/asf/systemml/blob/6a4aa1d6/src/test/java/org/apache/sysml/test/integration/functions/codegen/RowAggTmplTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegen/RowAggTmplTest.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegen/RowAggTmplTest.java
index 614d6e0..182adf4 100644
--- 
a/src/test/java/org/apache/sysml/test/integration/functions/codegen/RowAggTmplTest.java
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegen/RowAggTmplTest.java
@@ -58,6 +58,7 @@ public class RowAggTmplTest extends AutomatedTestBase
        private static final String TEST_NAME20 = TEST_NAME+"20"; //1 / (1 - (A 
/ rowSums(A)))
        private static final String TEST_NAME21 = TEST_NAME+"21"; 
//sum(X/rowSums(X))
        private static final String TEST_NAME22 = TEST_NAME+"22"; 
//((7+X)+(X-7)+exp(X))/(rowMins(X)+0.5) 
+       private static final String TEST_NAME23 = TEST_NAME+"23"; //L2SVM outer 
loop 
        
        private static final String TEST_DIR = "functions/codegen/";
        private static final String TEST_CLASS_DIR = TEST_DIR + 
RowAggTmplTest.class.getSimpleName() + "/";
@@ -69,7 +70,7 @@ public class RowAggTmplTest extends AutomatedTestBase
        @Override
        public void setUp() {
                TestUtils.clearAssertionInformation();
-               for(int i=1; i<=22; i++)
+               for(int i=1; i<=23; i++)
                        addTestConfiguration( TEST_NAME+i, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME+i, new String[] { String.valueOf(i) 
}) );
        }
        
@@ -403,6 +404,21 @@ public class RowAggTmplTest extends AutomatedTestBase
                testCodegenIntegration( TEST_NAME22, false, ExecType.SPARK );
        }
        
+       @Test   
+       public void testCodegenRowAggRewrite23CP() {
+               testCodegenIntegration( TEST_NAME23, true, ExecType.CP );
+       }
+       
+       @Test
+       public void testCodegenRowAgg23CP() {
+               testCodegenIntegration( TEST_NAME23, false, ExecType.CP );
+       }
+       
+       @Test
+       public void testCodegenRowAgg23SP() {
+               testCodegenIntegration( TEST_NAME23, false, ExecType.SPARK );
+       }
+       
        private void testCodegenIntegration( String testname, boolean rewrites, 
ExecType instType )
        {       
                boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
@@ -430,7 +446,7 @@ public class RowAggTmplTest extends AutomatedTestBase
                        rCmd = getRCmd(inputDir(), expectedDir());              
        
 
                        OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
-
+                       
                        runTest(true, false, null, -1); 
                        runRScript(true); 
                        

http://git-wip-us.apache.org/repos/asf/systemml/blob/6a4aa1d6/src/test/scripts/functions/codegen/rowAggPattern23.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern23.R 
b/src/test/scripts/functions/codegen/rowAggPattern23.R
new file mode 100644
index 0000000..c0319a6
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern23.R
@@ -0,0 +1,40 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+library("matrixStats")
+
+X = matrix(seq(1,3000), 60, 50);
+Y = seq(1,60);
+Xw = seq(2,61);
+lambda = 7;
+
+out = 1 - Y * Xw
+sv = (out > 0)
+out = sv * out
+obj = 0.5 * sum(out * out)
+g_new = t(X) %*% (out * Y)
+
+R = as.matrix(obj + sum(g_new));
+
+writeMM(as(R, "CsparseMatrix"), paste(args[2], "S", sep="")); 

http://git-wip-us.apache.org/repos/asf/systemml/blob/6a4aa1d6/src/test/scripts/functions/codegen/rowAggPattern23.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern23.dml 
b/src/test/scripts/functions/codegen/rowAggPattern23.dml
new file mode 100644
index 0000000..4aafd0f
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern23.dml
@@ -0,0 +1,37 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+
+X = matrix(seq(1,3000), 60, 50);
+Y = seq(1,60);
+Xw = seq(2,61);
+if(1==1){}
+
+out = 1 - Y * Xw
+sv = (out > 0)
+out = sv * out
+obj = 0.5 * sum(out * out)
+g_new = t(X) %*% (out * Y)
+
+if(1==1){}
+R = as.matrix(obj + sum(g_new));
+
+write(R, $1)

Reply via email to