[SYSTEMML-2037] Fix output representations binary/ternary instructions This patch fixes special cases of binary instructions where the input sizes (e.g., matrix-vector) do not cover a potential dense-sparse change, which causes outputs to remain in wrong sparse/dense representations. For execution types such as singlenode as used in JMLC scenarios this is unnecessary. Furthermore, for special cases of ternary instructions such as ctable rexpand, the output representation cannot be determined upfront and hence, we should similar to binary operations, check for sparse/dense conversions accordingly.
Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/f84fd71a Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/f84fd71a Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/f84fd71a Branch: refs/heads/master Commit: f84fd71a4250f40dfeed10c64cb73c3a2fd6722d Parents: c1860ce Author: Matthias Boehm <[email protected]> Authored: Wed Dec 6 19:19:03 2017 -0800 Committer: Matthias Boehm <[email protected]> Committed: Thu Dec 7 13:36:04 2017 -0800 ---------------------------------------------------------------------- .../instructions/cp/ComputationCPInstruction.java | 6 ++++++ .../runtime/instructions/cp/TernaryCPInstruction.java | 8 +++++++- .../sysml/runtime/util/LongLongDoubleHashMap.java | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/f84fd71a/src/main/java/org/apache/sysml/runtime/instructions/cp/ComputationCPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/ComputationCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/ComputationCPInstruction.java index 1e71e63..4dbdba4 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/ComputationCPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/ComputationCPInstruction.java @@ -19,6 +19,9 @@ package org.apache.sysml.runtime.instructions.cp; +import org.apache.sysml.api.DMLScript; +import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM; +import org.apache.sysml.runtime.controlprogram.caching.CacheableData; import org.apache.sysml.runtime.matrix.data.MatrixBlock; import org.apache.sysml.runtime.matrix.operators.Operator; @@ -54,6 +57,9 @@ public abstract class ComputationCPInstruction extends CPInstruction { } protected boolean checkGuardedRepresentationChange( MatrixBlock in1, MatrixBlock in2, MatrixBlock out ) { + if( DMLScript.rtplatform == RUNTIME_PLATFORM.SINGLE_NODE + && !CacheableData.isCachingActive() ) + return true; double memIn1 = (in1 != null) ? in1.getInMemorySize() : 0; double memIn2 = (in2 != null) ? in2.getInMemorySize() : 0; double memReq = out.isInSparseFormat() ? http://git-wip-us.apache.org/repos/asf/systemml/blob/f84fd71a/src/main/java/org/apache/sysml/runtime/instructions/cp/TernaryCPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/TernaryCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/TernaryCPInstruction.java index 34a260a..a927bba 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/TernaryCPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/TernaryCPInstruction.java @@ -175,6 +175,12 @@ public class TernaryCPInstruction extends ComputationCPInstruction { else resultBlock.examSparsity(); + // Ensure right dense/sparse output representation for special cases + // such as ctable expand (guarded by released input memory) + if( checkGuardedRepresentationChange(matBlock1, matBlock2, resultBlock) ) { + resultBlock.examSparsity(); + } + ec.setMatrixOutput(output.getName(), resultBlock, getExtendedOpcode()); - } + } } http://git-wip-us.apache.org/repos/asf/systemml/blob/f84fd71a/src/main/java/org/apache/sysml/runtime/util/LongLongDoubleHashMap.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/util/LongLongDoubleHashMap.java b/src/main/java/org/apache/sysml/runtime/util/LongLongDoubleHashMap.java index d6b9e09..08cd369 100644 --- a/src/main/java/org/apache/sysml/runtime/util/LongLongDoubleHashMap.java +++ b/src/main/java/org/apache/sysml/runtime/util/LongLongDoubleHashMap.java @@ -56,6 +56,18 @@ public class LongLongDoubleHashMap public int size() { return size; } + + public int getNonZeros() { + //note: the exact number of non-zeros might be smaller than size + //if negative and positive values canceled each other out + int ret = 0; + for( ADoubleEntry e : data ) + while( e != null ) { + ret += (e.value != 0) ? 1 : 0; + e = e.next; + } + return ret; + } public void addValue(long key1, long key2, double value) {
