Repository: systemml
Updated Branches:
  refs/heads/master b02599c6d -> 367935fad


[SYSTEMML-2091] Performance sparse-sparse reshape (shallow for CSR)

This patch improves the performance of sparse-sparse reshape operations
for the special case of N:1 row mappings and inputs in CSR format.
Specifically, we now allocate the output in the memory-efficient CSR
representation as well which allows for a shallow copy of the values
array. The row pointers and column indexes are, however, reconstructed.

On a scenario of 10 iterations of reshaping a 100K x 10K matrix with
sparsity 0.1 to a 10K x 100K matrix, this patch improved the total
runtime from 16.2s to 2.6s


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

Branch: refs/heads/master
Commit: 367935fadba335d6e1d7502d9a80115b0b2bf2e2
Parents: b02599c
Author: Matthias Boehm <[email protected]>
Authored: Fri Jan 26 23:00:36 2018 -0800
Committer: Matthias Boehm <[email protected]>
Committed: Fri Jan 26 23:00:36 2018 -0800

----------------------------------------------------------------------
 .../runtime/matrix/data/LibMatrixReorg.java     | 28 +++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/367935fa/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixReorg.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixReorg.java 
b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixReorg.java
index 1c34252..59df934 100644
--- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixReorg.java
+++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixReorg.java
@@ -1221,6 +1221,28 @@ public class LibMatrixReorg
                                                c.append(0, cix+aix[j], 
avals[j]);
                                }
                        }
+                       else if( cols%clen==0 //SPECIAL CSR N:1 MATRIX->MATRIX
+                               && SHALLOW_COPY_REORG && SPARSE_OUTPUTS_IN_CSR
+                               && a instanceof SparseBlockCSR ) { //int nnz
+                               int[] aix = ((SparseBlockCSR)a).indexes();
+                               int n = cols/clen, pos = 0;
+                               int[] rptr = new int[rows+1];
+                               int[] indexes = new int[(int)a.size()];
+                               rptr[0] = 0;
+                               for(int bi=0, ci=0; bi<rlen; bi+=n, ci++) {
+                                       for( int i=bi, cix=0; i<bi+n; i++, 
cix+=clen ) {
+                                               if(a.isEmpty(i)) continue;
+                                               int apos = a.pos(i);
+                                               int alen = a.size(i);
+                                               for( int j=apos; j<apos+alen; 
j++ )
+                                                       indexes[pos++] = 
cix+aix[j];
+                                       }
+                                       rptr[ci+1] = pos;
+                               }
+                               //create CSR block with shallow copy of values
+                               out.sparseBlock = new SparseBlockCSR(rptr, 
indexes,
+                                       ((SparseBlockCSR)a).values(), pos);
+                       }
                        else if( cols%clen==0 ) { //SPECIAL N:1 MATRIX->MATRIX
                                int n = cols/clen;
                                for(int bi=0, ci=0; bi<rlen; bi+=n, ci++) {
@@ -1234,10 +1256,8 @@ public class LibMatrixReorg
                                                int alen = a.size(i);
                                                int[] aix = a.indexes(i);
                                                double[] avals = a.values(i);
-                                               for( int j=apos; j<apos+alen; 
j++ ) {
-                                                       int cj = 
(int)((cix+aix[j])%cols);
-                                                       c.append(ci, cj, 
avals[j]);
-                                               }
+                                               for( int j=apos; j<apos+alen; 
j++ )
+                                                       c.append(ci, 
cix+aix[j], avals[j]);
                                        }
                                }
                        }

Reply via email to