// 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 // 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 using namespace Eigen; template using Mat = Matrix; template EIGEN_DONT_INLINE void do_compute(SVD& svd, const typename SVD::MatrixType& A) { svd.compute(A); } template static void BM_JacobiSVD(benchmark::State& state) { const Index n = state.range(0); Mat A = Mat::Random(n, n); JacobiSVD, Options> svd(n, n); for (auto _ : state) { do_compute(svd, A); benchmark::DoNotOptimize(svd.singularValues().data()); } state.SetItemsProcessed(state.iterations()); } // clang-format off #define JACOBI_SWEEP_SIZES ->Arg(32)->Arg(64)->Arg(128)->Arg(192)->Arg(256)->Arg(384)->Arg(512) // float ValuesOnly BENCHMARK(BM_JacobiSVD) JACOBI_SWEEP_SIZES ->Name("Jacobi_float_VO"); // float ThinUV BENCHMARK(BM_JacobiSVD) JACOBI_SWEEP_SIZES ->Name("Jacobi_float_UV"); // double ValuesOnly BENCHMARK(BM_JacobiSVD) JACOBI_SWEEP_SIZES ->Name("Jacobi_double_VO"); // double ThinUV BENCHMARK(BM_JacobiSVD) JACOBI_SWEEP_SIZES ->Name("Jacobi_double_UV"); // complex ValuesOnly BENCHMARK(BM_JacobiSVD, 0>) JACOBI_SWEEP_SIZES ->Name("Jacobi_cfloat_VO"); // complex ThinUV BENCHMARK((BM_JacobiSVD, ComputeThinU | ComputeThinV>)) JACOBI_SWEEP_SIZES ->Name("Jacobi_cfloat_UV"); // complex ValuesOnly BENCHMARK(BM_JacobiSVD, 0>) JACOBI_SWEEP_SIZES ->Name("Jacobi_cdouble_VO"); // complex ThinUV BENCHMARK((BM_JacobiSVD, ComputeThinU | ComputeThinV>)) JACOBI_SWEEP_SIZES ->Name("Jacobi_cdouble_UV"); #undef JACOBI_SWEEP_SIZES // clang-format on