This is an automated email from the ASF dual-hosted git repository.

baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new 57cb875d45 [MINOR] Change parallelization thresholds on Aggregate
57cb875d45 is described below

commit 57cb875d45b3d81b6cb4703ed29ce3e0585ad06f
Author: Sebastian Baunsgaard <baunsga...@apache.org>
AuthorDate: Wed Aug 28 13:28:51 2024 +0200

    [MINOR] Change parallelization thresholds on Aggregate
    
    This commit change the thresholds for performing
    parallel aggregation. Since the change of the parallelization
    to use more shared thread pools parallel execution have to happen
    much earlier around 1k non zero elements.
    
    rows:   100 cols:   100 sp: 1.000 par: 16 sum,    0.153+-  0.066 ms,
    rows:   100 cols:   100 sp: 1.000 par:  1 sum,    0.052+-  0.002 ms,
    rows:   141 cols:   141 sp: 1.000 par: 16 sum,    0.153+-  0.019 ms,
    rows:   141 cols:   141 sp: 1.000 par:  1 sum,    0.100+-  0.001 ms,
    rows:   199 cols:   199 sp: 1.000 par: 16 sum,    0.191+-  0.014 ms,
    rows:   199 cols:   199 sp: 1.000 par:  1 sum,    0.200+-  0.002 ms,
    rows:   281 cols:   281 sp: 1.000 par: 16 sum,    0.276+-  0.021 ms,
    rows:   281 cols:   281 sp: 1.000 par:  1 sum,    0.398+-  0.003 ms,
    rows:   398 cols:   398 sp: 1.000 par: 16 sum,    0.428+-  0.026 ms,
    rows:   398 cols:   398 sp: 1.000 par:  1 sum,    0.797+-  0.004 ms,
    rows:   562 cols:   562 sp: 1.000 par: 16 sum,    0.506+-  0.085 ms,
    rows:   562 cols:   562 sp: 1.000 par:  1 sum,    1.588+-  0.004 ms,
    rows:   794 cols:   794 sp: 1.000 par: 16 sum,    0.961+-  0.318 ms,
    rows:   794 cols:   794 sp: 1.000 par:  1 sum,    3.170+-  0.008 ms,
---
 .../sysds/runtime/matrix/data/LibMatrixAgg.java    |  8 +--
 .../sysds/performance/matrix/MatrixAggregate.java  | 71 ++++++++++++++++++++++
 .../performance/matrix/MatrixBinaryCellPerf.java   | 18 +++---
 3 files changed, 84 insertions(+), 13 deletions(-)

diff --git 
a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixAgg.java 
b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixAgg.java
index 277e0d0e1a..41dca9d4c7 100644
--- a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixAgg.java
+++ b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixAgg.java
@@ -98,8 +98,8 @@ public class LibMatrixAgg {
 
        //internal configuration parameters
        private static final boolean NAN_AWARENESS = false;
-       private static final long PAR_NUMCELL_THRESHOLD1 = 1024*1024; //Min 1M 
elements
-       private static final long PAR_NUMCELL_THRESHOLD2 = 1024;   //Min 16K 
elements
+       private static final long PAR_NUMCELL_THRESHOLD1 = 1024*256; //Min 256K 
elements
+       private static final long PAR_NUMCELL_THRESHOLD2 = 1024*4;   //Min 4K 
elements
        private static final long PAR_INTERMEDIATE_SIZE_THRESHOLD = 
2*1024*1024; //Max 2MB
        
        ////////////////////////////////
@@ -682,13 +682,13 @@ public class LibMatrixAgg {
                boolean sharedTP = 
(InfrastructureAnalyzer.getLocalParallelism() == k);
                return k > 1 && out.isThreadSafe() && in.rlen > (sharedTP ? k/8 
: k/2)
                        && (uaop.indexFn instanceof ReduceCol || out.clen*8*k < 
PAR_INTERMEDIATE_SIZE_THRESHOLD) //size
-                       && in.nonZeros > (sharedTP ? k*PAR_NUMCELL_THRESHOLD2 : 
PAR_NUMCELL_THRESHOLD1);
+                       && in.nonZeros > (sharedTP ? PAR_NUMCELL_THRESHOLD2 : 
PAR_NUMCELL_THRESHOLD1);
        }
        
        public static boolean satisfiesMultiThreadingConstraints(MatrixBlock 
in, int k) {
                boolean sharedTP = 
(InfrastructureAnalyzer.getLocalParallelism() == k);
                return k > 1 && in.rlen > (sharedTP ? k/8 : k/2)
-                       && in.nonZeros > (sharedTP ? k*PAR_NUMCELL_THRESHOLD2 : 
PAR_NUMCELL_THRESHOLD1);
+                       && in.nonZeros > (sharedTP ? PAR_NUMCELL_THRESHOLD2 : 
PAR_NUMCELL_THRESHOLD1);
        }
        
        /**
diff --git 
a/src/test/java/org/apache/sysds/performance/matrix/MatrixAggregate.java 
b/src/test/java/org/apache/sysds/performance/matrix/MatrixAggregate.java
new file mode 100644
index 0000000000..f6a466efaa
--- /dev/null
+++ b/src/test/java/org/apache/sysds/performance/matrix/MatrixAggregate.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.performance.matrix;
+
+import org.apache.sysds.performance.compression.APerfTest;
+import org.apache.sysds.performance.generators.ConstMatrix;
+import org.apache.sysds.performance.generators.GenPair;
+import org.apache.sysds.performance.generators.IGenerate;
+import org.apache.sysds.runtime.matrix.data.MatrixBlock;
+import org.apache.sysds.test.TestUtils;
+import org.apache.sysds.utils.stats.InfrastructureAnalyzer;
+
+public class MatrixAggregate extends APerfTest<Object, MatrixBlock> {
+
+       private final int k;
+
+       public MatrixAggregate(int N, IGenerate<MatrixBlock> gen, int k) {
+               super(N, gen);
+               this.k = k;
+       }
+
+       public void run() throws Exception {
+               MatrixBlock mb = gen.take();
+
+               String info = String.format("rows: %5d cols: %5d sp: %5.3f par: 
%2d", mb.getNumRows(), mb.getNumColumns(),
+                       mb.getSparsity(), k);
+               warmup(() -> sum(), 100);
+               execute(() -> sum(), info + " sum");
+       }
+
+       private void sum() {
+               MatrixBlock in = gen.take();
+               in.sum(k);
+               ret.add(null);
+       }
+
+       @Override
+       protected String makeResString() {
+               return "";
+       }
+
+       public static void main(String[] args) throws Exception {
+               // Matrix Blocks:
+
+               int k = InfrastructureAnalyzer.getLocalParallelism();
+               for(double i = 2.0d; i < 3.0; i += 0.15) {
+                       MatrixBlock a = TestUtils
+                               
.ceil(TestUtils.generateTestMatrixBlock((int)Math.pow(10, i), 
Math.min((int)Math.pow(10, i), 1000), 0, 100, 1.0, 42));
+                       new MatrixAggregate(3000, new ConstMatrix(a, -1), 
k).run();
+                       new MatrixAggregate(3000, new ConstMatrix(a, -1), 
1).run();
+               }
+
+       }
+}
diff --git 
a/src/test/java/org/apache/sysds/performance/matrix/MatrixBinaryCellPerf.java 
b/src/test/java/org/apache/sysds/performance/matrix/MatrixBinaryCellPerf.java
index 6e187dff9d..7649b66cff 100644
--- 
a/src/test/java/org/apache/sysds/performance/matrix/MatrixBinaryCellPerf.java
+++ 
b/src/test/java/org/apache/sysds/performance/matrix/MatrixBinaryCellPerf.java
@@ -78,16 +78,16 @@ public class MatrixBinaryCellPerf extends APerfTest<Object, 
Pair<MatrixBlock, Ma
                System.out.println("Sparse Sparse 0.1");
                new MatrixBinaryCellPerf(N, gen, k).run();
 
-               // gen = new GenPair<>(new ConstMatrix(a_d, -1), new 
ConstMatrix(b_s, -1));
-               // System.out.println("Dense Sparse 0.1");
-               // new MatrixBinaryCellPerf(N, gen, k).run();
+               gen = new GenPair<>(new ConstMatrix(a_d, -1), new 
ConstMatrix(b_s, -1));
+               System.out.println("Dense Sparse 0.1");
+               new MatrixBinaryCellPerf(N, gen, k).run();
 
-               // gen = new GenPair<>(new ConstMatrix(a_s, -1), new 
ConstMatrix(b_d, -1));
-               // System.out.println("Sparse Dense 0.1");
-               // new MatrixBinaryCellPerf(N, gen, k).run();
+               gen = new GenPair<>(new ConstMatrix(a_s, -1), new 
ConstMatrix(b_d, -1));
+               System.out.println("Sparse Dense 0.1");
+               new MatrixBinaryCellPerf(N, gen, k).run();
 
-               // gen = new GenPair<>(new ConstMatrix(a_d, -1), new 
ConstMatrix(b_d, -1));
-               // System.out.println("Dense Dense");
-               // new MatrixBinaryCellPerf(N, gen, k).run();
+               gen = new GenPair<>(new ConstMatrix(a_d, -1), new 
ConstMatrix(b_d, -1));
+               System.out.println("Dense Dense");
+               new MatrixBinaryCellPerf(N, gen, k).run();
        }
 }

Reply via email to