You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by ni...@apache.org on 2017/05/01 23:56:24 UTC

incubator-systemml git commit: [SYSTEMML-1552] Allow Python mllearn estimators to force the usage of GPU

Repository: incubator-systemml
Updated Branches:
  refs/heads/master 8e5599dd9 -> 1cc219527


[SYSTEMML-1552] Allow Python mllearn estimators to force the usage of GPU

Closes #480.


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

Branch: refs/heads/master
Commit: 1cc219527c88a85b256f3c2230e06b176b4fd679
Parents: 8e5599d
Author: Niketan Pansare <np...@us.ibm.com>
Authored: Mon May 1 15:55:44 2017 -0800
Committer: Niketan Pansare <np...@us.ibm.com>
Committed: Mon May 1 16:55:44 2017 -0700

----------------------------------------------------------------------
 .../apache/sysml/api/mlcontext/MLContext.java   | 16 ++++++
 .../sysml/api/mlcontext/ScriptExecutor.java     | 14 +++++
 src/main/python/systemml/mlcontext.py           | 23 ++++++++
 src/main/python/systemml/mllearn/estimators.py  | 60 ++++++++++++++++++--
 .../sysml/api/ml/BaseSystemMLClassifier.scala   |  8 ++-
 5 files changed, 116 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/1cc21952/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
index 41df7fd..7887b7b 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
@@ -98,6 +98,11 @@ public class MLContext {
 	 * Whether or not GPU mode should be enabled
 	 */
 	private boolean gpu = false;
+	
+	/**
+	 * Whether or not GPU mode should be force
+	 */
+	private boolean forceGPU = false;
 
 	/**
 	 * The number of heavy hitters that are printed as part of the statistics
@@ -273,6 +278,7 @@ public class MLContext {
 		scriptExecutor.setExplain(explain);
 		scriptExecutor.setExplainLevel(explainLevel);
 		scriptExecutor.setGPU(gpu);
+		scriptExecutor.setForceGPU(forceGPU);
 		scriptExecutor.setStatistics(statistics);
 		scriptExecutor.setStatisticsMaxHeavyHitters(statisticsMaxHeavyHitters);
 		scriptExecutor.setInit(scriptHistoryStrings.isEmpty());
@@ -419,6 +425,16 @@ public class MLContext {
 	public void setGPU(boolean enable) {
 		this.gpu = enable;
 	}
+	
+	/**
+	 * Whether or not to explicitly "force" the usage of GPU.
+	 * If a GPU is not available, and the GPU mode is set or if available memory on GPU is less, SystemML will crash when the program is run.
+	 * @param enable
+	 * 					true if needs to be enabled, false otherwise
+	 */
+	public void setForceGPU(boolean enable) {
+		this.forceGPU = enable;
+	}
 
 	/**
 	 * Whether or not the GPU mode is enabled.

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/1cc21952/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java b/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
index bb891ca..2044875 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
@@ -118,6 +118,8 @@ public class ScriptExecutor {
 	protected boolean explain = false;
 	protected boolean gpu = false;
 	protected boolean oldGPU = false;
+	protected boolean forceGPU = false;
+	protected boolean oldForceGPU = false;
 	protected boolean statistics = false;
 	protected boolean oldStatistics = false;
 	protected ExplainLevel explainLevel;
@@ -248,7 +250,9 @@ public class ScriptExecutor {
 		}
 		oldGPU = DMLScript.USE_ACCELERATOR; 
 		oldStatistics = DMLScript.STATISTICS;
+		oldForceGPU = DMLScript.FORCE_ACCELERATOR;
 		DMLScript.USE_ACCELERATOR = gpu;
+		DMLScript.FORCE_ACCELERATOR = forceGPU;
 		DMLScript.STATISTICS = statistics;
 	}
 
@@ -335,6 +339,7 @@ public class ScriptExecutor {
 	protected void cleanupAfterExecution() {
 		restoreInputsInSymbolTable();
 		DMLScript.USE_ACCELERATOR = oldGPU;
+		DMLScript.FORCE_ACCELERATOR = oldForceGPU;
 		DMLScript.STATISTICS = oldStatistics;
 	}
 
@@ -652,5 +657,14 @@ public class ScriptExecutor {
 	public void setGPU(boolean enabled) {
 		this.gpu = enabled;
 	}
+	
+	/**
+	 * Whether or not to force GPU usage
+	 * @param enabled
+	 * 					true if enabled, false otherwise
+	 */
+	public void setForceGPU(boolean enabled) {
+		this.forceGPU = enabled;
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/1cc21952/src/main/python/systemml/mlcontext.py
----------------------------------------------------------------------
diff --git a/src/main/python/systemml/mlcontext.py b/src/main/python/systemml/mlcontext.py
index 5619623..fc6d75c 100644
--- a/src/main/python/systemml/mlcontext.py
+++ b/src/main/python/systemml/mlcontext.py
@@ -362,6 +362,17 @@ class MLContext(object):
         self._ml.setGPU(bool(enable))
         return self
     
+    def setForceGPU(self, enable):
+        """
+        Whether or not to force the usage of GPU operators.
+
+        Parameters
+        ----------
+        enable: boolean
+        """
+        self._ml.setForceGPU(bool(enable))
+        return self
+        
     def setStatisticsMaxHeavyHitters(self, maxHeavyHitters):
         """
         The maximum number of heavy hitters that are printed as part of the statistics.
@@ -397,6 +408,18 @@ class MLContext(object):
         self._ml.setExplainLevel(explainLevel)
         return self
 
+    def setConfigProperty(self, propertyName, propertyValue):
+        """
+        Set configuration property, such as setConfigProperty("localtmpdir", "/tmp/systemml").
+
+        Parameters
+        ----------
+        propertyName: String
+        propertyValue: String
+        """
+        self._ml.setConfigProperty(propertyName, propertyValue)
+        return self
+    
     def version(self):
         """Display the project version."""
         return self._ml.version()

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/1cc21952/src/main/python/systemml/mllearn/estimators.py
----------------------------------------------------------------------
diff --git a/src/main/python/systemml/mllearn/estimators.py b/src/main/python/systemml/mllearn/estimators.py
index 195ed9d..deed4c2 100644
--- a/src/main/python/systemml/mllearn/estimators.py
+++ b/src/main/python/systemml/mllearn/estimators.py
@@ -67,19 +67,71 @@ class BaseSystemMLEstimator(Estimator):
         """
         self.label_col = colName
 
-    def setGPU(self, enableGPU):
-        self.estimator.setGPU(enableGPU)
+    def setGPU(self, enable):
+        """
+        Whether or not to enable GPU.
+
+        Parameters
+        ----------
+        enable: boolean
+        """
+        self.estimator.setGPU(enable)
         return self
     
+    def setForceGPU(self, enable):
+        """
+        Whether or not to force the usage of GPU operators.
+
+        Parameters
+        ----------
+        enable: boolean
+        """
+        self.estimator.setForceGPU(enable)
+        return self
+        
     def setExplain(self, explain):
+        """
+        Explanation about the program. Mainly intended for developers.
+
+        Parameters
+        ----------
+        explain: boolean
+        """
         self.estimator.setExplain(explain)
         return self
             
-    def setStatistics(self, stat):
-        self.estimator.setStatistics(stat)
+    def setStatistics(self, statistics):
+        """
+        Whether or not to output statistics (such as execution time, elapsed time)
+        about script executions.
+
+        Parameters
+        ----------
+        statistics: boolean
+        """
+        self.estimator.setStatistics(statistics)
         return self
     
+    def setStatisticsMaxHeavyHitters(self, maxHeavyHitters):
+        """
+        The maximum number of heavy hitters that are printed as part of the statistics.
+
+        Parameters
+        ----------
+        maxHeavyHitters: int
+        """
+        self.estimator.setStatisticsMaxHeavyHitters(maxHeavyHitters)
+        return self
+        
     def setConfigProperty(self, propertyName, propertyValue):
+        """
+        Set configuration property, such as setConfigProperty("localtmpdir", "/tmp/systemml").
+
+        Parameters
+        ----------
+        propertyName: String
+        propertyValue: String
+        """
         self.estimator.setConfigProperty(propertyName, propertyValue)
         return self
     

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/1cc21952/src/main/scala/org/apache/sysml/api/ml/BaseSystemMLClassifier.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/org/apache/sysml/api/ml/BaseSystemMLClassifier.scala b/src/main/scala/org/apache/sysml/api/ml/BaseSystemMLClassifier.scala
index a104c5c..2dbcc03 100644
--- a/src/main/scala/org/apache/sysml/api/ml/BaseSystemMLClassifier.scala
+++ b/src/main/scala/org/apache/sysml/api/ml/BaseSystemMLClassifier.scala
@@ -69,18 +69,24 @@ trait HasRegParam extends Params {
 
 trait BaseSystemMLEstimatorOrModel {
   var enableGPU:Boolean = false
+  var forceGPU:Boolean = false
   var explain:Boolean = false
   var statistics:Boolean = false
+  var statisticsMaxHeavyHitters:Int = 10
   val config:HashMap[String, String] = new HashMap[String, String]()
   def setGPU(enableGPU1:Boolean):BaseSystemMLEstimatorOrModel = { enableGPU = enableGPU1; this}
+  def setForceGPU(enableGPU1:Boolean):BaseSystemMLEstimatorOrModel = { forceGPU = enableGPU1; this}
   def setExplain(explain1:Boolean):BaseSystemMLEstimatorOrModel = { explain = explain1; this}
   def setStatistics(statistics1:Boolean):BaseSystemMLEstimatorOrModel = { statistics = statistics1; this}
+  def setStatisticsMaxHeavyHitters(statisticsMaxHeavyHitters1:Int):BaseSystemMLEstimatorOrModel = { statisticsMaxHeavyHitters = statisticsMaxHeavyHitters1; this}
   def setConfigProperty(key:String, value:String):BaseSystemMLEstimatorOrModel = { config.put(key, value); this}
   def updateML(ml:MLContext):Unit = {
     ml.setGPU(enableGPU); ml.setExplain(explain); ml.setStatistics(statistics); config.map(x => ml.setConfigProperty(x._1, x._2))
   }
   def copyProperties(other:BaseSystemMLEstimatorOrModel):BaseSystemMLEstimatorOrModel = {
-    other.setGPU(enableGPU); other.setExplain(explain); other.setStatistics(statistics); config.map(x => other.setConfigProperty(x._1, x._2))
+    other.setGPU(enableGPU); other.setForceGPU(forceGPU);
+    other.setExplain(explain); other.setStatistics(statistics); other.setStatisticsMaxHeavyHitters(statisticsMaxHeavyHitters);
+    config.map(x => other.setConfigProperty(x._1, x._2))
     return other
   }
 }