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 2018/05/24 02:42:52 UTC

systemml git commit: [SYSTEMML-2343] Fix function call graph (analysis of second order funs)

Repository: systemml
Updated Branches:
  refs/heads/master a13632d45 -> 683b0f7f6


[SYSTEMML-2343] Fix function call graph (analysis of second order funs)

This patch fixes special cases of eval functions under persistent writes
or operations such as toString for which the function call graph
contained incorrect meta data. The missing info about second order
functions then led to the incorrect removal of "unused" functions and
thus errors due to missing functions.


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

Branch: refs/heads/master
Commit: 683b0f7f65b087b837cd2208753cbec0df1d3262
Parents: a13632d
Author: Matthias Boehm <mb...@gmail.com>
Authored: Wed May 23 19:42:05 2018 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Wed May 23 19:42:05 2018 -0700

----------------------------------------------------------------------
 .../sysml/hops/ipa/FunctionCallGraph.java       | 25 +--------------
 .../sysml/hops/rewrite/HopRewriteUtils.java     | 13 ++++++++
 .../sysml/parser/dml/DMLParserWrapper.java      |  4 +--
 .../functions/external/EvalFunctionTest.java    | 24 +++++++++-----
 .../scripts/functions/external/SecondOrder.dml  | 33 --------------------
 .../functions/external/SecondOrderBuiltin.dml   | 28 +++++++++++++++++
 .../functions/external/SecondOrderExternal.dml  | 33 ++++++++++++++++++++
 7 files changed, 93 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/683b0f7f/src/main/java/org/apache/sysml/hops/ipa/FunctionCallGraph.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ipa/FunctionCallGraph.java b/src/main/java/org/apache/sysml/hops/ipa/FunctionCallGraph.java
index c4e11db..b1bf301 100644
--- a/src/main/java/org/apache/sysml/hops/ipa/FunctionCallGraph.java
+++ b/src/main/java/org/apache/sysml/hops/ipa/FunctionCallGraph.java
@@ -23,7 +23,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -33,8 +32,6 @@ import java.util.stream.Collectors;
 import org.apache.sysml.hops.FunctionOp;
 import org.apache.sysml.hops.Hop;
 import org.apache.sysml.hops.HopsException;
-import org.apache.sysml.hops.Hop.DataOpTypes;
-import org.apache.sysml.hops.Hop.OpOpN;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.parser.DMLProgram;
 import org.apache.sysml.parser.ExternalFunctionStatement;
@@ -315,21 +312,8 @@ public class FunctionCallGraph
 			if( hopsDAG == null || hopsDAG.isEmpty() ) 
 				return false; //nothing to do
 
-			// BFS traverse the dag to find paramserv operator
-			// which can occur anyway in the entire dag
-			LinkedList<Hop> queue = new LinkedList<>(hopsDAG);
-			while (!queue.isEmpty()) {
-				Hop h = queue.poll();
-				if (h.isVisited())
-					continue;
-				if (HopRewriteUtils.isParameterBuiltinOp(h, Hop.ParamBuiltinOp.PARAMSERV))
-					return true;
-				if (!h.getInput().isEmpty())
-					queue.addAll(h.getInput());
-				h.setVisited();
-			}
-			
 			//function ops can only occur as root nodes of the dag
+			ret = HopRewriteUtils.containsSecondOrderBuiltin(hopsDAG);
 			for( Hop h : hopsDAG ) {
 				if( h instanceof FunctionOp ) {
 					FunctionOp fop = (FunctionOp) h;
@@ -382,13 +366,6 @@ public class FunctionCallGraph
 						ret = true;
 					}
 				}
-				else if( HopRewriteUtils.isData(h, DataOpTypes.TRANSIENTWRITE)
-						&& HopRewriteUtils.isNary(h.getInput().get(0), OpOpN.EVAL) ) {
-					//NOTE: after RewriteSplitDagDataDependentOperators, eval operators
-					//will always appear as childs to root nodes which allows for an
-					//efficient existence check without DAG traversal.
-					ret = true;
-				}
 			}
 		}
 		

http://git-wip-us.apache.org/repos/asf/systemml/blob/683b0f7f/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
index bfc9d40..269e9e6 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
@@ -1351,4 +1351,17 @@ public class HopRewriteUtils
 		return hop.getInput().stream().allMatch(
 			h -> dim1 ? h.rowsKnown() : h.colsKnown());
 	}
+	
+	public static boolean containsSecondOrderBuiltin(ArrayList<Hop> roots) {
+		Hop.resetVisitStatus(roots);
+		return roots.stream().anyMatch(r -> containsSecondOrderBuiltin(r));
+	}
+	
+	private static boolean containsSecondOrderBuiltin(Hop hop) {
+		if( hop.isVisited() ) return false;
+		hop.setVisited();
+		return HopRewriteUtils.isNary(hop, OpOpN.EVAL)
+			|| HopRewriteUtils.isParameterBuiltinOp(hop, Hop.ParamBuiltinOp.PARAMSERV)
+			|| hop.getInput().stream().anyMatch(c -> containsSecondOrderBuiltin(c));
+	}
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/683b0f7f/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java b/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
index b44d448..1d7daa1 100644
--- a/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
+++ b/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
@@ -84,9 +84,7 @@ public class DMLParserWrapper extends ParserWrapper
 	 */
 	@Override
 	public DMLProgram parse(String fileName, String dmlScript, Map<String,String> argVals) {
-		DMLProgram prog = doParse(fileName, dmlScript, null, argVals);
-		
-		return prog;
+		return doParse(fileName, dmlScript, null, argVals);
 	}
 	
 	/**

http://git-wip-us.apache.org/repos/asf/systemml/blob/683b0f7f/src/test/java/org/apache/sysml/test/integration/functions/external/EvalFunctionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/external/EvalFunctionTest.java b/src/test/java/org/apache/sysml/test/integration/functions/external/EvalFunctionTest.java
index 3165089..c098f05 100644
--- a/src/test/java/org/apache/sysml/test/integration/functions/external/EvalFunctionTest.java
+++ b/src/test/java/org/apache/sysml/test/integration/functions/external/EvalFunctionTest.java
@@ -29,7 +29,9 @@ import org.apache.sysml.test.integration.TestConfiguration;
 
 public class EvalFunctionTest extends AutomatedTestBase 
 {
-	private final static String TEST_NAME = "SecondOrder";
+	private final static String TEST_NAME1 = "SecondOrderExternal";
+	private final static String TEST_NAME2 = "SecondOrderBuiltin";
+	
 	private final static String TEST_DIR = "functions/external/";
 	private final static String TEST_CLASS_DIR = TEST_DIR + EvalFunctionTest.class.getSimpleName() + "/";
 	
@@ -38,22 +40,30 @@ public class EvalFunctionTest extends AutomatedTestBase
 	private final static int cols = 110;
 	private final static double sparsity = 0.7;
 	
-	
 	@Override
 	public void setUp() {
-		addTestConfiguration(TEST_NAME, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] { "Y" }) );
+		addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "Y" }) );
+		addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[] { "Y" }) );
 	}
 
 	@Test
-	public void runEvalFunctionTest() {
-		
-		TestConfiguration config = getTestConfiguration(TEST_NAME);
+	public void runEvalFunctionExternalTest() {
+		runEvalFunctionTest(TEST_NAME1);
+	}
+	
+	@Test
+	public void runEvalFunctionBuiltinTest() {
+		runEvalFunctionTest(TEST_NAME2);
+	}
+	
+	private void runEvalFunctionTest(String testname) {
+		TestConfiguration config = getTestConfiguration(testname);
 		config.addVariable("rows", rows);
 		config.addVariable("cols", cols);
 		loadTestConfiguration(config);
 		
 		String HOME = SCRIPT_DIR + TEST_DIR;
-		fullDMLScriptName = HOME + TEST_NAME + ".dml";
+		fullDMLScriptName = HOME + testname + ".dml";
 		programArgs = new String[]{"-args", input("X"), output("Y") };
 		
 		try {

http://git-wip-us.apache.org/repos/asf/systemml/blob/683b0f7f/src/test/scripts/functions/external/SecondOrder.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/external/SecondOrder.dml b/src/test/scripts/functions/external/SecondOrder.dml
deleted file mode 100644
index 88cbf47..0000000
--- a/src/test/scripts/functions/external/SecondOrder.dml
+++ /dev/null
@@ -1,33 +0,0 @@
-#-------------------------------------------------------------
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-# 
-#   http://www.apache.org/licenses/LICENSE-2.0
-# 
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-#-------------------------------------------------------------
-
-
-foo1 = externalFunction(String fname, Matrix[Double] A)
-return (Matrix[Double] B) 
-implemented in (classname="org.apache.sysml.udf.lib.EvalFunction", exectype="mem", secondorder="true")   
-
-foo2 = function(Matrix[Double] A) return(Matrix[Double] B) {
-   B = A + 7;
-}
-
-X = read($1);
-Y = foo1("foo2", X);
-write(Y, $2)

http://git-wip-us.apache.org/repos/asf/systemml/blob/683b0f7f/src/test/scripts/functions/external/SecondOrderBuiltin.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/external/SecondOrderBuiltin.dml b/src/test/scripts/functions/external/SecondOrderBuiltin.dml
new file mode 100644
index 0000000..b61d847
--- /dev/null
+++ b/src/test/scripts/functions/external/SecondOrderBuiltin.dml
@@ -0,0 +1,28 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+foo1 = function (matrix[double] A) return (matrix[double] B) {
+  B = A + 7
+}
+
+X = read($1);
+Y = eval("foo1", X);
+write(Y, $2);

http://git-wip-us.apache.org/repos/asf/systemml/blob/683b0f7f/src/test/scripts/functions/external/SecondOrderExternal.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/external/SecondOrderExternal.dml b/src/test/scripts/functions/external/SecondOrderExternal.dml
new file mode 100644
index 0000000..88cbf47
--- /dev/null
+++ b/src/test/scripts/functions/external/SecondOrderExternal.dml
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+
+foo1 = externalFunction(String fname, Matrix[Double] A)
+return (Matrix[Double] B) 
+implemented in (classname="org.apache.sysml.udf.lib.EvalFunction", exectype="mem", secondorder="true")   
+
+foo2 = function(Matrix[Double] A) return(Matrix[Double] B) {
+   B = A + 7;
+}
+
+X = read($1);
+Y = foo1("foo2", X);
+write(Y, $2)