Repository: systemml Updated Branches: refs/heads/master 328e8a002 -> 0cff14094
[SYSTEMML-1835] Improved compilation of sparse-safe codegen cell ops The codegen templates Cell and MAgg are flagged during compilation as sparse-safe or -unsafe depending on the characteristics of the specific operator DAG. This patch makes two minor improvements to the selection of sparse drivers as well as the analysis of sparse-safe DAGs. On GLM binomial-probit (100M x 10, 20/10 outer/inner iterations), this patch improved the end-to-end runtime w/ codegen from 185s to 145s (whereas the baseline without fusion requires about ~2,500s). Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/0cff1409 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/0cff1409 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/0cff1409 Branch: refs/heads/master Commit: 0cff14094fc77edb026f4582fb05e7a92362069f Parents: 328e8a0 Author: Matthias Boehm <mboe...@gmail.com> Authored: Wed Sep 27 00:12:47 2017 -0700 Committer: Matthias Boehm <mboe...@gmail.com> Committed: Wed Sep 27 00:12:47 2017 -0700 ---------------------------------------------------------------------- .../org/apache/sysml/hops/codegen/cplan/CNodeUnary.java | 12 ++++++++---- .../sysml/hops/codegen/template/TemplateCell.java | 4 ++-- .../sysml/hops/codegen/template/TemplateUtils.java | 7 ++++--- .../org/apache/sysml/hops/rewrite/HopRewriteUtils.java | 4 ++++ 4 files changed, 18 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/0cff1409/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeUnary.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeUnary.java b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeUnary.java index 860d35a..5e3ef83 100644 --- a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeUnary.java +++ b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeUnary.java @@ -19,6 +19,7 @@ package org.apache.sysml.hops.codegen.cplan; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.sysml.hops.codegen.template.TemplateUtils; import org.apache.sysml.parser.Expression.DataType; @@ -165,10 +166,13 @@ public class CNodeUnary extends CNode return StringUtils.capitalize(tmp[1].toLowerCase()); } public boolean isScalarLookup() { - return this == LOOKUP0 - || this == UnaryType.LOOKUP_R - || this == UnaryType.LOOKUP_C - || this == UnaryType.LOOKUP_RC; + return ArrayUtils.contains(new UnaryType[]{ + LOOKUP0, LOOKUP_R, LOOKUP_C, LOOKUP_RC}, this); + } + public boolean isSparseSafeScalar() { + return ArrayUtils.contains(new UnaryType[]{ + POW2, MULT2, ABS, ROUND, CEIL, FLOOR, SIGN, + SIN, TAN, SELP, SPROP}, this); } } http://git-wip-us.apache.org/repos/asf/systemml/blob/0cff1409/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 4b0c126..b075c58 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 @@ -327,7 +327,7 @@ public class TemplateCell extends TemplateBase && roots.get(i).getInput().contains(mainInput)) || (HopRewriteUtils.isBinary(roots.get(i), OpOp2.DIV) && roots.get(i).getInput().get(0) == mainInput) - || (TemplateUtils.rIsBinaryOnly(outputs.get(i), BinType.MULT) + || (TemplateUtils.rIsSparseSafeOnly(outputs.get(i), BinType.MULT) && TemplateUtils.rContainsInput(outputs.get(i), mainInput.getHopID())); if( onlySum ) ret &= (aggOps.get(i)==AggOp.SUM || aggOps.get(i)==AggOp.SUM_SQ); @@ -366,7 +366,7 @@ public class TemplateCell extends TemplateBase if( h1.isScalar() && h2.isScalar() ) return Long.compare(h1.getHopID(), h2.getHopID()); return (h1.dimsKnown(true) && h2.dimsKnown(true) && h1.getNnz() != h2.getNnz() - && (HopRewriteUtils.isSparse(h1) || HopRewriteUtils.isSparse(h2))) ? + && (HopRewriteUtils.isSparse(h1, 1.0) || HopRewriteUtils.isSparse(h2, 1.0))) ? Long.compare(h1.getNnz(), h2.getNnz()) : Long.compare(h1.getHopID(), h2.getHopID()); } http://git-wip-us.apache.org/repos/asf/systemml/blob/0cff1409/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 21f44b2..06d83bd 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 @@ -250,13 +250,14 @@ public class TemplateUtils && ArrayUtils.contains(types, ((CNodeBinary)node).getType()); } - public static boolean rIsBinaryOnly(CNode node, BinType...types) { + public static boolean rIsSparseSafeOnly(CNode node, BinType...types) { if( !(isBinary(node, types) || node instanceof CNodeData - || (node instanceof CNodeUnary && ((CNodeUnary)node).getType().isScalarLookup())) ) + || (node instanceof CNodeUnary && ((CNodeUnary)node).getType().isScalarLookup()) + || (node instanceof CNodeUnary && ((CNodeUnary)node).getType().isSparseSafeScalar())) ) return false; boolean ret = true; for( CNode c : node.getInput() ) - ret &= rIsBinaryOnly(c, types); + ret &= rIsSparseSafeOnly(c, types); return ret; } http://git-wip-us.apache.org/repos/asf/systemml/blob/0cff1409/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 af9d593..2d58f4c 100644 --- a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java +++ b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java @@ -772,6 +772,10 @@ public class HopRewriteUtils && MatrixBlock.evalSparseFormatInMemory(hop.getDim1(), hop.getDim2(), hop.getNnz()); } + public static boolean isSparse( Hop hop, double threshold ) { + return hop.getSparsity() < threshold; + } + public static boolean isEqualValue( LiteralOp hop1, LiteralOp hop2 ) throws HopsException {