Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1588,5 +1588,19 @@
<artifactId>fastdoubleparser</artifactId>
<version>0.9.0</version>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.37</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.37</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ private static void matrixMultSparseSparseVM(SparseBlock a, SparseBlock b, Dense
int blen = b.size(aix[k]);
int[] bix = b.indexes(aix[k]);
double[] bvals = b.values(aix[k]);
vectMultiplyAdd(avals[k], bvals, cvals, bix, bpos, 0, blen);
vectMultiplyAddScatter(avals[k], bvals, cvals, bix, bpos, 0, blen);
}
}

Expand All @@ -2069,7 +2069,7 @@ private static long matrixMultSparseSparseSparseMM(SparseBlock a, SparseBlock b,
for(int k = apos; k < apos+alen; k++) {
int aixk = aix[k];
if( b.isEmpty(aixk) ) continue;
vectMultiplyAdd(avals[k], b.values(aixk), tmp,
vectMultiplyAddScatter(avals[k], b.values(aixk), tmp,
b.indexes(aixk), b.pos(aixk), 0, b.size(aixk));
hitNonEmpty = true;
}
Expand Down Expand Up @@ -2100,7 +2100,7 @@ private static void matrixMultSparseSparseMMSmallRHS(SparseBlock a, SparseBlock
for(int k = apos; k < apos+alen; k++) {
int aixk = aix[k];
if( b.isEmpty(aixk) ) continue;
vectMultiplyAdd(avals[k], b.values(aixk), cvals,
vectMultiplyAddScatter(avals[k], b.values(aixk), cvals,
b.indexes(aixk), b.pos(aixk), cix, b.size(aixk));
}
}
Expand Down Expand Up @@ -2132,7 +2132,7 @@ private static void matrixMultSparseSparseMM(SparseBlock a, SparseBlock b, Dense
int k = curk[i-bi] + apos;
for(; k < apos+alen && aix[k]<bkmin; k++) {
if( b.isEmpty(aix[k]) ) continue;
vectMultiplyAdd(avals[k], b.values(aix[k]), cvals,
vectMultiplyAddScatter(avals[k], b.values(aix[k]), cvals,
b.indexes(aix[k]), b.pos(aix[k]), cix, b.size(aix[k]));
}
curk[i-bi] = k - apos;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.apache.sysds.test.component.matrix;

import java.util.concurrent.TimeUnit;
import org.apache.sysds.runtime.matrix.data.LibMatrixMult;
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
import org.apache.sysds.test.TestUtils;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
Comment on lines +15 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add this JMH dependency to make a benchmark for the matrix multiply.

Instead please move this from being in test to being in performance.
https://github.com/apache/systemds/tree/main/src/test/java/org/apache/sysds/performance

and do not add the dependency package for the benchmark.

public class BenchmarkMatMult {

private MatrixBlock left;
private MatrixBlock right;
private MatrixBlock result;

@Param({"1024", "2048", "4096", "8192"})
public int m;

@Param({"1"})
public int cd;

@Param({"0.5", "0.75", "1.0"})
public double sparsityLeft;

@Param({"0.001", "0.01", "0.1", "0.2"})
public double sparsityRight;

@Param({"1024", "2048", "4096", "8192"})
public int n;

@Setup(Level.Trial)
public void setup() {
left = TestUtils.ceil(TestUtils.generateTestMatrixBlock(m, cd, -10, 10, sparsityLeft, 13));
if (!left.isInSparseFormat()) {
left.sparseToDense();
left.denseToSparse(true);
}

MatrixBlock rightOriginal = TestUtils.ceil(TestUtils.generateTestMatrixBlock(cd, n, -10, 10, sparsityRight, 14));
right = new MatrixBlock();
right.copy(rightOriginal, false);
if (!right.isInSparseFormat()) {
right.sparseToDense();
right.denseToSparse(true);
}

result = new MatrixBlock(m, n, true);
result.allocateBlock();
}

@Setup(Level.Iteration)
public void clearResult() {
result.reset(m, n, true);
}

@Benchmark
public void benchmarkSparseSparse(Blackhole bh) {
LibMatrixMult.matrixMult(left, right, result);
bh.consume(result);
}

public static void main(String[] args) throws RunnerException {
String tag = "vector-api-mult-sparse-sparse-" + System.currentTimeMillis();
Options opt = new OptionsBuilder()
.include(BenchmarkMatMult.class.getName())
.jvmArgs("--add-modules=jdk.incubator.vector")
.result(tag + ".csv")
.resultFormat(ResultFormatType.CSV)
.build();
new Runner(opt).run();
}
}