Repository: systemml
Updated Branches:
  refs/heads/master 0177a1310 -> 8e1146e89


[MINOR] Improved memory profiling JMLC pipelines, avoid allocations

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

Branch: refs/heads/master
Commit: 8e1146e8945dc1a3af1ecb888a2b5682e0e60040
Parents: 0177a13
Author: Matthias Boehm <[email protected]>
Authored: Sat Jun 9 18:41:45 2018 -0700
Committer: Matthias Boehm <[email protected]>
Committed: Sat Jun 9 18:41:45 2018 -0700

----------------------------------------------------------------------
 .../controlprogram/LocalVariableMap.java        | 23 ++++++++++++++++----
 .../controlprogram/caching/CacheableData.java   | 23 ++++++++++----------
 2 files changed, 31 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/8e1146e8/src/main/java/org/apache/sysml/runtime/controlprogram/LocalVariableMap.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/controlprogram/LocalVariableMap.java 
b/src/main/java/org/apache/sysml/runtime/controlprogram/LocalVariableMap.java
index 672e9f7..a926816 100644
--- 
a/src/main/java/org/apache/sysml/runtime/controlprogram/LocalVariableMap.java
+++ 
b/src/main/java/org/apache/sysml/runtime/controlprogram/LocalVariableMap.java
@@ -123,11 +123,26 @@ public class LocalVariableMap implements Cloneable
        }
 
        public double getPinnedDataSize() {
-               //note: this method returns the total size of pinned data 
objects
-               //that are not subject to automatic eviction.
+               //note: this method returns the total size of distinct pinned
+               //data objects that are not subject to automatic eviction 
+               //(in JMLC all matrices and frames are pinned)
+               
+               //compute map of distinct cachable data
+               Map<Integer, Data> dict = new HashMap<>();
+               for( Entry<String,Data> e : localMap.entrySet() ) {
+                       int hash = System.identityHashCode(e.getValue());
+                       if( !dict.containsKey(hash) && e.getValue() instanceof 
CacheableData )
+                               dict.put(hash, e.getValue());
+               }
+               
+               //compute total in-memory size
+               return dict.values().stream().mapToDouble(
+                       d -> ((CacheableData<?>)d).getDataSize()).sum();
+       }
+       
+       public long countPinnedData() {
                return localMap.values().stream()
-                       .filter(d -> (d instanceof CacheableData))
-                       .mapToDouble(d -> 
((CacheableData<?>)d).getDataSize()).sum();
+                       .filter(d -> (d instanceof CacheableData)).count();
        }
        
        public String serialize() {

http://git-wip-us.apache.org/repos/asf/systemml/blob/8e1146e8/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheableData.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheableData.java
 
b/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheableData.java
index a9a22e0..27e84d5 100644
--- 
a/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheableData.java
+++ 
b/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheableData.java
@@ -207,7 +207,7 @@ public abstract class CacheableData<T extends CacheBlock> 
extends Data
                _uniqueID = isCachingActive() ? _seq.getNextID() : -1;
                _cacheStatus = CacheStatus.EMPTY;
                _numReadThreads = 0;
-               _gpuObjects = new HashMap<>();
+               _gpuObjects = DMLScript.USE_ACCELERATOR ? new HashMap<>() : 
null;
        }
        
        /**
@@ -671,16 +671,17 @@ public abstract class CacheableData<T extends CacheBlock> 
extends Data
 
                LOG.trace("Exporting " + this.getDebugName() + " to " + fName + 
" in format " + outputFormat);
                
-               //TODO remove
-               boolean copiedFromGPU = false;
-               for (Map.Entry<GPUContext, GPUObject> kv : 
_gpuObjects.entrySet()) {
-                       GPUObject gObj = kv.getValue();
-                       if (gObj != null && copiedFromGPU && gObj.isDirty()) {
-                               throw new DMLRuntimeException("Internal Error : 
Inconsistent internal state, A copy of this CacheableData was dirty on more 
than 1 GPU");
-                       } else if (gObj != null){
-                               copiedFromGPU = gObj.acquireHostRead(null);
-                               if( _data == null )
-                                       getCache();
+               if( DMLScript.USE_ACCELERATOR ) {
+                       boolean copiedFromGPU = false;
+                       for (Map.Entry<GPUContext, GPUObject> kv : 
_gpuObjects.entrySet()) {
+                               GPUObject gObj = kv.getValue();
+                               if (gObj != null && copiedFromGPU && 
gObj.isDirty()) {
+                                       throw new DMLRuntimeException("Internal 
Error : Inconsistent internal state, A copy of this CacheableData was dirty on 
more than 1 GPU");
+                               } else if (gObj != null){
+                                       copiedFromGPU = 
gObj.acquireHostRead(null);
+                                       if( _data == null )
+                                               getCache();
+                               }
                        }
                }
                

Reply via email to