This is an automated email from the ASF dual-hosted git repository.
mboehm7 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/systemml.git
The following commit(s) were added to refs/heads/master by this push:
new 39c5654 [MINOR] Extended JMLC API (handling of pinned variables)
39c5654 is described below
commit 39c56541ca83ea36093384220d19a31b5578537e
Author: Anthony Thomas <[email protected]>
AuthorDate: Thu Apr 9 19:29:55 2020 +0200
[MINOR] Extended JMLC API (handling of pinned variables)
Closes #835.
---
.../java/org/apache/sysds/api/jmlc/PreparedScript.java | 17 +++++++++++++----
.../sysds/runtime/controlprogram/LocalVariableMap.java | 4 ++++
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sysds/api/jmlc/PreparedScript.java
b/src/main/java/org/apache/sysds/api/jmlc/PreparedScript.java
index 04101f2..3175fcb 100644
--- a/src/main/java/org/apache/sysds/api/jmlc/PreparedScript.java
+++ b/src/main/java/org/apache/sysds/api/jmlc/PreparedScript.java
@@ -72,7 +72,7 @@ public class PreparedScript implements ConfigurableAPI
//input/output specification
private final HashSet<String> _inVarnames;
private final HashSet<String> _outVarnames;
- private final HashMap<String,Data> _inVarReuse;
+ private final LocalVariableMap _inVarReuse;
//internal state (reused)
private final Program _prog;
@@ -91,7 +91,7 @@ public class PreparedScript implements ConfigurableAPI
_vars.setRegisteredOutputs(that._outVarnames);
_inVarnames = that._inVarnames;
_outVarnames = that._outVarnames;
- _inVarReuse = new HashMap<>(that._inVarReuse);
+ _inVarReuse = new LocalVariableMap(that._inVarReuse);
_dmlconf = that._dmlconf;
_cconf = that._cconf;
}
@@ -115,7 +115,7 @@ public class PreparedScript implements ConfigurableAPI
Collections.addAll(_inVarnames, inputs);
_outVarnames = new HashSet<>();
Collections.addAll(_outVarnames, outputs);
- _inVarReuse = new HashMap<>();
+ _inVarReuse = new LocalVariableMap();
//attach registered outputs (for dynamic recompile)
_vars.setRegisteredOutputs(_outVarnames);
@@ -415,7 +415,16 @@ public class PreparedScript implements ConfigurableAPI
public void clearParameters() {
_vars.removeAll();
}
-
+
+ /**
+ * Remove all references to pinned variables from this script.
+ * Note: this *does not* remove the underlying data. It merely
+ * removes a reference to it from this prepared script. This is
+ * useful if you want to maintain an independent cache of weights
+ * and allow the JVM to garbage collect under memory pressure.
+ */
+ public void clearPinnedData() { _inVarReuse.removeAll(); }
+
/**
* Executes the prepared script over the bound inputs, creating the
* result variables according to bound and registered outputs.
diff --git
a/src/main/java/org/apache/sysds/runtime/controlprogram/LocalVariableMap.java
b/src/main/java/org/apache/sysds/runtime/controlprogram/LocalVariableMap.java
index 92eabbd..1ac47b7 100644
---
a/src/main/java/org/apache/sysds/runtime/controlprogram/LocalVariableMap.java
+++
b/src/main/java/org/apache/sysds/runtime/controlprogram/LocalVariableMap.java
@@ -94,6 +94,10 @@ public class LocalVariableMap implements Cloneable
localMap.putAll(vals);
}
+ public void putAll(LocalVariableMap vars) {
+ putAll(vars.localMap);
+ }
+
public Data remove( String name ) {
return localMap.remove( name );
}