You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2016/01/04 18:42:26 UTC

incubator-systemml git commit: Performance grouped aggregate count (special case dense vector count)

Repository: incubator-systemml
Updated Branches:
  refs/heads/master ff2aea542 -> 7fc8b9628


Performance grouped aggregate count (special case dense vector count) 

For example, on a scenario with a dense 1G x 1 input matrix (8GB) and
numGroups=10, this led to a performance improvement from 25.2s to 3.7s.  

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

Branch: refs/heads/master
Commit: 7fc8b9628bbf0625d11767aa3cdaf54c3779443b
Parents: ff2aea5
Author: Matthias Boehm <mb...@us.ibm.com>
Authored: Mon Jan 4 09:41:57 2016 -0800
Committer: Matthias Boehm <mb...@us.ibm.com>
Committed: Mon Jan 4 09:41:57 2016 -0800

----------------------------------------------------------------------
 .../sysml/runtime/matrix/data/LibMatrixAgg.java | 43 +++++++++++++++++++-
 1 file changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/7fc8b962/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixAgg.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixAgg.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixAgg.java
index 1373df3..ef45da6 100644
--- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixAgg.java
+++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixAgg.java
@@ -47,6 +47,7 @@ import org.apache.sysml.runtime.instructions.cp.KahanObject;
 import org.apache.sysml.runtime.matrix.operators.AggregateOperator;
 import org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator;
 import org.apache.sysml.runtime.matrix.operators.CMOperator;
+import org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes;
 import org.apache.sysml.runtime.matrix.operators.Operator;
 import org.apache.sysml.runtime.matrix.operators.UnaryOperator;
 import org.apache.sysml.runtime.util.UtilFunctions;
@@ -411,7 +412,13 @@ public class LibMatrixAgg
 		//note: current support only for column vectors
 		if(op instanceof CMOperator) {
 			CMOperator cmOp = (CMOperator) op;
-			groupedAggregateCM(groups, target, weights, result, numGroups, cmOp, 0, target.clen);
+			if( cmOp.getAggOpType()==AggregateOperationTypes.COUNT && weights==null && target.clen==1 ) {
+				//special case for vector counts
+				groupedAggregateVecCount(groups, result, numGroups);
+			}
+			else { //general case
+				groupedAggregateCM(groups, target, weights, result, numGroups, cmOp, 0, target.clen);
+			}
 		}
 		//Aggregate operator for sum (via kahan sum)
 		//note: support for row/column vectors and dense/sparse
@@ -437,7 +444,7 @@ public class LibMatrixAgg
 	{
 		//fall back to sequential version if necessary
 		boolean rowVector = (target.getNumRows()==1 && target.getNumColumns()>1);
-		if( k <= 1 || (long)target.rlen*target.clen < PAR_NUMCELL_THRESHOLD || rowVector ) {
+		if( k <= 1 || (long)target.rlen*target.clen < PAR_NUMCELL_THRESHOLD || rowVector || target.clen==1 ) {
 			groupedAggregate(groups, target, weights, result, numGroups, op);
 			return;
 		}
@@ -910,6 +917,38 @@ public class LibMatrixAgg
 	
 	/**
 	 * 
+	 * @param groups
+	 * @param result
+	 * @param numGroups
+	 * @throws DMLRuntimeException
+	 */
+	private static void groupedAggregateVecCount( MatrixBlock groups, MatrixBlock result, int numGroups ) 
+		throws DMLRuntimeException
+	{
+		//note: groups are always dense because 0 invalid
+		if( groups.isInSparseFormat() || groups.isEmptyBlock(false) )
+			throw new DMLRuntimeException("Unsupported sparse input for aggregate-count on group vector.");
+		
+		double[] a = groups.denseBlock;
+		int[] tmp = new int[numGroups];
+		int m = groups.rlen;
+		
+		//compute counts
+		for( int i = 0; i < m; i++ ) {
+			int g = (int) a[i];		
+			if ( g > numGroups )
+				continue;
+			tmp[g-1]++;
+		}
+		
+		//copy counts into result
+		for( int i=0; i<numGroups; i++ ) {
+			result.appendValue(i, 0, tmp[i]);
+		}
+	}
+	
+	/**
+	 * 
 	 * @param in
 	 * @param aggVal
 	 * @param aggCorr