You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by du...@apache.org on 2017/05/05 20:47:09 UTC

[1/3] incubator-systemml git commit: [SYSTEMML-1554] IPA Scalar Transient Read Replacement

Repository: incubator-systemml
Updated Branches:
  refs/heads/master 2c5c3b14e -> abc9686fb


[SYSTEMML-1554] IPA Scalar Transient Read Replacement

Currently, during IPA we collect all variables (scalars & matrices)
eligible for propagation across blocks (i.e. not updated in block), and
then propagate only the matrix sizes across the blocks. This extends
IPA to also replace all eligible scalar transient reads with literals
based on the variables that have already been collected.  The benefit is
that many ops will be able to determine their respective output sizes
during regular compilation, instead of having to wait until dynamic
recompilation, and thus we can reduce the pressure on dynamic
recompilation.  Additionally, this literal replacement applies to all
current and future operations, rather than only a set of supported
operations.

Closes #468.


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

Branch: refs/heads/master
Commit: 0b1dcddf2efb9af859f7c9cd3f54128ee2ab3d86
Parents: 2c5c3b1
Author: Mike Dusenberry <mw...@us.ibm.com>
Authored: Fri May 5 13:45:13 2017 -0700
Committer: Mike Dusenberry <mw...@us.ibm.com>
Committed: Fri May 5 13:45:13 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/ipa/InterProceduralAnalysis.java | 25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/0b1dcddf/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
index b0ebfaa..6068ce7 100644
--- a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
+++ b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
@@ -535,6 +535,9 @@ public class InterProceduralAnalysis
 			//old stats in, new stats out if updated
 			ArrayList<Hop> roots = sb.get_hops();
 			DMLProgram prog = sb.getDMLProg();
+			//replace scalar reads with literals
+			Hop.resetVisitStatus(roots);
+			propagateScalarsAcrossDAG(roots, callVars);
 			//refresh stats across dag
 			Hop.resetVisitStatus(roots);
 			propagateStatisticsAcrossDAG(roots, callVars);
@@ -543,7 +546,27 @@ public class InterProceduralAnalysis
 			propagateStatisticsIntoFunctions(prog, roots, fcand, callVars, fcandSafeNNZ, unaryFcands, fnStack);
 		}
 	}
-	
+
+	/**
+	 * Propagate scalar values across DAGs.
+	 *
+	 * This replaces scalar reads and typecasts thereof with literals.
+	 *
+	 * @param roots  List of HOPs.
+	 * @param vars  Map of variables eligible for propagation.
+	 * @throws HopsException
+	 */
+	private void propagateScalarsAcrossDAG(ArrayList<Hop> roots, LocalVariableMap vars)
+		throws HopsException
+	{
+		for (Hop hop : roots) {
+			try {
+				Recompiler.rReplaceLiterals(hop, vars, true);
+			} catch (Exception ex) {
+				throw new HopsException("Failed to perform scalar literal replacement.", ex);
+			}
+		}
+	}
 
 	private void propagateStatisticsAcrossPredicateDAG( Hop root, LocalVariableMap vars ) 
 		throws HopsException


[2/3] incubator-systemml git commit: [SYSTEMML-1575] DataType Change Test Fix

Posted by du...@apache.org.
[SYSTEMML-1575] DataType Change Test Fix

While working on SYSTEMML-1554, an additional bug was uncovered.
Specifically, with the new IPA scalar replacement enhancement, the
`org.apache.sysml.test.integration.functions.misc.DataTypeChangeTest#testDataTypeChangeValidate4c`
test started to fail due to attempts to cast a Matrix to a Scalar
object during IPA scalar replacement.  This was due to a bug in which
if the calling program reassigned a variable to the output of a
function, and the datatype differed between that variable and the
function output, the calling program's variable map would not be
updated to remove this variable.  Thus, a variable of the incorrect
datatype would remain in the calling program, and  when the new IPA
scalar replacement ran over the rest of the calling program, it would
attempt to replace a scalar using the value in the calling program
variable map, which would incorrectly still be a matrix type.  This
bug did not show up before since we did not previously employ IPA
scalar replacement.

This fix updates the `extractFunctionCallReturnStatistics` method
to remove the variable from the calling program's variable map if
the calling program is reassigning a variable to the output of this
function and the datatypes differ.

Closes #468.


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

Branch: refs/heads/master
Commit: a281f38c750d9fcaba2b91aba8dbd360be7037ca
Parents: 0b1dcdd
Author: Mike Dusenberry <mw...@us.ibm.com>
Authored: Fri May 5 13:45:18 2017 -0700
Committer: Mike Dusenberry <mw...@us.ibm.com>
Committed: Fri May 5 13:45:18 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/ipa/InterProceduralAnalysis.java      | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/a281f38c/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
index 6068ce7..37fa379 100644
--- a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
+++ b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
@@ -747,7 +747,20 @@ public class InterProceduralAnalysis
 				DataIdentifier di = foutputOps.get(i);
 				String fvarname = di.getName(); //name in function signature
 				String pvarname = outputVars[i]; //name in calling program
-				
+
+				// If the calling program is reassigning a variable with the output of this
+				// function, and the datatype differs between that variable and this function
+				// output, remove that variable from the calling program's variable map.
+				if( callVars.keySet().contains(pvarname) ) {
+					DataType fdataType = di.getDataType();
+					DataType pdataType = callVars.get(pvarname).getDataType();
+					if( fdataType != pdataType ) {
+						// datatype has changed, and the calling program is reassigning the
+						// the variable, so remove it from the calling variable map
+						callVars.remove(pvarname);
+					}
+				}
+				// Update or add to the calling program's variable map.
 				if( di.getDataType()==DataType.MATRIX && tmpVars.keySet().contains(fvarname) )
 				{
 					MatrixObject moIn = (MatrixObject) tmpVars.get(fvarname);


[3/3] incubator-systemml git commit: [MINOR] Adding documentation to IPA functions.

Posted by du...@apache.org.
[MINOR] Adding documentation to IPA functions.


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

Branch: refs/heads/master
Commit: abc9686fbaaa11c12cfa02c49c7675165acdf176
Parents: a281f38
Author: Mike Dusenberry <mw...@us.ibm.com>
Authored: Fri May 5 13:45:23 2017 -0700
Committer: Mike Dusenberry <mw...@us.ibm.com>
Committed: Fri May 5 13:45:23 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/ipa/InterProceduralAnalysis.java | 87 ++++++++++++++++++--
 .../apache/sysml/hops/recompile/Recompiler.java | 11 ++-
 2 files changed, 87 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/abc9686f/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
index 37fa379..95a6069 100644
--- a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
+++ b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
@@ -460,8 +460,21 @@ public class InterProceduralAnalysis
 	/////////////////////////////
 	// INTRA-PROCEDURE ANALYSIS
 	//////	
-	
-	private void propagateStatisticsAcrossBlock( StatementBlock sb, Map<String, Integer> fcand, LocalVariableMap callVars, Map<String, Set<Long>> fcandSafeNNZ, Set<String> unaryFcands, Set<String> fnStack ) 
+
+	/**
+	 * Perform intra-procedural analysis (IPA) by propagating statistics
+	 * across statement blocks.
+	 *
+	 * @param sb  DML statement blocks.
+	 * @param fcand  Function candidates.
+	 * @param callVars  Map of variables eligible for propagation.
+	 * @param fcandSafeNNZ  Function candidate safe non-zeros.
+	 * @param unaryFcands  Unary function candidates.
+	 * @param fnStack  Function stack to determine current scope.
+	 * @throws HopsException  If a HopsException occurs.
+	 * @throws ParseException  If a ParseException occurs.
+	 */
+	private void propagateStatisticsAcrossBlock( StatementBlock sb, Map<String, Integer> fcand, LocalVariableMap callVars, Map<String, Set<Long>> fcandSafeNNZ, Set<String> unaryFcands, Set<String> fnStack )
 		throws HopsException, ParseException
 	{
 		if (sb instanceof FunctionStatementBlock)
@@ -552,9 +565,15 @@ public class InterProceduralAnalysis
 	 *
 	 * This replaces scalar reads and typecasts thereof with literals.
 	 *
+	 * Ultimately, this leads to improvements because the size
+	 * expression evaluation over DAGs with scalar symbol table entries
+	 * (which is also applied during IPA) is limited to supported
+	 * operations, whereas literal replacement is a brute force method
+	 * that applies to all (including future) operations.
+	 *
 	 * @param roots  List of HOPs.
 	 * @param vars  Map of variables eligible for propagation.
-	 * @throws HopsException
+	 * @throws HopsException  If a HopsException occurs.
 	 */
 	private void propagateScalarsAcrossDAG(ArrayList<Hop> roots, LocalVariableMap vars)
 		throws HopsException
@@ -589,8 +608,15 @@ public class InterProceduralAnalysis
 			throw new HopsException("Failed to update Hop DAG statistics.", ex);
 		}
 	}
-	
-	private void propagateStatisticsAcrossDAG( ArrayList<Hop> roots, LocalVariableMap vars ) 
+
+	/**
+	 * Propagate matrix sizes across DAGs.
+	 *
+	 * @param roots  List of HOP DAG root nodes.
+	 * @param vars  Map of variables eligible for propagation.
+	 * @throws HopsException  If a HopsException occurs.
+	 */
+	private void propagateStatisticsAcrossDAG( ArrayList<Hop> roots, LocalVariableMap vars )
 		throws HopsException
 	{
 		if( roots == null )
@@ -615,14 +641,44 @@ public class InterProceduralAnalysis
 	/////////////////////////////
 	// INTER-PROCEDURE ANALYIS
 	//////
-	
-	private void propagateStatisticsIntoFunctions(DMLProgram prog, ArrayList<Hop> roots, Map<String, Integer> fcand, LocalVariableMap callVars, Map<String, Set<Long>> fcandSafeNNZ, Set<String> unaryFcands, Set<String> fnStack ) 
+
+	/**
+	 * Propagate statistics from the calling program into a function
+	 * block.
+	 *
+	 * @param prog  The DML program.
+	 * @param roots List of HOP DAG root notes for propagation.
+	 * @param fcand  Function candidates.
+	 * @param callVars  Calling program's map of variables eligible for
+	 *                     propagation.
+	 * @param fcandSafeNNZ  Function candidate safe non-zeros.
+	 * @param unaryFcands  Unary function candidates.
+	 * @param fnStack  Function stack to determine current scope.
+	 * @throws HopsException  If a HopsException occurs.
+	 * @throws ParseException  If a ParseException occurs.
+	 */
+	private void propagateStatisticsIntoFunctions(DMLProgram prog, ArrayList<Hop> roots, Map<String, Integer> fcand, LocalVariableMap callVars, Map<String, Set<Long>> fcandSafeNNZ, Set<String> unaryFcands, Set<String> fnStack )
 			throws HopsException, ParseException
 	{
 		for( Hop root : roots )
 			propagateStatisticsIntoFunctions(prog, root, fcand, callVars, fcandSafeNNZ, unaryFcands, fnStack);
 	}
-	
+
+	/**
+	 * Propagate statistics from the calling program into a function
+	 * block.
+	 *
+	 * @param prog  The DML program.
+	 * @param hop HOP to propagate statistics into.
+	 * @param fcand  Function candidates.
+	 * @param callVars  Calling program's map of variables eligible for
+	 *                     propagation.
+	 * @param fcandSafeNNZ  Function candidate safe non-zeros.
+	 * @param unaryFcands  Unary function candidates.
+	 * @param fnStack  Function stack to determine current scope.
+	 * @throws HopsException  If a HopsException occurs.
+	 * @throws ParseException  If a ParseException occurs.
+	 */
 	private void propagateStatisticsIntoFunctions(DMLProgram prog, Hop hop, Map<String, Integer> fcand, LocalVariableMap callVars, Map<String, Set<Long>> fcandSafeNNZ, Set<String> unaryFcands, Set<String> fnStack ) 
 		throws HopsException, ParseException
 	{
@@ -732,7 +788,20 @@ public class InterProceduralAnalysis
 			}
 		}
 	}
-	
+
+	/**
+	 * Extract return variable statistics from this function into the
+	 * calling program.
+	 *
+	 * @param fstmt  The function statement.
+	 * @param fop  The function op.
+	 * @param tmpVars  Function's map of variables eligible for
+	 *                    extraction.
+	 * @param callVars  Calling program's map of variables.
+	 * @param overwrite  Whether or not to overwrite variables in the
+	 *                      calling program's variable map.
+	 * @throws HopsException  If a HopsException occurs.
+	 */
 	private void extractFunctionCallReturnStatistics( FunctionStatement fstmt, FunctionOp fop, LocalVariableMap tmpVars, LocalVariableMap callVars, boolean overwrite ) 
 		throws HopsException
 	{

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/abc9686f/src/main/java/org/apache/sysml/hops/recompile/Recompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/recompile/Recompiler.java b/src/main/java/org/apache/sysml/hops/recompile/Recompiler.java
index 6a2d88c..6c8ddea 100644
--- a/src/main/java/org/apache/sysml/hops/recompile/Recompiler.java
+++ b/src/main/java/org/apache/sysml/hops/recompile/Recompiler.java
@@ -1311,12 +1311,19 @@ public class Recompiler
 		}
 		
 	}
-	
+
+	/**
+	 * Remove any scalar variables from the variable map if the variable
+	 * is updated in this block.
+	 *
+	 * @param callVars  Map of variables eligible for propagation.
+	 * @param sb  DML statement block.
+	 */
 	public static void removeUpdatedScalars( LocalVariableMap callVars, StatementBlock sb )
 	{
 		if( sb != null )
 		{
-			//remove update scalar variables from constants
+			//remove updated scalar variables from constants
 			for( String varname : sb.variablesUpdated().getVariables().keySet() )
 			{
 				Data dat = callVars.get(varname);