Repository: systemml
Updated Branches:
  refs/heads/master ddaf166fb -> 868b4b98a


[SYSTEMML-2148] Performance codegen cell ops over compressed matrices

This patch makes a minor performance improvement to codegen cell
operations over compressed matrices, especially for multi-threaded
execution. Specifically, we now reuse in a thread-local manner the
allocated count arrays across column groups.


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

Branch: refs/heads/master
Commit: 868b4b98a48d549b4f9670a590693c05613d14b3
Parents: ddaf166
Author: Matthias Boehm <mboe...@gmail.com>
Authored: Wed Feb 14 21:48:53 2018 -0800
Committer: Matthias Boehm <mboe...@gmail.com>
Committed: Wed Feb 14 22:10:45 2018 -0800

----------------------------------------------------------------------
 .../apache/sysml/runtime/codegen/SpoofCellwise.java   |  7 +++++--
 .../apache/sysml/runtime/compress/ColGroupDDC1.java   |  8 ++++----
 .../apache/sysml/runtime/compress/ColGroupDDC2.java   |  8 ++++----
 .../apache/sysml/runtime/compress/ColGroupOLE.java    |  8 ++++----
 .../apache/sysml/runtime/compress/ColGroupRLE.java    |  8 ++++----
 .../apache/sysml/runtime/compress/ColGroupValue.java  | 14 ++++++++++++--
 6 files changed, 33 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/868b4b98/src/main/java/org/apache/sysml/runtime/codegen/SpoofCellwise.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/codegen/SpoofCellwise.java 
b/src/main/java/org/apache/sysml/runtime/codegen/SpoofCellwise.java
index 5080e6c..b7024ed 100644
--- a/src/main/java/org/apache/sysml/runtime/codegen/SpoofCellwise.java
+++ b/src/main/java/org/apache/sysml/runtime/codegen/SpoofCellwise.java
@@ -1082,10 +1082,13 @@ public abstract class SpoofCellwise extends 
SpoofOperator implements Serializabl
                if( sparseSafe && b.length==0 && !a.hasUncompressedColGroup() ) 
{
                        //note: all remaining groups are guaranteed 
ColGroupValue
                        boolean entireGrp = (rl==0 && ru==a.getNumRows());
+                       int maxNumVals = a.getColGroups().stream().mapToInt(
+                               g -> 
((ColGroupValue)g).getNumValues()).max().orElse(0);
+                       int[] counts = new int[maxNumVals];
                        for( ColGroup grp : a.getColGroups() ) {
                                ColGroupValue grpv = (ColGroupValue) grp;
-                               int[] counts = entireGrp ? 
-                                       grpv.getCounts() : grpv.getCounts(rl, 
ru);
+                               counts = entireGrp ? grpv.getCounts(counts) :
+                                       grpv.getCounts(rl, ru, counts);
                                for(int k=0; k<grpv.getNumValues(); k++) {
                                        kbuff2.set(0, 0);
                                        double in = grpv.sumValues(k, kplus, 
kbuff2);

http://git-wip-us.apache.org/repos/asf/systemml/blob/868b4b98/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC1.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC1.java 
b/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC1.java
index 117a1d3..565aa8f 100644
--- a/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC1.java
+++ b/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC1.java
@@ -204,14 +204,14 @@ public class ColGroupDDC1 extends ColGroupDDC
        }
        
        @Override 
-       public int[] getCounts() {
-               return getCounts(0, getNumRows());
+       public int[] getCounts(int[] counts) {
+               return getCounts(0, getNumRows(), counts);
        }
        
        @Override 
-       public int[] getCounts(int rl, int ru) {
+       public int[] getCounts(int rl, int ru, int[] counts) {
                final int numVals = getNumValues();
-               int[] counts = new int[numVals];
+               Arrays.fill(counts, 0, numVals, 0);
                for( int i=rl; i<ru; i++ )
                        counts[_data[i]&0xFF] ++;
                return counts;

http://git-wip-us.apache.org/repos/asf/systemml/blob/868b4b98/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC2.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC2.java 
b/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC2.java
index 6303ff0..28e565c 100644
--- a/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC2.java
+++ b/src/main/java/org/apache/sysml/runtime/compress/ColGroupDDC2.java
@@ -193,14 +193,14 @@ public class ColGroupDDC2 extends ColGroupDDC
        }
        
        @Override 
-       public int[] getCounts() {
-               return getCounts(0, getNumRows());
+       public int[] getCounts(int[] counts) {
+               return getCounts(0, getNumRows(), counts);
        }
        
        @Override 
-       public int[] getCounts(int rl, int ru) {
+       public int[] getCounts(int rl, int ru, int[] counts) {
                final int numVals = getNumValues();
-               int[] counts = new int[numVals];
+               Arrays.fill(counts, 0, numVals, 0);
                for( int i=rl; i<ru; i++ )
                        counts[_data[i]] ++;
                return counts;

http://git-wip-us.apache.org/repos/asf/systemml/blob/868b4b98/src/main/java/org/apache/sysml/runtime/compress/ColGroupOLE.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/compress/ColGroupOLE.java 
b/src/main/java/org/apache/sysml/runtime/compress/ColGroupOLE.java
index e466369..4561c14 100644
--- a/src/main/java/org/apache/sysml/runtime/compress/ColGroupOLE.java
+++ b/src/main/java/org/apache/sysml/runtime/compress/ColGroupOLE.java
@@ -229,9 +229,9 @@ public class ColGroupOLE extends ColGroupOffset
        }
        
        @Override 
-       public int[] getCounts() {
+       public int[] getCounts(int[] counts) {
                final int numVals = getNumValues();
-               int[] counts = new int[numVals];
+               Arrays.fill(counts, 0, numVals, 0);
                for (int k = 0; k < numVals; k++) {
                        int boff = _ptr[k];
                        int blen = len(k);
@@ -245,10 +245,10 @@ public class ColGroupOLE extends ColGroupOffset
        }
        
        @Override 
-       public int[] getCounts(int rl, int ru) {
+       public int[] getCounts(int rl, int ru, int[] counts) {
                final int blksz = BitmapEncoder.BITMAP_BLOCK_SZ;
                final int numVals = getNumValues();
-               int[] counts = new int[numVals];
+               Arrays.fill(counts, 0, numVals, 0);
                for (int k = 0; k < numVals; k++) {
                        int boff = _ptr[k];
                        int blen = len(k);

http://git-wip-us.apache.org/repos/asf/systemml/blob/868b4b98/src/main/java/org/apache/sysml/runtime/compress/ColGroupRLE.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/compress/ColGroupRLE.java 
b/src/main/java/org/apache/sysml/runtime/compress/ColGroupRLE.java
index 876012f..cbdf4a5 100644
--- a/src/main/java/org/apache/sysml/runtime/compress/ColGroupRLE.java
+++ b/src/main/java/org/apache/sysml/runtime/compress/ColGroupRLE.java
@@ -225,9 +225,9 @@ public class ColGroupRLE extends ColGroupOffset
        }
        
        @Override 
-       public int[] getCounts() {
+       public int[] getCounts(int[] counts) {
                final int numVals = getNumValues();
-               int[] counts = new int[numVals];
+               Arrays.fill(counts, 0, numVals, 0);
                for (int k = 0; k < numVals; k++) {
                        int boff = _ptr[k];
                        int blen = len(k);
@@ -244,9 +244,9 @@ public class ColGroupRLE extends ColGroupOffset
        }
        
        @Override 
-       public int[] getCounts(int rl, int ru) {
+       public int[] getCounts(int rl, int ru, int[] counts) {
                final int numVals = getNumValues();
-               int[] counts = new int[numVals];
+               Arrays.fill(counts, 0, numVals, 0);
                for (int k = 0; k < numVals; k++) {
                        int boff = _ptr[k];
                        int blen = len(k);

http://git-wip-us.apache.org/repos/asf/systemml/blob/868b4b98/src/main/java/org/apache/sysml/runtime/compress/ColGroupValue.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/compress/ColGroupValue.java 
b/src/main/java/org/apache/sysml/runtime/compress/ColGroupValue.java
index a416c5e..2e5dc78 100644
--- a/src/main/java/org/apache/sysml/runtime/compress/ColGroupValue.java
+++ b/src/main/java/org/apache/sysml/runtime/compress/ColGroupValue.java
@@ -149,9 +149,19 @@ public abstract class ColGroupValue extends ColGroup
                return ret;
        }
        
-       public abstract int[] getCounts();
+       public final int[] getCounts() {
+               int[] tmp = new int[getNumValues()];
+               return getCounts(tmp);
+       }
+       
+       public abstract int[] getCounts(int[] out);
+       
+       public final int[] getCounts(int rl, int ru) {
+               int[] tmp = new int[getNumValues()];
+               return getCounts(rl, ru, tmp);
+       }
        
-       public abstract int[] getCounts(int rl, int ru);
+       public abstract int[] getCounts(int rl, int ru, int[] out);
        
        public int[] getCounts(boolean inclZeros) {
                int[] counts = getCounts();

Reply via email to