Repository: systemml
Updated Branches:
  refs/heads/master ec4963552 -> 3cda8a981


[SYSTEMML-2022] Fix codegen blocksize handling for spark row ops

This patch addresses perftest failures of MLogreg sparse with intercept
2, where we incorrectly chosen a row template despite an output size of
1001. This was because (1) the memory estimates did not correctly
reflect the handling of sparse outputs in row templates, and (2) we only
checked valid input dimensions (in this case 1000) but not the output
dimensions (in this case 1001 after cbind). Furthermore, this patch also
improves the memory estimates for cell and outer templates that are able
to directly output sparse outputs without conversion.


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

Branch: refs/heads/master
Commit: 3cda8a981256257b5d830039d686a59d8c378e6a
Parents: ec49635
Author: Matthias Boehm <[email protected]>
Authored: Sun Nov 19 15:34:24 2017 -0800
Committer: Matthias Boehm <[email protected]>
Committed: Sun Nov 19 15:54:02 2017 -0800

----------------------------------------------------------------------
 src/main/java/org/apache/sysml/hops/OptimizerUtils.java  |  7 ++++++-
 .../org/apache/sysml/hops/codegen/SpoofCompiler.java     | 11 +++++++----
 .../java/org/apache/sysml/hops/codegen/SpoofFusedOp.java |  6 +++++-
 .../hops/codegen/opt/PlanSelectionFuseCostBasedV2.java   |  7 ++++---
 .../runtime/instructions/spark/SpoofSPInstruction.java   |  3 ++-
 5 files changed, 24 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/3cda8a98/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/OptimizerUtils.java 
b/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
index d67e086..4684a97 100644
--- a/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
+++ b/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
@@ -771,9 +771,14 @@ public class OptimizerUtils
        }
        
        public static double getTotalMemEstimate(Hop[] in, Hop out) {
+               return getTotalMemEstimate(in, out, false);
+       }
+       
+       public static double getTotalMemEstimate(Hop[] in, Hop out, boolean 
denseOut) {
                return Arrays.stream(in)
                        .mapToDouble(h -> h.getOutputMemEstimate()).sum()
-                       + out.getOutputMemEstimate();
+                       + (!denseOut ? out.getOutputMemEstimate() :
+                               OptimizerUtils.estimateSize(out.getDim1(), 
out.getDim2()));
        }
        
        /**

http://git-wip-us.apache.org/repos/asf/systemml/blob/3cda8a98/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java 
b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
index 8683bb0..7f67b43 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
@@ -655,7 +655,8 @@ public class SpoofCompiler
                                
HopRewriteUtils.setOutputParametersForScalar(hnew);
                                hnew = HopRewriteUtils.createUnary(hnew, 
OpOp1.CAST_AS_MATRIX);
                        }
-                       else if( tmpCNode instanceof CNodeRow && 
((CNodeRow)tmpCNode).getRowType()==RowType.NO_AGG_CONST )
+                       else if( tmpCNode instanceof CNodeRow && 
(((CNodeRow)tmpCNode).getRowType()==RowType.NO_AGG_CONST
+                               || 
((CNodeRow)tmpCNode).getRowType()==RowType.COL_AGG_CONST) )
                                
((SpoofFusedOp)hnew).setConstDim2(((CNodeRow)tmpCNode).getConstDim2());
                        
                        if( !(tmpCNode instanceof CNodeMultiAgg) )
@@ -736,17 +737,19 @@ public class SpoofCompiler
                                                LOG.trace("Removed invalid row 
cplan w/o agg on column vector.");
                                }
                                else if( OptimizerUtils.isSparkExecutionMode() 
) {
+                                       Hop hop = 
memo.getHopRefs().get(e.getKey());
                                        boolean isSpark = DMLScript.rtplatform 
== RUNTIME_PLATFORM.SPARK
-                                               || 
OptimizerUtils.getTotalMemEstimate(inHops, memo.getHopRefs().get(e.getKey()))
+                                               || 
OptimizerUtils.getTotalMemEstimate(inHops, hop, true)
                                                        > 
OptimizerUtils.getLocalMemBudget();
-                                       boolean invalidNcol = false;
+                                       boolean invalidNcol = 
hop.getDataType().isMatrix() && (HopRewriteUtils.isTransposeOperation(hop) ?
+                                               hop.getDim1() > 
hop.getRowsInBlock() : hop.getDim2() > hop.getColsInBlock());
                                        for( Hop in : inHops )
                                                invalidNcol |= 
(in.getDataType().isMatrix() 
                                                        && in.getDim2() > 
in.getColsInBlock());
                                        if( isSpark && invalidNcol ) {
                                                cplans2.remove(e.getKey());
                                                if( LOG.isTraceEnabled() )
-                                                       LOG.trace("Removed 
invalid row cplan w/ ncol>ncolpb.");         
+                                                       LOG.trace("Removed 
invalid row cplan w/ ncol>ncolpb.");
                                        }
                                }
                        }

http://git-wip-us.apache.org/repos/asf/systemml/blob/3cda8a98/src/main/java/org/apache/sysml/hops/codegen/SpoofFusedOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/SpoofFusedOp.java 
b/src/main/java/org/apache/sysml/hops/codegen/SpoofFusedOp.java
index bae51cb..368a84a 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/SpoofFusedOp.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/SpoofFusedOp.java
@@ -32,6 +32,7 @@ import org.apache.sysml.lops.LopsException;
 import org.apache.sysml.lops.SpoofFused;
 import org.apache.sysml.parser.Expression.DataType;
 import org.apache.sysml.parser.Expression.ValueType;
+import org.apache.sysml.runtime.codegen.SpoofRowwise;
 import org.apache.sysml.runtime.matrix.MatrixCharacteristics;
 
 public class SpoofFusedOp extends Hop implements MultiThreadedHop
@@ -92,7 +93,10 @@ public class SpoofFusedOp extends Hop implements 
MultiThreadedHop
 
        @Override
        protected double computeOutputMemEstimate(long dim1, long dim2, long 
nnz) {
-               return OptimizerUtils.estimateSize(dim1, dim2);
+               return _class.getGenericSuperclass().equals(SpoofRowwise.class) 
?
+                       OptimizerUtils.estimateSize(dim1, dim2) :
+                       OptimizerUtils.estimatePartitionedSizeExactSparsity(
+                               dim1, dim2, getRowsInBlock(), getColsInBlock(), 
nnz);
        }
 
        @Override

http://git-wip-us.apache.org/repos/asf/systemml/blob/3cda8a98/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
 
b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
index 08d5e44..7ad00fa 100644
--- 
a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
+++ 
b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
@@ -648,14 +648,15 @@ public class PlanSelectionFuseCostBasedV2 extends 
PlanSelection
                                        continue;
                                Hop hop = memo.getHopRefs().get(hopID);
                                boolean isSpark = DMLScript.rtplatform == 
RUNTIME_PLATFORM.SPARK
-                                       || 
OptimizerUtils.getTotalMemEstimate(hop.getInput().toArray(new Hop[0]), hop)
+                                       || 
OptimizerUtils.getTotalMemEstimate(hop.getInput().toArray(new Hop[0]), hop, 
true)
                                                > 
OptimizerUtils.getLocalMemBudget();
-                               boolean validNcol = true;
+                               boolean validNcol = 
hop.getDataType().isScalar() || (HopRewriteUtils.isTransposeOperation(hop) ? 
+                                       hop.getDim1() <= hop.getRowsInBlock() : 
hop.getDim2() <= hop.getColsInBlock());
                                for( Hop in : hop.getInput() )
                                        validNcol &= in.getDataType().isScalar()
                                                || (in.getDim2() <= 
in.getColsInBlock())
                                                || (hop instanceof AggBinaryOp 
&& in.getDim1() <= in.getRowsInBlock()
-                                               && 
HopRewriteUtils.isTransposeOperation(in));
+                                                       && 
HopRewriteUtils.isTransposeOperation(in));
                                if( isSpark && !validNcol ) {
                                        List<MemoTableEntry> blacklist = 
memo.get(hopID, TemplateType.ROW);
                                        
memo.remove(memo.getHopRefs().get(hopID), TemplateType.ROW);

http://git-wip-us.apache.org/repos/asf/systemml/blob/3cda8a98/src/main/java/org/apache/sysml/runtime/instructions/spark/SpoofSPInstruction.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/spark/SpoofSPInstruction.java
 
b/src/main/java/org/apache/sysml/runtime/instructions/spark/SpoofSPInstruction.java
index eb74fed..5058b0b 100644
--- 
a/src/main/java/org/apache/sysml/runtime/instructions/spark/SpoofSPInstruction.java
+++ 
b/src/main/java/org/apache/sysml/runtime/instructions/spark/SpoofSPInstruction.java
@@ -212,7 +212,8 @@ public class SpoofSPInstruction extends SPInstruction {
                                        mcIn.getCols()+", 
ncolpb="+mcIn.getColsPerBlock()+".");
                        }
                        SpoofRowwise op = (SpoofRowwise) 
CodegenUtils.createInstance(_class);
-                       long clen2 = (op.getRowType()==RowType.NO_AGG_CONST) ? 
op.getConstDim2() :
+                       long clen2 = (op.getRowType()==RowType.NO_AGG_CONST 
+                               || op.getRowType()==RowType.COL_AGG_CONST) ? 
op.getConstDim2() :
                                op.getRowType().isRowTypeB1() ? 
sec.getMatrixCharacteristics(_in[1].getName()).getCols() : -1;
                        RowwiseFunction fmmc = new 
RowwiseFunction(_class.getName(),
                                _classBytes, bcVect2, bcMatrices, scalars, 
(int)mcIn.getCols(), (int)clen2);

Reply via email to