Repository: incubator-systemml Updated Branches: refs/heads/master 9c19b4771 -> de270219f
[SYSTEMML-1475] Fix codegen cost model (number and size of inputs) This patch fixes the cost-based codegen plan selection to account for correct input sizes and disregard scalar inputs. Furthermore, this also adds more trace logging information and fixes remaining correctness issues of multi aggregates. Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/de270219 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/de270219 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/de270219 Branch: refs/heads/master Commit: de270219f7cf462c0d7c3471bcae1b17b81962b6 Parents: 9c19b47 Author: Matthias Boehm <[email protected]> Authored: Fri Apr 7 13:40:40 2017 -0700 Committer: Matthias Boehm <[email protected]> Committed: Fri Apr 7 13:40:52 2017 -0700 ---------------------------------------------------------------------- .../template/PlanSelectionFuseCostBased.java | 13 ++++++++++--- .../runtime/codegen/SpoofMultiAggregate.java | 18 +++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/de270219/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 151dab2..7682336 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 @@ -244,7 +244,7 @@ public class PlanSelectionFuseCostBased extends PlanSelection fullAggs.add(hopID); } if( LOG.isTraceEnabled() ) { - LOG.trace("Found ua(RC) aggregations: " + + LOG.trace("Found within-partition ua(RC) aggregations: " + Arrays.toString(fullAggs.toArray(new Long[0]))); } @@ -277,6 +277,12 @@ public class PlanSelectionFuseCostBased extends PlanSelection for( Hop hop : roots ) rCollectAggregatesSharedRead(hop, fullAggs); + if( LOG.isTraceEnabled() ) { + for( Entry<Long, ArrayList<Long>> e : fullAggs.entrySet() ) + LOG.trace("Found across-partition ua(RC) aggregations for "+e.getKey()+": " + + Arrays.toString(e.getValue().toArray(new Long[0]))); + } + //construct and add multiagg template plans (w/ max 3 aggregations) for( Entry<Long, ArrayList<Long>> e : fullAggs.entrySet() ) { if( e.getValue().size()<=1 ) @@ -531,8 +537,8 @@ public class PlanSelectionFuseCostBased extends PlanSelection costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, costVect, best.type); else { //include children and I/O costs costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, null, null); - if( costVect != null ) - costVect.addInputSize( c.getHopID(), Math.max(current.getDim1(),1)*Math.max(current.getDim2(),1)); + if( costVect != null && c.getDataType().isMatrix() ) + costVect.addInputSize( c.getHopID(), Math.max(c.getDim1(),1)*Math.max(c.getDim2(),1)); } } @@ -711,6 +717,7 @@ public class PlanSelectionFuseCostBased extends PlanSelection @Override public String toString() { return "["+outSize+", "+computeCosts+", {" + +Arrays.toString(inSizes.keySet().toArray(new Long[0]))+", " +Arrays.toString(inSizes.values().toArray(new Double[0]))+"}]"; } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/de270219/src/main/java/org/apache/sysml/runtime/codegen/SpoofMultiAggregate.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/codegen/SpoofMultiAggregate.java b/src/main/java/org/apache/sysml/runtime/codegen/SpoofMultiAggregate.java index ea76ac5..081e805 100644 --- a/src/main/java/org/apache/sysml/runtime/codegen/SpoofMultiAggregate.java +++ b/src/main/java/org/apache/sysml/runtime/codegen/SpoofMultiAggregate.java @@ -156,14 +156,18 @@ public abstract class SpoofMultiAggregate extends SpoofOperator implements Seria private void setInitialOutputValues(double[] c) { - for( int k=0; k<_aggOps.length; k++ ) { - switch(_aggOps[k]) { - case SUM: - case SUM_SQ: c[k] = 0; break; - case MIN: c[k] = Double.MAX_VALUE; break; - case MAX: c[k] = -Double.MAX_VALUE; break; - } + for( int k=0; k<_aggOps.length; k++ ) + c[k] = getInitialValue(_aggOps[k]); + } + + public static double getInitialValue(AggOp aggop) { + switch( aggop ) { + case SUM: + case SUM_SQ: return 0; + case MIN: return Double.MAX_VALUE; + case MAX: return -Double.MAX_VALUE; } + return 0; }
