[SYSTEMML-1253] Selective wdivmm rewrite (dense factors), stratstats Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/d3e617b0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/d3e617b0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/d3e617b0
Branch: refs/heads/master Commit: d3e617b0c9f65cc1b80e884e8df6c7d3668332b0 Parents: 0a3d248 Author: Matthias Boehm <[email protected]> Authored: Sun Feb 12 07:44:03 2017 +0100 Committer: Matthias Boehm <[email protected]> Committed: Sun Feb 12 09:41:48 2017 +0100 ---------------------------------------------------------------------- .../sysml/hops/rewrite/HopRewriteUtils.java | 6 +++++ .../RewriteAlgebraicSimplificationDynamic.java | 26 +++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/d3e617b0/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 8ccb531..50501dc 100644 --- a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java +++ b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java @@ -60,6 +60,7 @@ import org.apache.sysml.runtime.instructions.cp.DoubleObject; import org.apache.sysml.runtime.instructions.cp.IntObject; import org.apache.sysml.runtime.instructions.cp.ScalarObject; import org.apache.sysml.runtime.instructions.cp.StringObject; +import org.apache.sysml.runtime.matrix.data.MatrixBlock; import org.apache.sysml.runtime.util.UtilFunctions; public class HopRewriteUtils @@ -672,6 +673,11 @@ public class HopRewriteUtils && hop.getInput().get(1).getDim1() < hop.getInput().get(1).getDim2(); } + public static boolean isSparse( Hop hop ) { + return hop.dimsKnown(true) //dims and nnz known + && MatrixBlock.evalSparseFormatInMemory(hop.getDim1(), hop.getDim2(), hop.getNnz()); + } + public static boolean isEqualValue( LiteralOp hop1, LiteralOp hop2 ) throws HopsException { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/d3e617b0/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 ed89a05..e8e3862 100644 --- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationDynamic.java +++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationDynamic.java @@ -1972,18 +1972,22 @@ public class RewriteAlgebraicSimplificationDynamic extends HopRewriteRule Hop U = hi.getInput().get(1).getInput().get(0); Hop V = hi.getInput().get(1).getInput().get(1); - if( !HopRewriteUtils.isTransposeOperation(V) ) - V = HopRewriteUtils.createTranspose(V); - else - V = V.getInput().get(0); + //for this basic pattern, we're more conservative and only apply wdivmm if + //the factors are not known to be sparse + if( !HopRewriteUtils.isSparse(U) && !HopRewriteUtils.isSparse(V) ) { + if( !HopRewriteUtils.isTransposeOperation(V) ) + V = HopRewriteUtils.createTranspose(V); + else + V = V.getInput().get(0); - hnew = new QuaternaryOp(hi.getName(), DataType.MATRIX, ValueType.DOUBLE, - OpOp4.WDIVMM, W, U, V, new LiteralOp(-1), 0, true, false); - HopRewriteUtils.setOutputBlocksizes(hnew, W.getRowsInBlock(), W.getColsInBlock()); - hnew.refreshSizeInformation(); - - appliedPattern = true; - LOG.debug("Applied simplifyWeightedDivMM7 (line "+hi.getBeginLine()+")"); + hnew = new QuaternaryOp(hi.getName(), DataType.MATRIX, ValueType.DOUBLE, + OpOp4.WDIVMM, W, U, V, new LiteralOp(-1), 0, true, false); + HopRewriteUtils.setOutputBlocksizes(hnew, W.getRowsInBlock(), W.getColsInBlock()); + hnew.refreshSizeInformation(); + + appliedPattern = true; + LOG.debug("Applied simplifyWeightedDivMM7 (line "+hi.getBeginLine()+")"); + } } //relink new hop into original position
