[SYSTEMML-1537] Fix codegen cost model (missing common operations) This patch includes ctable, centralmoment, and covariance in both binary and ternary forms into the codegen cost model, which is used in the cost-based plan selector.
Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/7b7b9ba9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/7b7b9ba9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/7b7b9ba9 Branch: refs/heads/master Commit: 7b7b9ba9ba48faab05f396ddbac0c81eb2cc50f3 Parents: 53fe1ae Author: Matthias Boehm <[email protected]> Authored: Tue Apr 18 14:23:50 2017 -0700 Committer: Matthias Boehm <[email protected]> Committed: Wed Apr 19 18:46:29 2017 -0700 ---------------------------------------------------------------------- .../template/PlanSelectionFuseCostBased.java | 34 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/7b7b9ba9/src/main/java/org/apache/sysml/hops/codegen/template/PlanSelectionFuseCostBased.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/codegen/template/PlanSelectionFuseCostBased.java b/src/main/java/org/apache/sysml/hops/codegen/template/PlanSelectionFuseCostBased.java index ae2b076..70a6086 100644 --- a/src/main/java/org/apache/sysml/hops/codegen/template/PlanSelectionFuseCostBased.java +++ b/src/main/java/org/apache/sysml/hops/codegen/template/PlanSelectionFuseCostBased.java @@ -41,6 +41,7 @@ import org.apache.sysml.hops.Hop; import org.apache.sysml.hops.Hop.AggOp; import org.apache.sysml.hops.Hop.Direction; import org.apache.sysml.hops.IndexingOp; +import org.apache.sysml.hops.LiteralOp; import org.apache.sysml.hops.ParameterizedBuiltinOp; import org.apache.sysml.hops.ReorgOp; import org.apache.sysml.hops.TernaryOp; @@ -781,13 +782,26 @@ public class PlanSelectionFuseCostBased extends PlanSelection case RBIND: costs = 1; break; case INTDIV: costs = 6; break; case MODULUS: costs = 8; break; - case DIV: costs = 22; break; + case DIV: costs = 22; break; case LOG: - case LOG_NZ: costs = 32; break; - case POW: costs = (HopRewriteUtils.isLiteralOfValue( + case LOG_NZ: costs = 32; break; + case POW: costs = (HopRewriteUtils.isLiteralOfValue( current.getInput().get(1), 2) ? 1 : 16); break; case MINUS_NZ: case MINUS1_MULT: costs = 2; break; + case CENTRALMOMENT: + int type = (int) (current.getInput().get(1) instanceof LiteralOp ? + HopRewriteUtils.getIntValueSafe((LiteralOp)current.getInput().get(1)) : 2); + switch( type ) { + case 0: costs = 1; break; //count + case 1: costs = 8; break; //mean + case 2: costs = 16; break; //cm2 + case 3: costs = 31; break; //cm3 + case 4: costs = 51; break; //cm4 + case 5: costs = 16; break; //variance + } + break; + case COVARIANCE: costs = 23; break; default: throw new RuntimeException("Cost model not " + "implemented yet for: "+((BinaryOp)current).getOp()); @@ -797,6 +811,20 @@ public class PlanSelectionFuseCostBased extends PlanSelection switch( ((TernaryOp)current).getOp() ) { case PLUS_MULT: case MINUS_MULT: costs = 2; break; + case CTABLE: costs = 3; break; + case CENTRALMOMENT: + int type = (int) (current.getInput().get(1) instanceof LiteralOp ? + HopRewriteUtils.getIntValueSafe((LiteralOp)current.getInput().get(1)) : 2); + switch( type ) { + case 0: costs = 2; break; //count + case 1: costs = 9; break; //mean + case 2: costs = 17; break; //cm2 + case 3: costs = 32; break; //cm3 + case 4: costs = 52; break; //cm4 + case 5: costs = 17; break; //variance + } + break; + case COVARIANCE: costs = 23; break; default: throw new RuntimeException("Cost model not " + "implemented yet for: "+((TernaryOp)current).getOp());
