
dev.ludovic.benchmarks.SgemvBenchmark Maven / Gradle / Ivy
/*
* Copyright 2020, Ludovic Henry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package dev.ludovic.blas.benchmarks;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
@Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
public class SgemvBenchmark extends BLASBenchmark {
@Param({"N", "T"})
public String trans;
@Param({"10", "10000"})
public int m;
@Param({"10", "10000"})
public int n;
public float alpha;
public float[] a;
public float[] x;
public float beta;
public float[] y;
@Setup
public void setup() {
alpha = randomFloat();
a = randomFloatArray(m * n);
x = randomFloatArray(trans.equals("T") ? m : n);
beta = randomFloat();
y = randomFloatArray(trans.equals("T") ? n : m);
}
@Benchmark
public void f2j(Blackhole bh) {
f2jBLAS.sgemv(trans, m, n, alpha, a, m, x, 1, beta, y, 1);
bh.consume(y);
}
@Benchmark
public void vector(Blackhole bh) {
vectorizedBLAS.sgemv(trans, m, n, alpha, a, m, x, 1, beta, y, 1);
bh.consume(y);
}
@Benchmark
public void blas(Blackhole bh) {
nativeBLAS.sgemv(trans, m, n, alpha, a, m, x, 1, beta, y, 1);
bh.consume(y);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy