r/javahelp • • Jul 27 '19

Project Panama (vectorIntrinsics), matmul performance

Pulled and compiled vectorIntrinsics branch of project Panama today.

The main OMG is that measured scope takes only 400-450ms (after C2, C1 - 700ms) for 2048x2048 matrix-matrix multiplication.

Ubuntu 18.04. Ryzen 1600x stock.

float[][] a = generate(size, () -> (float) Math.random());
float[][] b = generate(size, () -> (float) Math.random());
float[][] r = generate(size, () -> 0.0f);

// measured scope
for(int i = 0; i < size; i++) {
            int finalI = i;
            forkJoinPool.submit(() -> {
                for(int j = 0; j < size; j++) {
                    float dotProduct = 0;
                    for(int k = 0; k < size; k += SPECIES.length()) {
                        FloatVector av = fromArray(SPECIES, a[finalI], k);
                        // just assuming, that `b` matrix is transposed
                        FloatVector bv = fromArray(SPECIES, b[j], k);

                        dotProduct += av.lanewise(MUL, bv).reduceLanes(ADD);
                    }
                    r[finalI][j] = dotProduct;
                }
            });
}
forkJoinPool.shutdown();
forkJoinPool.awaitTermination(100, TimeUnit.SECONDS);

Am i missing something in the code ? Because performance is unbelievable. Does anyone has precise benchmarks results for CUBLAS, MKL for such sizes?

1 Upvotes

0 comments sorted by