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 2019/03/05 23:49:43 UTC
[systemml] branch master updated: [SYSTEMML-540] Reduce the memory
pressure of CP lstm_backward instruction
This is an automated email from the ASF dual-hosted git repository.
niketanpansare 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 c7b9745 [SYSTEMML-540] Reduce the memory pressure of CP lstm_backward instruction
c7b9745 is described below
commit c7b9745800e0c71f0c6c76b8284c78e33a5cdb01
Author: Niketan Pansare <np...@us.ibm.com>
AuthorDate: Tue Mar 5 15:48:09 2019 -0800
[SYSTEMML-540] Reduce the memory pressure of CP lstm_backward instruction
- When lstm_backward in invoked, this commit avoids memory allocation and left indexing of output and carry activations of the corresponding forward invocation.
---
.../runtime/instructions/cp/DnnCPInstruction.java | 6 +++---
.../sysml/runtime/matrix/data/LibMatrixDNN.java | 20 +++++++++-----------
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/DnnCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/DnnCPInstruction.java
index 50a11de..35ac5b6 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/cp/DnnCPInstruction.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/DnnCPInstruction.java
@@ -388,8 +388,6 @@ public class DnnCPInstruction extends UnaryCPInstruction {
+ "but found [" + dc.getNumRows() + "," + dc.getNumColumns() + "]");
}
- MatrixBlock out = new MatrixBlock(N, return_seq ? (T*M) : M, false);
- MatrixBlock c = new MatrixBlock(N, M, false);
MatrixBlock cache_out = new MatrixBlock(T, N*M, false);
MatrixBlock cache_c = new MatrixBlock(T, N*M, false);
MatrixBlock cache_ifog = new MatrixBlock(T, N*4*M, false);
@@ -401,7 +399,9 @@ public class DnnCPInstruction extends UnaryCPInstruction {
cache_ifog.allocateDenseBlock();
LibMatrixDNN.lstm(X, W, b, out0, c0,
return_seq, N, T, D, M,
- out, c, cache_out, cache_c, cache_ifog,
+ // Avoid out and c computation in lstm forward call
+ null, null,
+ cache_out, cache_c, cache_ifog,
_numThreads);
MatrixBlock dX = new MatrixBlock(N, T*D, false);
diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNN.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNN.java
index 0005932..3ec9fb3 100644
--- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNN.java
+++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNN.java
@@ -20,7 +20,6 @@ package org.apache.sysml.runtime.matrix.data;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
@@ -41,7 +40,6 @@ import org.apache.sysml.runtime.functionobjects.Multiply;
import org.apache.sysml.runtime.functionobjects.Plus;
import org.apache.sysml.runtime.functionobjects.PlusMultiply;
import org.apache.sysml.runtime.functionobjects.Power;
-import org.apache.sysml.runtime.functionobjects.Power2;
import org.apache.sysml.runtime.functionobjects.SwapIndex;
import org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode;
import org.apache.sysml.runtime.instructions.cp.KahanObject;
@@ -57,8 +55,6 @@ import org.apache.sysml.runtime.matrix.operators.UnaryOperator;
import org.apache.sysml.runtime.util.CommonThreadPool;
import org.apache.sysml.runtime.util.DnnUtils;
-import com.sun.org.apache.xpath.internal.operations.Minus;
-
/*
* This class allows users to invoke deep learning related operations
* (such as conv2d, conv2d_backward_data, conv2d_backward_filter, maxpooling, maxpooling_backward, bias_add)
@@ -514,7 +510,7 @@ public class LibMatrixDNN {
public static void lstm(MatrixBlock X, MatrixBlock W, MatrixBlock b, MatrixBlock out0, MatrixBlock c0,
boolean return_seq, int N, int T, int D, int M,
- MatrixBlock out, MatrixBlock c, // output
+ MatrixBlock out, MatrixBlock c, // output: if null, the output and c are not passed back
MatrixBlock cache_out, MatrixBlock cache_c, MatrixBlock cache_ifog, // if null, the cache values are not computed
int numThreads) {
MatrixBlock out_prev = out0;
@@ -624,7 +620,7 @@ public class LibMatrixDNN {
updateIfogCache(cache_ifog, ifo, g, t, N, M);
}
- if(return_seq) {
+ if(return_seq && out != null) {
out = out.leftIndexingOperations(out_t, 0, N-1, (t-1)*M, t*M-1, out, UpdateType.INPLACE);
}
out_prev = out_t;
@@ -635,12 +631,14 @@ public class LibMatrixDNN {
reshapeAsRowMatrixAndLeftIndex(cache_c, c_t, t-1, N*M);
}
}
- if(out_t != null && !return_seq)
+ if(out_t != null && !return_seq && out != null)
out.copy(out_t);
- if(c_t != null)
- c.copy(c_t);
- else
- c.copy(c0);
+ if(c != null) {
+ if(c_t != null)
+ c.copy(c_t);
+ else
+ c.copy(c0);
+ }
if(cache_out != null) {
cache_out.recomputeNonZeros();
cache_c.recomputeNonZeros();