2026-02-25 10:03:05 -08:00
|
|
|
// Standalone JacobiSVD benchmark for block-size and threshold sweeps.
|
|
|
|
|
// Compile-time parameters via -D flags:
|
|
|
|
|
// BLOCK_SIZE (default 24), BLOCKING_THRESHOLD (default 192)
|
|
|
|
|
//
|
|
|
|
|
// Build example:
|
|
|
|
|
// g++ -O3 -DNDEBUG -march=native -DBLOCK_SIZE=16 -DBLOCKING_THRESHOLD=128
|
|
|
|
|
// -I../.. bench_jacobi_sweep.cpp -lbenchmark -lbenchmark_main -lpthread
|
|
|
|
|
|
|
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
|
|
|
|
|
|
// Override block size before including Eigen headers.
|
|
|
|
|
#ifdef BLOCK_SIZE
|
|
|
|
|
#define EIGEN_JACOBI_SVD_BLOCK_SIZE BLOCK_SIZE
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef BLOCKING_THRESHOLD
|
|
|
|
|
#define EIGEN_JACOBI_SVD_BLOCKING_THRESHOLD BLOCKING_THRESHOLD
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <Eigen/Dense>
|
|
|
|
|
|
|
|
|
|
using namespace Eigen;
|
|
|
|
|
|
|
|
|
|
template <typename Scalar>
|
|
|
|
|
using Mat = Matrix<Scalar, Dynamic, Dynamic>;
|
|
|
|
|
|
|
|
|
|
template <typename SVD>
|
|
|
|
|
EIGEN_DONT_INLINE void do_compute(SVD& svd, const typename SVD::MatrixType& A) {
|
|
|
|
|
svd.compute(A);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Scalar, int Options>
|
|
|
|
|
static void BM_JacobiSVD(benchmark::State& state) {
|
|
|
|
|
const Index n = state.range(0);
|
|
|
|
|
Mat<Scalar> A = Mat<Scalar>::Random(n, n);
|
|
|
|
|
JacobiSVD<Mat<Scalar>, Options> svd(n, n);
|
|
|
|
|
for (auto _ : state) {
|
|
|
|
|
do_compute(svd, A);
|
|
|
|
|
benchmark::DoNotOptimize(svd.singularValues().data());
|
|
|
|
|
}
|
|
|
|
|
state.SetItemsProcessed(state.iterations());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 17:42:07 -07:00
|
|
|
// clang-format off
|
|
|
|
|
#define JACOBI_SWEEP_SIZES ->Arg(32)->Arg(64)->Arg(128)->Arg(192)->Arg(256)->Arg(384)->Arg(512)
|
2026-02-25 10:03:05 -08:00
|
|
|
// float ValuesOnly
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK(BM_JacobiSVD<float, 0>) JACOBI_SWEEP_SIZES ->Name("Jacobi_float_VO");
|
2026-02-25 10:03:05 -08:00
|
|
|
// float ThinUV
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK(BM_JacobiSVD<float, ComputeThinU | ComputeThinV>) JACOBI_SWEEP_SIZES ->Name("Jacobi_float_UV");
|
2026-02-25 10:03:05 -08:00
|
|
|
// double ValuesOnly
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK(BM_JacobiSVD<double, 0>) JACOBI_SWEEP_SIZES ->Name("Jacobi_double_VO");
|
2026-02-25 10:03:05 -08:00
|
|
|
// double ThinUV
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK(BM_JacobiSVD<double, ComputeThinU | ComputeThinV>) JACOBI_SWEEP_SIZES ->Name("Jacobi_double_UV");
|
2026-02-25 10:03:05 -08:00
|
|
|
// complex<float> ValuesOnly
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK(BM_JacobiSVD<std::complex<float>, 0>) JACOBI_SWEEP_SIZES ->Name("Jacobi_cfloat_VO");
|
2026-02-25 10:03:05 -08:00
|
|
|
// complex<float> ThinUV
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK((BM_JacobiSVD<std::complex<float>, ComputeThinU | ComputeThinV>)) JACOBI_SWEEP_SIZES ->Name("Jacobi_cfloat_UV");
|
2026-02-25 10:03:05 -08:00
|
|
|
// complex<double> ValuesOnly
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK(BM_JacobiSVD<std::complex<double>, 0>) JACOBI_SWEEP_SIZES ->Name("Jacobi_cdouble_VO");
|
2026-02-25 10:03:05 -08:00
|
|
|
// complex<double> ThinUV
|
2026-03-20 17:42:07 -07:00
|
|
|
BENCHMARK((BM_JacobiSVD<std::complex<double>, ComputeThinU | ComputeThinV>)) JACOBI_SWEEP_SIZES ->Name("Jacobi_cdouble_UV");
|
|
|
|
|
#undef JACOBI_SWEEP_SIZES
|
|
|
|
|
// clang-format on
|