Skip to content

Commit 8af6bda

Browse files
committed
[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.
1 parent d0287b1 commit 8af6bda

File tree

3 files changed

+179
-1
lines changed

3 files changed

+179
-1
lines changed

scripts/perftest/resource/test_ops.dml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
#-------------------------------------------------------------
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
#-------------------------------------------------------------
121

222
X = read($X);
323
Y = read($Y);

src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixMult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class LibMatrixMult
7373
{
7474
//internal configuration
7575
private static final long MEM_OVERHEAD_THRESHOLD = 2L*1024*1024; //MAX 2 MB
76-
private static final long PAR_MINFLOP_THRESHOLD1 = 2L*1024*1024; //MIN 2 MFLOP
76+
public static final long PAR_MINFLOP_THRESHOLD1 = 2L*1024*1024; //MIN 2 MFLOP
7777
private static final long PAR_MINFLOP_THRESHOLD2 = 128L*1024; //MIN 2 MFLOP
7878
public static final int L2_CACHESIZE = 256 * 1024; //256KB (common size)
7979
public static final int L3_CACHESIZE = 16 * 1024 * 1024; //16MB (common size)
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.sysds.test.component.matrix;
21+
22+
import org.apache.sysds.runtime.matrix.data.LibMatrixMult;
23+
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
24+
import org.apache.sysds.test.TestUtils;
25+
import org.apache.sysds.utils.stats.InfrastructureAnalyzer;
26+
import org.junit.Test;
27+
28+
public class MatrixMultiplyKernelTest {
29+
private static final int MIN_PAR = (int)LibMatrixMult.PAR_MINFLOP_THRESHOLD1+1;
30+
private static final int MIN_PAR_SQRT = (int)Math.sqrt(MIN_PAR);
31+
32+
// dense-dense kernels
33+
34+
@Test
35+
public void testDenseDenseDotProduct() {
36+
testMatrixMultiply(1, MIN_PAR, 1, 1, 1);
37+
}
38+
39+
@Test
40+
public void testDenseDenseOuterProduct() {
41+
testMatrixMultiply(MIN_PAR_SQRT, 1, MIN_PAR_SQRT, 1, 1);
42+
}
43+
44+
@Test
45+
public void testDenseDenseVectorScalar() {
46+
testMatrixMultiply(MIN_PAR, 1, 1, 1, 1);
47+
}
48+
49+
@Test
50+
public void testDenseDenseMatrixSmallVector() {
51+
testMatrixMultiply(MIN_PAR, 16, 1, 1, 1);
52+
}
53+
54+
// @Test //FIXME
55+
// public void testDenseDenseMatrixLargeVector() {
56+
// testMatrixMultiply(16, MIN_PAR, 1, 1, 1);
57+
// }
58+
59+
@Test
60+
public void testDenseDenseVectorMatrix() {
61+
testMatrixMultiply(1, MIN_PAR, 16, 1, 1);
62+
}
63+
64+
@Test
65+
public void testDenseDenseSmallMatrixMatrix() {
66+
testMatrixMultiply(16, MIN_PAR, 16, 1, 1);
67+
}
68+
69+
@Test
70+
public void testDenseDenseMatrixSmallMatrix() {
71+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, 4, 1, 1);
72+
}
73+
74+
@Test
75+
public void testDenseDenseMatrixMatrix() {
76+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 1, 1);
77+
}
78+
79+
// dense-sparse kernels
80+
81+
@Test
82+
public void testDenseSparseVectorMatrix() {
83+
testMatrixMultiply(1, MIN_PAR, 12, 1, 0.1);
84+
}
85+
86+
@Test
87+
public void testDenseSparseMatrixMatrix() {
88+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 1, 0.1);
89+
}
90+
91+
// sparse-dense kernels
92+
93+
// @Test FIXME
94+
// public void testSparseDenseDotProduct() {
95+
// testMatrixMultiply(1, MIN_PAR, 1, 0.1, 1);
96+
// }
97+
98+
@Test
99+
public void testSparseDenseMatrixSmallVector() {
100+
testMatrixMultiply(MIN_PAR_SQRT, 1024, 1, 0.1, 1);
101+
}
102+
103+
@Test // see SYSTEMDS-3769
104+
public void testSparseDenseMatrixLargeVector() {
105+
testMatrixMultiply(13, 8000, 1, 0.1, 1);
106+
}
107+
108+
@Test
109+
public void testSparseDenseVectorMatrix() {
110+
testMatrixMultiply(1, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 1);
111+
}
112+
113+
@Test
114+
public void testSparseDenseSmallMatrixMatrix() {
115+
testMatrixMultiply(9, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 1);
116+
}
117+
118+
@Test
119+
public void testSparseDenseMatrixSmallMatrix() {
120+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, 9, 0.1, 1);
121+
}
122+
123+
@Test
124+
public void testSparseDenseMatrixMatrix() {
125+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 1);
126+
}
127+
128+
// sparse-sparse kernels
129+
@Test
130+
public void testSparseSparseVectorMatrix() {
131+
testMatrixMultiply(1, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 0.1);
132+
}
133+
134+
@Test //w/ sparse output
135+
public void testSparseSparseSparseMatrixMatrix() {
136+
testMatrixMultiply(MIN_PAR_SQRT, 2, MIN_PAR_SQRT, 0.1, 0.1);
137+
}
138+
139+
@Test
140+
public void testSparseSparseMatrixSmallMatrix() {
141+
testMatrixMultiply(MIN_PAR_SQRT, 15, 1000, 0.1, 0.1);
142+
}
143+
144+
@Test
145+
public void testSparseSparseMatrixMatrix() {
146+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 0.1);
147+
}
148+
149+
private void testMatrixMultiply(int n, int m, int l, double sp1, double sp2) {
150+
MatrixBlock mb1 = MatrixBlock.randOperations(n, m, sp1, 0, 0.1, "uniform", 3);
151+
MatrixBlock mb2 = MatrixBlock.randOperations(m, l, sp2, 0, 0.1, "uniform", 7);
152+
//run single- and multi-threaded kernels and compare
153+
MatrixBlock ret1 = LibMatrixMult.matrixMult(mb1, mb2);
154+
MatrixBlock ret2 = LibMatrixMult.matrixMult(mb1, mb2,
155+
InfrastructureAnalyzer.getLocalParallelism());
156+
TestUtils.compareMatrices(ret1, ret2, 1e-8);
157+
}
158+
}

0 commit comments

Comments
 (0)