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 2017/10/09 03:16:53 UTC

systemml git commit: [SYSTEMML-1947] Performance cp read sparse binary matrices (seq, par)

Repository: systemml
Updated Branches:
  refs/heads/master 0505fd38c -> d9c09e771


[SYSTEMML-1947] Performance cp read sparse binary matrices (seq, par)

A previous performance improvement for reading ultra-sparse binary block
matrices (SYSTEMML-1838) changed the block format of temporary reuse
blocks from MCSR to CSR. For specific scenarios of sparse matrices with
a number of columns lower or equal the blocksize, this caused a fallback
from efficient row copies to the default path of value appends. This was
problematic because it leads to repeated reallocations in the presence
of skew that are unnecessary for matrices with a single column block. 

This patch improves this codepath for all sparse block formats,
including the currently used CSR blocks. By leveraging efficient row
copies without redundant deep copy or reallocations, this modification
significantly reduces GC overhead.

On a scenario of reading the Mnist8m dataset (19GB, sp=0.25) from HDFS,
this patch improved performance from 30.1s (19s GC) to 20.3s (11s GC).


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

Branch: refs/heads/master
Commit: d9c09e77196516c17c80813c7ed60378a1515f51
Parents: 0505fd3
Author: Matthias Boehm <mb...@gmail.com>
Authored: Sun Oct 8 20:16:55 2017 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Sun Oct 8 20:17:10 2017 -0700

----------------------------------------------------------------------
 .../sysml/runtime/io/ReaderBinaryBlock.java     |  2 +-
 .../runtime/io/ReaderBinaryBlockParallel.java   | 20 ++++++++++----------
 .../sysml/runtime/matrix/data/MatrixBlock.java  | 11 +++++++----
 3 files changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/d9c09e77/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlock.java b/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlock.java
index e0c217a..5b5b8ca 100644
--- a/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlock.java
+++ b/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlock.java
@@ -110,7 +110,7 @@ public class ReaderBinaryBlock extends MatrixReader
 		MatrixBlock value = new MatrixBlock(brlen, bclen, sparse);
 		if( sparse ) {
 			value.allocateAndResetSparseRowsBlock(true, SparseBlock.Type.CSR);
-			value.getSparseBlock().allocate(0, 1024);
+			value.getSparseBlock().allocate(0, brlen*bclen);
 		}
 		return value;
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/d9c09e77/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlockParallel.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlockParallel.java b/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlockParallel.java
index 16260a8..374e795 100644
--- a/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlockParallel.java
+++ b/src/main/java/org/apache/sysml/runtime/io/ReaderBinaryBlockParallel.java
@@ -62,10 +62,10 @@ public class ReaderBinaryBlockParallel extends ReaderBinaryBlock
 		JobConf job = new JobConf(ConfigurationManager.getCachedJobConf());	
 		Path path = new Path( (_localFS ? "file:///" : "") + fname); 
 		FileSystem fs = IOUtilFunctions.getFileSystem(path, job);
-				
+		
 		//check existence and non-empty file
 		checkValidInputFile(fs, path); 
-	
+		
 		//core read 
 		readBinaryBlockMatrixFromHDFS(path, job, fs, ret, rlen, clen, brlen, bclen);
 		
@@ -79,7 +79,7 @@ public class ReaderBinaryBlockParallel extends ReaderBinaryBlock
 
 	private static void readBinaryBlockMatrixFromHDFS( Path path, JobConf job, FileSystem fs, MatrixBlock dest, long rlen, long clen, int brlen, int bclen )
 		throws IOException, DMLRuntimeException
-	{			
+	{
 		//set up preferred custom serialization framework for binary block format
 		if( MRJobConfiguration.USE_BINARYBLOCK_SERIALIZATION )
 			MRJobConfiguration.addBinaryBlockSerializationFramework( job );
@@ -95,7 +95,7 @@ public class ReaderBinaryBlockParallel extends ReaderBinaryBlock
 			}
 
 			//wait until all tasks have been executed
-			List<Future<Object>> rt = pool.invokeAll(tasks);	
+			List<Future<Object>> rt = pool.invokeAll(tasks);
 			
 			//check for exceptions and aggregate nnz
 			long lnnz = 0;
@@ -158,15 +158,15 @@ public class ReaderBinaryBlockParallel extends ReaderBinaryBlock
 					
 					int row_offset = (int)(key.getRowIndex()-1)*_brlen;
 					int col_offset = (int)(key.getColumnIndex()-1)*_bclen;
-					
 					int rows = value.getNumRows();
 					int cols = value.getNumColumns();
 					
 					//bound check per block
-					if( row_offset + rows < 0 || row_offset + rows > _rlen || col_offset + cols<0 || col_offset + cols > _clen )
-					{
-						throw new IOException("Matrix block ["+(row_offset+1)+":"+(row_offset+rows)+","+(col_offset+1)+":"+(col_offset+cols)+"] " +
-								              "out of overall matrix range [1:"+_rlen+",1:"+_clen+"].");
+					if( row_offset + rows < 0 || row_offset + rows > _rlen 
+						|| col_offset + cols<0 || col_offset + cols > _clen ) {
+						throw new IOException("Matrix block ["+(row_offset+1)+":"
+							+(row_offset+rows)+","+(col_offset+1)+":"+(col_offset+cols)+"] " +
+							"out of overall matrix range [1:"+_rlen+",1:"+_clen+"].");
 					}
 			
 					//copy block to result
@@ -196,7 +196,7 @@ public class ReaderBinaryBlockParallel extends ReaderBinaryBlock
 					else
 					{
 						_dest.copy( row_offset, row_offset+rows-1, 
-								   col_offset, col_offset+cols-1, value, false );
+							col_offset, col_offset+cols-1, value, false );
 					}
 					
 					//aggregate nnz

http://git-wip-us.apache.org/repos/asf/systemml/blob/d9c09e77/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
index 5b1e663..aee9956 100644
--- a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
+++ b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
@@ -725,11 +725,14 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab
 			{
 				if( b.isEmpty(i) ) continue;
 				int aix = rowoffset+i;
-					
+				
 				//single block append (avoid re-allocations)
-				if( sparseBlock.isEmpty(aix) && coloffset==0
-					&& b instanceof SparseBlockMCSR ) { 
-					sparseBlock.set(aix, b.get(i), deep);
+				if( sparseBlock.isEmpty(aix) && coloffset==0 ) { 
+					//note: the deep copy flag is only relevant for MCSR due to
+					//shallow references of b.get(i); other block formats do not
+					//require a redundant copy because b.get(i) created a new row.
+					boolean ldeep = (deep && b instanceof SparseBlockMCSR);
+					sparseBlock.set(aix, b.get(i), ldeep);
 				}
 				else { //general case
 					int pos = b.pos(i);