Repository: systemml Updated Branches: refs/heads/master b06f390ec -> 51db735eb
[MINOR] Refactoring maxpool/avgpool operation for external calls Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/2982c73f Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/2982c73f Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/2982c73f Branch: refs/heads/master Commit: 2982c73fd94eda3b9669a2fb843d1395602af8bf Parents: b06f390 Author: Matthias Boehm <[email protected]> Authored: Mon Jun 18 14:15:08 2018 -0700 Committer: Matthias Boehm <[email protected]> Committed: Mon Jun 18 14:15:08 2018 -0700 ---------------------------------------------------------------------- .../matrix/data/LibMatrixDNNPooling.java | 60 ++++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/2982c73f/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNNPooling.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNNPooling.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNNPooling.java index 4d92377..4ff8e5e 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNNPooling.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDNNPooling.java @@ -97,6 +97,36 @@ public class LibMatrixDNNPooling { return ret; } + public static void poolingDenseStride1Pad0(PoolingType pType, double minVal, double pFact, + double[] in, double[] out, int rl, int ru, int C, int P, int Q, int R, int S, int H, int W) { + boolean max = (pType == PoolingType.MAX); + int CHW = C * H * W; + + if( P == 1 && Q == 1 && W == 1 ) { + //quick-path w/o materialized index arrays and + //simplified inner loops for P = 1, Q = 1, W = 1 + int lenh = Math.min(R,H); + for(int i = rl, oix=rl*C; i < ru; i++, oix+=C) + for (int c = 0, off=i*CHW; c < C; c++, off+=H) { + out[oix+c] = max ? max(minVal, in, off, lenh) : + avg(minVal, in, off, lenh, pFact); + } + } + else { + int CPQ = C * P * Q, HW = H * W; + Arrays.fill(out, rl*CPQ, ru*CPQ, minVal); + //quick-path w/o materialized index arrays + for(int i = rl; i < ru; i++) + for (int c = 0, off=i*CHW, oix=i*CPQ; c < C; c++, off+=HW) + for (int p = 0; p < P; p++, oix+=Q) + for (int h = p; h < Math.min(p+R,H); h++) + for (int q = 0, off2=off+h*W; q < Q; q++) { + out[oix+q] = max ? max(out[oix+q], in, off2+q, Math.min(S,W-q)) : + avg(out[oix+q], in, off2+q, Math.min(S,W-q), pFact); + } + } + } + private static class DensePooling implements Callable<Long> { private final int _rl, _ru; @@ -125,32 +155,14 @@ public class LibMatrixDNNPooling { double minValForMaxPoolOperations = _poolingType == PoolingType.AVG ? 0 : _params.minValForMaxPoolOperations; boolean max = (_poolingType == PoolingType.MAX); - //thread-local initialization of output block - if( !(_params.isStride1Pad0() && _params.isAllOnes(P, Q, W)) ) - Arrays.fill(out, _rl*CPQ, _ru*CPQ, minValForMaxPoolOperations); - - if( _params.isStride1Pad0() && _params.isAllOnes(P, Q, W) ) { - //quick-path w/o materialized index arrays and - //simplified inner loops for P = 1, Q = 1, W = 1 - int lenh = Math.min(R,H); - for(int i = _rl, oix=_rl*C; i < _ru; i++, oix+=C) - for (int c = 0, off=i*CHW; c < C; c++, off+=H) { - out[oix+c] = max ? max(minValForMaxPoolOperations, in, off, lenh) : - avg(minValForMaxPoolOperations, in, off, lenh, _poolingMultiplier); - } - } - else if( _params.isStride1Pad0() ) { - //quick-path w/o materialized index arrays - for(int i = _rl; i < _ru; i++) - for (int c = 0, off=i*CHW, oix=i*CPQ; c < C; c++, off+=HW) - for (int p = 0; p < P; p++, oix+=Q) - for (int h = p; h < Math.min(p+R,H); h++) - for (int q = 0, off2=off+h*W; q < Q; q++) { - out[oix+q] = max ? max(out[oix+q], in, off2+q, Math.min(S,W-q)) : - avg(out[oix+q], in, off2+q, Math.min(S,W-q), _poolingMultiplier); - } + if( _params.isStride1Pad0() ) { + poolingDenseStride1Pad0(_poolingType, minValForMaxPoolOperations, + _poolingMultiplier, in, out, _rl, _ru, C, P, Q, R, S, H, W); } else { //general case + //thread-local initialization of output block + Arrays.fill(out, _rl*CPQ, _ru*CPQ, minValForMaxPoolOperations); + int[] hl = _params.start_indexes_h, hu = _params.end_indexes_h; int[] wl = _params.start_indexes_w, wu = _params.end_indexes_w; for(int i = _rl; i < _ru; i++)
