Skip to content

Commit eea4afc

Browse files
committed
[MINOR] Additional tests for single-/multi-threaded matmult and uagg
1 parent b6adcca commit eea4afc

File tree

3 files changed

+156
-2
lines changed

3 files changed

+156
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class LibMatrixAgg {
9898

9999
//internal configuration parameters
100100
private static final boolean NAN_AWARENESS = false;
101-
private static final long PAR_NUMCELL_THRESHOLD1 = 1024*256; //Min 256K elements
101+
public static final long PAR_NUMCELL_THRESHOLD1 = 1024*256; //Min 256K elements
102102
private static final long PAR_NUMCELL_THRESHOLD2 = 1024*4; //Min 4K elements
103103
private static final long PAR_INTERMEDIATE_SIZE_THRESHOLD = 2*1024*1024; //Max 2MB
104104

@@ -207,7 +207,7 @@ else if( !in.sparse && lastColCorr )
207207

208208
}
209209

210-
public static MatrixBlock aggregateUnaryMatrix(AggregateUnaryOperator op,MatrixBlock in, MatrixValue result,
210+
public static MatrixBlock aggregateUnaryMatrix(AggregateUnaryOperator op, MatrixBlock in, MatrixValue result,
211211
int blen, MatrixIndexes indexesIn, boolean inCP){
212212

213213
MatrixBlock ret = LibMatrixAgg.prepareAggregateUnaryOutput(in, op, result, blen);
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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.instructions.InstructionUtils;
23+
import org.apache.sysds.runtime.matrix.data.LibMatrixAgg;
24+
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
25+
import org.apache.sysds.runtime.matrix.operators.AggregateUnaryOperator;
26+
import org.apache.sysds.test.TestUtils;
27+
import org.apache.sysds.utils.stats.InfrastructureAnalyzer;
28+
import org.junit.Test;
29+
30+
public class MatrixAggKernelTest {
31+
private static final int MIN_PAR = 2*(int)LibMatrixAgg.PAR_NUMCELL_THRESHOLD1;
32+
private static final int MIN_PAR_SQRT = (int)Math.sqrt(MIN_PAR);
33+
private static final int K = InfrastructureAnalyzer.getLocalParallelism();
34+
35+
@Test
36+
public void testDenseKahanSum() {
37+
testMatrixAggregation("uak+", "uark+", "uack+", 0.95);
38+
}
39+
40+
@Test
41+
public void testSparseKahanSum() {
42+
testMatrixAggregation("uak+", "uark+", "uack+", 0.1);
43+
}
44+
45+
@Test
46+
public void testDenseSum() {
47+
testMatrixAggregation("ua+", "uar+", "uac+", 0.95);
48+
}
49+
50+
@Test
51+
public void testSparseSum() {
52+
testMatrixAggregation("ua+", "uar+", "uac+", 0.1);
53+
}
54+
55+
@Test
56+
public void testDenseSqSum() {
57+
testMatrixAggregation("uasqk+", "uarsqk+", "uacsqk+", 0.95);
58+
}
59+
60+
@Test
61+
public void testSparseSqSum() {
62+
testMatrixAggregation("uasqk+", "uarsqk+", "uacsqk+", 0.1);
63+
}
64+
65+
@Test
66+
public void testDenseMean() {
67+
testMatrixAggregation("uamean", "uarmean", "uacmean", 0.95);
68+
}
69+
70+
@Test
71+
public void testSparseMean() {
72+
testMatrixAggregation("uamean", "uarmean", "uacmean", 0.1);
73+
}
74+
75+
@Test
76+
public void testDenseVar() {
77+
testMatrixAggregation("uavar", "uarvar", "uacvar", 0.95);
78+
}
79+
80+
@Test
81+
public void testSparseVar() {
82+
testMatrixAggregation("uavar", "uarvar", "uacvar", 0.1);
83+
}
84+
85+
@Test
86+
public void testDenseMin() {
87+
testMatrixAggregation("uamin", "uarmin", "uacmin", 0.95);
88+
}
89+
90+
@Test
91+
public void testSparseMin() {
92+
testMatrixAggregation("uamin", "uarmin", "uacmin", 0.1);
93+
}
94+
95+
@Test
96+
public void testDenseMax() {
97+
testMatrixAggregation("uamax", "uarmax", "uacmax", 0.95);
98+
}
99+
100+
@Test
101+
public void testSparseMax() {
102+
testMatrixAggregation("uamax", "uarmax", "uacmax", 0.1);
103+
}
104+
105+
private void testMatrixAggregation(String opcode1, String opcode2, String opcode3, double sp) {
106+
testMatrixAggregation(getOp(opcode1,1), getOp(opcode1,K), MIN_PAR, 1, sp);
107+
testMatrixAggregation(getOp(opcode2,1), getOp(opcode2,K), 1, MIN_PAR, sp);
108+
testMatrixAggregation(getOp(opcode3,1), getOp(opcode3,K), MIN_PAR, 1, sp);
109+
testMatrixAggregation(getOp(opcode1,1), getOp(opcode1,K), MIN_PAR_SQRT, MIN_PAR_SQRT, sp);
110+
testMatrixAggregation(getOp(opcode2,1), getOp(opcode2,K), MIN_PAR_SQRT, MIN_PAR_SQRT, sp);
111+
testMatrixAggregation(getOp(opcode3,1), getOp(opcode3,K), MIN_PAR_SQRT, MIN_PAR_SQRT, sp);
112+
}
113+
114+
private void testMatrixAggregation(AggregateUnaryOperator uaop1,
115+
AggregateUnaryOperator uaopk, int n, int m, double sp)
116+
{
117+
MatrixBlock mb1 = MatrixBlock.randOperations(n, m, sp, 0, 0.1, "uniform", 7);
118+
//run single- and multi-threaded kernels and compare
119+
MatrixBlock ret1 = mb1.aggregateUnaryOperations(uaop1);
120+
MatrixBlock ret2 = mb1.aggregateUnaryOperations(uaopk);
121+
TestUtils.compareMatrices(ret1, ret2, 1e-8);
122+
}
123+
124+
private AggregateUnaryOperator getOp(String opcode, int threads) {
125+
return InstructionUtils.parseBasicAggregateUnaryOperator(opcode, threads);
126+
}
127+
}

src/test/java/org/apache/sysds/test/component/matrix/MatrixMultiplyKernelTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,33 @@ public void testSparseSparseMatrixMatrix() {
151151
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 0.1);
152152
}
153153

154+
//ultra-sparse vs all
155+
156+
@Test
157+
public void testUltraSparseDense() {
158+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 1e-5, 0.95);
159+
}
160+
161+
@Test
162+
public void testUltraSparseSparse() {
163+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 1e-5, 0.1);
164+
}
165+
166+
@Test
167+
public void testUltraSparseUltraSparse() {
168+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 1e-5, 1e-5);
169+
}
170+
171+
@Test
172+
public void testSparseUltraSparse() {
173+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.1, 1e-5);
174+
}
175+
176+
@Test
177+
public void testDenseUltraSparse() {
178+
testMatrixMultiply(MIN_PAR_SQRT, MIN_PAR_SQRT, MIN_PAR_SQRT, 0.95, 1e-5);
179+
}
180+
154181
private void testMatrixMultiply(int n, int m, int l, double sp1, double sp2) {
155182
MatrixBlock mb1 = MatrixBlock.randOperations(n, m, sp1, 0, 0.1, "uniform", 3);
156183
MatrixBlock mb2 = MatrixBlock.randOperations(m, l, sp2, 0, 0.1, "uniform", 7);

0 commit comments

Comments
 (0)