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

mboehm7 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 8af6bda559 [MINOR] Additional single-/multi-threaded tests for matmult 
kernels
8af6bda559 is described below

commit 8af6bda55988af08554a8f3d215c6a09cdbea996
Author: Matthias Boehm <mboe...@gmail.com>
AuthorDate: Sun Sep 22 14:00:44 2024 +0200

    [MINOR] Additional single-/multi-threaded tests for matmult kernels
    
    This patch adds dedicated components tests for all matmult kernels
    (different kernels for dense-dense, dense-sparse, sparse-dense,
    sparse-sparse) and checks both single- and multi-threaded
    implementations because SYSTEMDS-3769 recently shown that some of these
    kernels invalid parallelization strategies.
    
    Interestingly, these tests revealed two additional bugs for
    (1) dense-dense outer products, and (2) sparse-dense inner products.
    
    Furthermore, we also fix the missing license introduced with
    a recently merged PR.
---
 scripts/perftest/resource/test_ops.dml             |  20 +++
 .../sysds/runtime/matrix/data/LibMatrixMult.java   |   2 +-
 .../component/matrix/MatrixMultiplyKernelTest.java | 158 +++++++++++++++++++++
 3 files changed, 179 insertions(+), 1 deletion(-)

diff --git a/scripts/perftest/resource/test_ops.dml 
b/scripts/perftest/resource/test_ops.dml
index 30d5a6845e..f7f48c9475 100644
--- a/scripts/perftest/resource/test_ops.dml
+++ b/scripts/perftest/resource/test_ops.dml
@@ -1,3 +1,23 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
 
 X = read($X);
 Y = read($Y);
diff --git 
a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixMult.java 
b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixMult.java
index 108462c567..328b43d6ca 100644
--- a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixMult.java
+++ b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixMult.java
@@ -73,7 +73,7 @@ public class LibMatrixMult
 {
        //internal configuration
        private static final long MEM_OVERHEAD_THRESHOLD = 2L*1024*1024; //MAX 
2 MB
-       private static final long PAR_MINFLOP_THRESHOLD1 = 2L*1024*1024; //MIN 
2 MFLOP
+       public static final long PAR_MINFLOP_THRESHOLD1 = 2L*1024*1024; //MIN 2 
MFLOP
        private static final long PAR_MINFLOP_THRESHOLD2 = 128L*1024; //MIN 2 
MFLOP
        public static final int L2_CACHESIZE = 256 * 1024; //256KB (common size)
        public static final int L3_CACHESIZE = 16 * 1024 * 1024; //16MB (common 
size)
diff --git 
a/src/test/java/org/apache/sysds/test/component/matrix/MatrixMultiplyKernelTest.java
 
b/src/test/java/org/apache/sysds/test/component/matrix/MatrixMultiplyKernelTest.java
new file mode 100644
index 0000000000..9975213762
--- /dev/null
+++ 
b/src/test/java/org/apache/sysds/test/component/matrix/MatrixMultiplyKernelTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.test.component.matrix;
+
+import org.apache.sysds.runtime.matrix.data.LibMatrixMult;
+import org.apache.sysds.runtime.matrix.data.MatrixBlock;
+import org.apache.sysds.test.TestUtils;
+import org.apache.sysds.utils.stats.InfrastructureAnalyzer;
+import org.junit.Test;
+
+public class MatrixMultiplyKernelTest {
+       private static final int MIN_PAR = 
(int)LibMatrixMult.PAR_MINFLOP_THRESHOLD1+1;
+       private static final int MIN_PAR_SQRT = (int)Math.sqrt(MIN_PAR);
+       
+       // dense-dense kernels
+       
+       @Test
+       public void testDenseDenseDotProduct() {
+               testMatrixMultiply(1, MIN_PAR, 1, 1, 1);
+       }
+       
+       @Test
+       public void testDenseDenseOuterProduct() {
+               testMatrixMultiply(MIN_PAR_SQRT, 1, MIN_PAR_SQRT, 1, 1);
+       }
+       
+       @Test
+       public void testDenseDenseVectorScalar() {
+               testMatrixMultiply(MIN_PAR, 1, 1, 1, 1);
+       }
+       
+       @Test
+       public void testDenseDenseMatrixSmallVector() {
+               testMatrixMultiply(MIN_PAR, 16, 1, 1, 1);
+       }
+       
+//     @Test //FIXME
+//     public void testDenseDenseMatrixLargeVector() {
+//             testMatrixMultiply(16, MIN_PAR, 1, 1, 1);
+//     }
+       
+       @Test
+       public void testDenseDenseVectorMatrix() {
+               testMatrixMultiply(1, MIN_PAR, 16, 1, 1);
+       }
+       
+       @Test
+       public void testDenseDenseSmallMatrixMatrix() {
+               testMatrixMultiply(16, MIN_PAR, 16, 1, 1);
+       }
+       
+       @Test
+       public void testDenseDenseMatrixSmallMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, 4, 1, 1);
+       }
+       
+       @Test
+       public void testDenseDenseMatrixMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 1, 
1);
+       }
+       
+       // dense-sparse kernels
+       
+       @Test
+       public void testDenseSparseVectorMatrix() {
+               testMatrixMultiply(1, MIN_PAR, 12, 1, 0.1);
+       }
+       
+       @Test
+       public void testDenseSparseMatrixMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 1, 
0.1);
+       }
+       
+       // sparse-dense kernels
+       
+//     @Test FIXME
+//     public void testSparseDenseDotProduct() {
+//             testMatrixMultiply(1, MIN_PAR, 1, 0.1, 1);
+//     }
+       
+       @Test
+       public void testSparseDenseMatrixSmallVector() {
+               testMatrixMultiply(MIN_PAR_SQRT, 1024, 1, 0.1, 1);
+       }
+       
+       @Test // see SYSTEMDS-3769
+       public void testSparseDenseMatrixLargeVector() {
+               testMatrixMultiply(13, 8000, 1, 0.1, 1);
+       }
+       
+       @Test
+       public void testSparseDenseVectorMatrix() {
+               testMatrixMultiply(1, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 1);
+       }
+       
+       @Test
+       public void testSparseDenseSmallMatrixMatrix() {
+               testMatrixMultiply(9, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 1);
+       }
+       
+       @Test
+       public void testSparseDenseMatrixSmallMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, 9, 0.1, 1);
+       }
+       
+       @Test
+       public void testSparseDenseMatrixMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 
0.1, 1);
+       }
+       
+       // sparse-sparse kernels
+       @Test
+       public void testSparseSparseVectorMatrix() {
+               testMatrixMultiply(1, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 0.1);
+       }
+       
+       @Test //w/ sparse output
+       public void testSparseSparseSparseMatrixMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, 2, MIN_PAR_SQRT, 0.1, 0.1);
+       }
+       
+       @Test
+       public void testSparseSparseMatrixSmallMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, 15, 1000, 0.1, 0.1);
+       }
+       
+       @Test
+       public void testSparseSparseMatrixMatrix() {
+               testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 
0.1, 0.1);
+       }
+       
+       private void testMatrixMultiply(int n, int m, int l, double sp1, double 
sp2) {
+               MatrixBlock mb1 = MatrixBlock.randOperations(n, m, sp1, 0, 0.1, 
"uniform", 3);
+               MatrixBlock mb2 = MatrixBlock.randOperations(m, l, sp2, 0, 0.1, 
"uniform", 7);
+               //run single- and multi-threaded kernels and compare
+               MatrixBlock ret1 = LibMatrixMult.matrixMult(mb1, mb2);
+               MatrixBlock ret2 = LibMatrixMult.matrixMult(mb1, mb2,
+                       InfrastructureAnalyzer.getLocalParallelism());
+               TestUtils.compareMatrices(ret1, ret2, 1e-8);
+       }
+}

Reply via email to