mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Optimize SYMV, SYR, SYR2, and TRMV product kernels
libeigen/eigen!2228 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
59
benchmarks/Core/bench_syr.cpp
Normal file
59
benchmarks/Core/bench_syr.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Benchmarks for symmetric rank-1 update (SYR).
|
||||
//
|
||||
// Tests C.selfadjointView<Lower>().rankUpdate(v, alpha) which computes
|
||||
// C += alpha * v * v^T, updating only the lower (or upper) triangle.
|
||||
// Exercises SelfadjointProduct.h / selfadjoint_rank1_update.
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <Eigen/Core>
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
template <typename Scalar>
|
||||
double syrFlops(Index n) {
|
||||
// SYR: n*(n+1)/2 multiply-adds ~ n^2
|
||||
return (NumTraits<Scalar>::IsComplex ? 8.0 : 2.0) * n * (n + 1) / 2;
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
static void BM_SYR_Lower(benchmark::State& state) {
|
||||
const Index n = state.range(0);
|
||||
using Mat = Matrix<Scalar, Dynamic, Dynamic>;
|
||||
using Vec = Matrix<Scalar, Dynamic, 1>;
|
||||
Vec v = Vec::Random(n);
|
||||
Mat C = Mat::Zero(n, n);
|
||||
Scalar alpha(1);
|
||||
for (auto _ : state) {
|
||||
C.template selfadjointView<Lower>().rankUpdate(v, alpha);
|
||||
benchmark::DoNotOptimize(C.data());
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
state.counters["GFLOPS"] = benchmark::Counter(syrFlops<Scalar>(n), benchmark::Counter::kIsIterationInvariantRate,
|
||||
benchmark::Counter::kIs1000);
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
static void BM_SYR_Upper(benchmark::State& state) {
|
||||
const Index n = state.range(0);
|
||||
using Mat = Matrix<Scalar, Dynamic, Dynamic>;
|
||||
using Vec = Matrix<Scalar, Dynamic, 1>;
|
||||
Vec v = Vec::Random(n);
|
||||
Mat C = Mat::Zero(n, n);
|
||||
Scalar alpha(1);
|
||||
for (auto _ : state) {
|
||||
C.template selfadjointView<Upper>().rankUpdate(v, alpha);
|
||||
benchmark::DoNotOptimize(C.data());
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
state.counters["GFLOPS"] = benchmark::Counter(syrFlops<Scalar>(n), benchmark::Counter::kIsIterationInvariantRate,
|
||||
benchmark::Counter::kIs1000);
|
||||
}
|
||||
|
||||
static void SyrSizes(::benchmark::Benchmark* b) {
|
||||
for (int n : {8, 16, 32, 64, 128, 256, 512, 1024, 2048}) b->Arg(n);
|
||||
}
|
||||
|
||||
BENCHMARK(BM_SYR_Lower<float>)->Apply(SyrSizes)->Name("SYR_Lower_float");
|
||||
BENCHMARK(BM_SYR_Lower<double>)->Apply(SyrSizes)->Name("SYR_Lower_double");
|
||||
BENCHMARK(BM_SYR_Upper<float>)->Apply(SyrSizes)->Name("SYR_Upper_float");
|
||||
BENCHMARK(BM_SYR_Upper<double>)->Apply(SyrSizes)->Name("SYR_Upper_double");
|
||||
Reference in New Issue
Block a user