You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2017/04/01 22:25:47 UTC

incubator-systemml git commit: [SYSTEMML-1454] New dynamic rewrites for nrow/ncol literal replacement

Repository: incubator-systemml
Updated Branches:
  refs/heads/master 420dd17be -> 648c62850


[SYSTEMML-1454] New dynamic rewrites for nrow/ncol literal replacement

This patch adds rewrites to replace unnecessary nrow/ncol operators with
literals in case of known dimensions after size updates during dynamic
recompilation. These unnecessary nrow/ncol operations have data
dependencies to their inputs which trigger computation even if the
intermediates are otherwise not required, for example, if they are part
of an existing or code generated fused operator.


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

Branch: refs/heads/master
Commit: 648c628505f04e75e6ece03ec4805a9641bbff88
Parents: 420dd17
Author: Matthias Boehm <mb...@gmail.com>
Authored: Sat Apr 1 01:22:35 2017 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Sat Apr 1 14:47:44 2017 -0700

----------------------------------------------------------------------
 .../org/apache/sysml/hops/ConvolutionOp.java    |  1 -
 .../sysml/hops/rewrite/HopRewriteUtils.java     |  7 ++++-
 .../RewriteAlgebraicSimplificationDynamic.java  | 28 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/648c6285/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ConvolutionOp.java b/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
index 1a48bc4..a097d19 100644
--- a/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
+++ b/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
@@ -26,7 +26,6 @@ import org.apache.sysml.lops.ConvolutionTransform.OperationTypes;
 import org.apache.sysml.lops.Lop;
 import org.apache.sysml.lops.LopProperties.ExecType;
 import org.apache.sysml.lops.LopsException;
-import org.apache.sysml.lops.ReBlock;
 import org.apache.sysml.parser.Expression.DataType;
 import org.apache.sysml.parser.Expression.ValueType;
 import org.apache.sysml.runtime.DMLRuntimeException;

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/648c6285/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
index 88ee174..a13f165 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
@@ -266,9 +266,14 @@ public class HopRewriteUtils
 	}
 	
 	public static void replaceChildReference( Hop parent, Hop inOld, Hop inNew, int pos ) {
+		replaceChildReference(parent, inOld, inNew, pos, true);
+	}
+	
+	public static void replaceChildReference( Hop parent, Hop inOld, Hop inNew, int pos, boolean refresh ) {
 		removeChildReferenceByPos(parent, inOld, pos);
 		addChildReference(parent, inNew, pos);
-		parent.refreshSizeInformation();
+		if( refresh )
+			parent.refreshSizeInformation();
 	}
 	
 	public static void cleanupUnreferenced( Hop... inputs ) {

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/648c6285/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationDynamic.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationDynamic.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationDynamic.java
index 0c2f337..66f6879 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationDynamic.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationDynamic.java
@@ -189,6 +189,7 @@ public class RewriteAlgebraicSimplificationDynamic extends HopRewriteRule
 			hi = simplifyEmptyBinaryOperation(hop, hi, i);    //e.g., X*Y -> matrix(0,nrow(X), ncol(X)) / X+Y->X / X-Y -> X
 			hi = simplifyScalarMVBinaryOperation(hi);         //e.g., X*y -> X*as.scalar(y), if y is a 1-1 matrix
 			hi = simplifyNnzComputation(hop, hi, i);          //e.g., sum(ppred(X,0,"!=")) -> literal(nnz(X)), if nnz known
+			hi = simplifyNrowNcolComputation(hop, hi, i);     //e.g., nrow(X) -> literal(nrow(X)), if nrow known to remove data dependency
 			
 			//process childs recursively after rewrites (to investigate pattern newly created by rewrites)
 			if( !descendFirst )
@@ -2440,4 +2441,31 @@ public class RewriteAlgebraicSimplificationDynamic extends HopRewriteRule
 		
 		return hi;
 	}
+	
+	private Hop simplifyNrowNcolComputation(Hop parent, Hop hi, int pos) 
+		throws HopsException
+	{
+		//nrow(X) -> literal(nrow(X)), ncol(X) -> literal(ncol(X)), if respective dims known
+		//(this rewrite aims to remove unnecessary data dependencies to X which trigger computation
+		//even if the intermediate is otherwise not required, e.g., when part of a fused operator)
+		if( hi instanceof UnaryOp ) 
+		{
+			if( ((UnaryOp)hi).getOp()==OpOp1.NROW && hi.getInput().get(0).getDim1()>0 ) {
+				Hop hnew = new LiteralOp(hi.getInput().get(0).getDim1());
+				HopRewriteUtils.replaceChildReference(parent, hi, hnew, pos, false);
+				HopRewriteUtils.cleanupUnreferenced(hi);
+				hi = hnew;
+				LOG.debug("Applied simplifyNrowComputation.");
+			}
+			else if( ((UnaryOp)hi).getOp()==OpOp1.NCOL && hi.getInput().get(0).getDim2()>0 ) {
+				Hop hnew = new LiteralOp(hi.getInput().get(0).getDim2());
+				HopRewriteUtils.replaceChildReference(parent, hi, hnew, pos, false);
+				HopRewriteUtils.cleanupUnreferenced(hi);
+				hi = hnew;
+				LOG.debug("Applied simplifyNcolComputation.");	
+			}
+		}
+		
+		return hi;
+	}
 }