Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add faster JVM baseline for MMM #1

Closed
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/ch/ethz/acl/ngen/mmm/BenchMMM.scala
Expand Up @@ -31,18 +31,26 @@ class BenchMMM extends Bench.ForkedTime {
performance of "MMM" config (
exec.minWarmupRuns -> 100,
exec.maxWarmupRuns -> 100,
exec.independentSamples -> 1
exec.independentSamples -> 1,
exec.jvmflags -> List("-XX:-TieredCompilation", // ensure C2 is actually used
"-XX:CompileThreshold=100" // the paper claims to set this
)
) in {
measure method "jMMM.blocked (JVM implementation)" in {
measure method "jMMM.fast (JVM implementation)" in {
using(argsMMM) in {
case (a, b, c, size) => MMM.jMMM.blocked(a, b, c, size)
case (a, b, c, size) => MMM.jMMM.fast(a, b, c, size)
}
}
measure method "nMMM.blocked (LMS generated)" in {
using(argsMMM) in {
case (a, b, c, size) => MMM.nMMM.blocked(a, b, c, size)
}
}
measure method "jMMM.blocked (JVM implementation)" in {
using(argsMMM) in {
case (a, b, c, size) => MMM.jMMM.blocked(a, b, c, size)
}
}
measure method "jMMM.baseline (JVM implementation)" in {
using(argsMMM) in {
case (a, b, c, size) => MMM.jMMM.baseline(a, b, c, size)
Expand Down
26 changes: 26 additions & 0 deletions src/ch/ethz/acl/ngen/mmm/JMMM.java
@@ -1,5 +1,7 @@
package ch.ethz.acl.ngen.mmm;

import java.util.Arrays;

public class JMMM {
//
// Baseline implementation of a Matrix-Matrix-Multiplication
Expand Down Expand Up @@ -36,4 +38,28 @@ public void blocked(float[] a, float[] b, float[] c, int n) {
}
}

public void fast(float[] a, float[] b, float[] c, int n) {
float[] bBuffer = new float[n];
float[] cBuffer = new float[n];
int in = 0;
for (int i = 0; i < n; ++i) {
int kn = 0;
for (int k = 0; k < n; ++k) {
float aik = a[in + k];
System.arraycopy(b, kn, bBuffer, 0, n);
saxpy(n, aik, bBuffer, cBuffer);
kn += n;
}
System.arraycopy(cBuffer, 0, c, in, n);
Arrays.fill(cBuffer, 0f);
in += n;
}
}

private void saxpy(int n, float aik, float[] b, float[] c) {
for (int i = 0; i < n; ++i) {
c[i] += aik * b[i];
}
}

}