diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 950d8b71..f701a3ba 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -23,20 +23,18 @@ target_include_directories( algebra_bench_array INTERFACE "$" ) target_link_libraries(algebra_bench_array INTERFACE algebra::array_cmath algebra::common_storage) -add_library( algebra::bench_array ALIAS algebra_bench_array ) - algebra_add_benchmark( array_getter "array/array_getter.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_array algebra::array_cmath ) + algebra_bench_array algebra::array_cmath ) algebra_add_benchmark( array_vector "array/array_vector.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_array algebra::array_cmath ) + algebra_bench_array algebra::array_cmath ) algebra_add_benchmark( array_transform3 "array/array_transform3.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_array algebra::array_cmath ) + algebra_bench_array algebra::array_cmath ) if( ALGEBRA_PLUGINS_INCLUDE_EIGEN ) add_library( algebra_bench_eigen INTERFACE ) @@ -44,23 +42,40 @@ if( ALGEBRA_PLUGINS_INCLUDE_EIGEN ) "$" ) target_link_libraries(algebra_bench_eigen INTERFACE algebra::eigen_eigen algebra::common_storage) - add_library( algebra::bench_eigen ALIAS algebra_bench_eigen ) - algebra_add_benchmark( eigen_getter "eigen/eigen_getter.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_eigen algebra::eigen_eigen ) + algebra_bench_eigen algebra::eigen_eigen ) algebra_add_benchmark( eigen_vector "eigen/eigen_vector.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_eigen algebra::eigen_eigen ) + algebra_bench_eigen algebra::eigen_eigen ) algebra_add_benchmark( eigen_transform3 "eigen/eigen_transform3.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_eigen algebra::eigen_eigen ) + algebra_bench_eigen algebra::eigen_eigen ) endif() if( ALGEBRA_PLUGINS_INCLUDE_VC ) + add_library( algebra_bench_vc_aos INTERFACE ) + target_include_directories( algebra_bench_vc_aos INTERFACE + "$" ) + target_link_libraries(algebra_bench_vc_aos INTERFACE + algebra::vc_aos + algebra::common_storage) + algebra_add_benchmark( vc_aos_getter + "vc_aos/vc_aos_getter.cpp" + LINK_LIBRARIES benchmark::benchmark algebra::bench_common + algebra_bench_vc_aos algebra::vc_aos ) + algebra_add_benchmark( vc_aos_vector + "vc_aos/vc_aos_vector.cpp" + LINK_LIBRARIES benchmark::benchmark algebra::bench_common + algebra_bench_vc_aos algebra::vc_aos ) + algebra_add_benchmark( vc_aos_transform3 + "vc_aos/vc_aos_transform3.cpp" + LINK_LIBRARIES benchmark::benchmark algebra::bench_common + algebra_bench_vc_aos algebra::vc_aos ) + if( NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang" ) add_library( algebra_bench_vc_soa INTERFACE ) target_include_directories( algebra_bench_vc_soa INTERFACE @@ -68,19 +83,17 @@ if( ALGEBRA_PLUGINS_INCLUDE_VC ) target_link_libraries(algebra_bench_vc_soa INTERFACE algebra::vc_soa algebra::common_storage) - add_library( algebra::bench_vc_soa ALIAS algebra_bench_vc_soa ) - algebra_add_benchmark( vc_soa_getter "vc_soa/vc_soa_getter.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_vc_soa algebra::vc_soa ) + algebra_bench_vc_soa algebra::vc_soa ) algebra_add_benchmark( vc_soa_vector "vc_soa/vc_soa_vector.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_vc_soa algebra::vc_soa ) + algebra_bench_vc_soa algebra::vc_soa ) algebra_add_benchmark( vc_soa_transform3 "vc_soa/vc_soa_transform3.cpp" LINK_LIBRARIES benchmark::benchmark algebra::bench_common - algebra::bench_vc_soa algebra::vc_soa ) + algebra_bench_vc_soa algebra::vc_soa ) endif() endif() diff --git a/benchmarks/array/array_getter.cpp b/benchmarks/array/array_getter.cpp index e53cb24a..b4d7890f 100644 --- a/benchmarks/array/array_getter.cpp +++ b/benchmarks/array/array_getter.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -9,6 +9,7 @@ #include "algebra/array_cmath.hpp" #include "benchmark/array/data_generator.hpp" #include "benchmark/common/benchmark_getter.hpp" +#include "benchmark/common/register_benchmark.hpp" // Benchmark include #include @@ -21,71 +22,42 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; - constexpr std::size_t n_warmup{static_cast(0.1 * n_samples)}; - // // Prepare benchmarks // algebra::benchmark_base::configuration cfg{}; - cfg.n_samples(n_samples).n_warmup(n_warmup); - cfg.do_sleep(false); + cfg.n_samples(100000); - vector_unaryOP_bm v_phi_s{cfg}; - vector_unaryOP_bm v_theta_s{cfg}; - vector_unaryOP_bm v_perp_s{cfg}; - vector_unaryOP_bm v_norm_s{cfg}; - vector_unaryOP_bm v_eta_s{cfg}; + using phi_f_t = vector_unaryOP_bm; + using theta_f_t = vector_unaryOP_bm; + using perp_f_t = vector_unaryOP_bm; + using norm_f_t = vector_unaryOP_bm; + using eta_f_t = vector_unaryOP_bm; - vector_unaryOP_bm v_phi_d{cfg}; - vector_unaryOP_bm v_theta_d{cfg}; - vector_unaryOP_bm v_perp_d{cfg}; - vector_unaryOP_bm v_norm_d{cfg}; - vector_unaryOP_bm v_eta_d{cfg}; + using phi_d_t = vector_unaryOP_bm; + using theta_d_t = vector_unaryOP_bm; + using perp_d_t = vector_unaryOP_bm; + using norm_d_t = vector_unaryOP_bm; + using eta_d_t = vector_unaryOP_bm; - std::cout << "Algebra-Plugins 'getter' benchmark (std::array)\n" + std::cout << "-----------------------------------------------\n" + << "Algebra-Plugins 'getter' benchmark (std::array)\n" << "-----------------------------------------------\n\n" << cfg; // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_phi_s.name() + "_single").c_str(), v_phi_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_phi_d.name() + "_double").c_str(), v_phi_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_theta_s.name() + "_single").c_str(), - v_theta_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_theta_d.name() + "_double").c_str(), - v_theta_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_perp_s.name() + "_single").c_str(), - v_perp_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_perp_d.name() + "_double").c_str(), - v_perp_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_norm_s.name() + "_single").c_str(), - v_norm_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_norm_d.name() + "_double").c_str(), - v_norm_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_eta_s.name() + "_single").c_str(), v_eta_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_eta_d.name() + "_double").c_str(), v_eta_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); diff --git a/benchmarks/array/array_transform3.cpp b/benchmarks/array/array_transform3.cpp index 752b3893..eaee61cf 100644 --- a/benchmarks/array/array_transform3.cpp +++ b/benchmarks/array/array_transform3.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -9,6 +9,7 @@ #include "algebra/array_cmath.hpp" #include "benchmark/array/data_generator.hpp" #include "benchmark/common/benchmark_transform3.hpp" +#include "benchmark/common/register_benchmark.hpp" // Benchmark include #include @@ -18,34 +19,27 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; - constexpr std::size_t n_warmup{static_cast(0.1 * n_samples)}; - // // Prepare benchmarks // algebra::benchmark_base::configuration cfg{}; - cfg.n_samples(n_samples).n_warmup(n_warmup); - cfg.do_sleep(false); + cfg.n_samples(100000); - transform3_bm> v_trf_s{cfg}; - transform3_bm> v_trf_d{cfg}; + using trf_f_t = transform3_bm>; + using trf_d_t = transform3_bm>; - std::cout << "Algebra-Plugins 'transform3' benchmark (std::array)\n" + std::cout << "-----------------------------------------------\n" + << "Algebra-Plugins 'transform3' benchmark (std::array)\n" << "---------------------------------------------------\n\n" << cfg; // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_trf_s.name() + "_single").c_str(), v_trf_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_trf_d.name() + "_double").c_str(), v_trf_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); ::benchmark::Shutdown(); -} \ No newline at end of file +} diff --git a/benchmarks/array/array_vector.cpp b/benchmarks/array/array_vector.cpp index 20b7ae05..e680b481 100644 --- a/benchmarks/array/array_vector.cpp +++ b/benchmarks/array/array_vector.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -9,6 +9,7 @@ #include "algebra/array_cmath.hpp" #include "benchmark/array/data_generator.hpp" #include "benchmark/common/benchmark_vector.hpp" +#include "benchmark/common/register_benchmark.hpp" // Benchmark include #include @@ -21,71 +22,44 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; - constexpr std::size_t n_warmup{static_cast(0.1 * n_samples)}; - // // Prepare benchmarks // algebra::benchmark_base::configuration cfg{}; - cfg.n_samples(n_samples).n_warmup(n_warmup); - cfg.do_sleep(false); + cfg.n_samples(100000); - vector_binaryOP_bm v_add_s{cfg}; - vector_binaryOP_bm v_sub_s{cfg}; - vector_binaryOP_bm v_dot_s{cfg}; - vector_binaryOP_bm v_cross_s{cfg}; - vector_unaryOP_bm v_normalize_s{ - cfg}; + using add_f_t = vector_binaryOP_bm; + using sub_f_t = vector_binaryOP_bm; + using dot_f_t = vector_binaryOP_bm; + using cross_f_t = vector_binaryOP_bm; + using normlz_f_t = + vector_unaryOP_bm; - vector_binaryOP_bm v_add_d{cfg}; - vector_binaryOP_bm v_sub_d{cfg}; - vector_binaryOP_bm v_dot_d{cfg}; - vector_binaryOP_bm v_cross_d{cfg}; - vector_unaryOP_bm v_normalize_d{ - cfg}; + using add_d_t = vector_binaryOP_bm; + using sub_d_t = vector_binaryOP_bm; + using dot_d_t = vector_binaryOP_bm; + using cross_d_t = vector_binaryOP_bm; + using normlz_d_t = + vector_unaryOP_bm; - std::cout << "Algebra-Plugins 'vector' benchmark (std::array)\n" + std::cout << "-----------------------------------------------\n" + << "Algebra-Plugins 'vector' benchmark (std::array)\n" << "-----------------------------------------------\n\n" << cfg; // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_add_s.name() + "_single").c_str(), v_add_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_add_d.name() + "_double").c_str(), v_add_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_sub_s.name() + "_single").c_str(), v_sub_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_sub_d.name() + "_double").c_str(), v_sub_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_dot_s.name() + "_single").c_str(), v_dot_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_dot_d.name() + "_double").c_str(), v_dot_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_cross_s.name() + "_single").c_str(), - v_cross_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_cross_d.name() + "_double").c_str(), - v_cross_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_normalize_s.name() + "_single").c_str(), - v_normalize_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_normalize_d.name() + "_double").c_str(), - v_normalize_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); diff --git a/benchmarks/common/include/benchmark/common/benchmark_base.hpp b/benchmarks/common/include/benchmark/common/benchmark_base.hpp index b3ca9fdd..10f38dc2 100644 --- a/benchmarks/common/include/benchmark/common/benchmark_base.hpp +++ b/benchmarks/common/include/benchmark/common/benchmark_base.hpp @@ -22,13 +22,9 @@ struct benchmark_base { struct configuration { /// Size of data sample to be used in benchmark std::size_t m_samples{100u}; - /// Run a number of operations before the benchmark - bool m_warmup = true; // Sleep after building data sample bool m_sleep = false; - // Size of data in warm-up round - std::size_t m_n_warmup{static_cast(0.1f * m_samples)}; - // Size of data in warm-up round + // Number of seconds to sleep std::size_t m_n_sleep{1u}; /// Setters @@ -37,15 +33,6 @@ struct benchmark_base { m_samples = n; return *this; } - configuration& do_warmup(bool b) { - m_warmup = b; - return *this; - } - configuration& n_warmup(std::size_t n) { - m_n_warmup = n; - m_warmup = true; - return *this; - } configuration& do_sleep(bool b) { m_sleep = b; return *this; @@ -60,8 +47,6 @@ struct benchmark_base { /// Getters /// @{ std::size_t n_samples() const { return m_samples; } - constexpr bool do_warmup() const { return m_warmup; } - constexpr std::size_t n_warmup() const { return m_n_warmup; } constexpr bool do_sleep() const { return m_sleep; } constexpr std::size_t n_sleep() const { return m_n_sleep; } /// @} @@ -95,9 +80,6 @@ struct benchmark_base { std::ostream& operator<<(std::ostream& os, const benchmark_base::configuration& cfg) { os << " -> running:\t " << cfg.n_samples() << " samples" << std::endl; - if (cfg.do_warmup()) { - os << " -> warmup: \t " << cfg.n_warmup() << " samples" << std::endl; - } if (cfg.do_sleep()) { os << " -> cool down:\t " << cfg.n_sleep() << "s" << std::endl; } @@ -105,4 +87,4 @@ std::ostream& operator<<(std::ostream& os, return os; } -} // namespace algebra \ No newline at end of file +} // namespace algebra diff --git a/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp b/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp index fb7298e5..e5d092e9 100644 --- a/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp +++ b/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -41,9 +41,7 @@ struct transform3_bm : public vector_bm { /// Construct from an externally provided configuration @param cfg transform3_bm(benchmark_base::configuration cfg) : base_type{cfg} { - const std::size_t n_data{this->m_cfg.n_samples() + this->m_cfg.n_warmup()}; - - trfs.reserve(n_data); + trfs.reserve(this->m_cfg.n_samples()); fill_random_trf(trfs); } @@ -54,30 +52,24 @@ struct transform3_bm : public vector_bm { /// Benchmark case void operator()(::benchmark::State &state) override { - const std::size_t n_samples{this->m_cfg.n_samples()}; - const std::size_t n_warmup{this->m_cfg.n_warmup()}; + using vector_t = typename transform3_t::vector3; + using point_t = typename transform3_t::point3; - // Spin down before benchmark (Thread zero is counting the clock) - if (state.thread_index() == 0 && this->m_cfg.do_sleep()) { - std::this_thread::sleep_for(std::chrono::seconds(this->m_cfg.n_sleep())); - } + const std::size_t n_samples{this->m_cfg.n_samples()}; // Run the benchmark for (auto _ : state) { - // Warm-up - state.PauseTiming(); - if (this->m_cfg.do_warmup()) { - for (std::size_t i{0u}; i < n_warmup; ++i) { - ::benchmark::DoNotOptimize( - this->trfs[i].vector_to_global(this->a[i])); - benchmark::ClobberMemory(); - } - } - state.ResumeTiming(); + for (std::size_t i{0}; i < n_samples; ++i) { + + point_t result1 = this->trfs[i].point_to_global(this->a[i]); + point_t result2 = this->trfs[i].point_to_local(this->a[i]); + vector_t result3 = this->trfs[i].vector_to_global(this->a[i]); + vector_t result4 = this->trfs[i].vector_to_local(this->a[i]); - for (std::size_t i{n_warmup}; i < n_samples + n_warmup; ++i) { - ::benchmark::DoNotOptimize(this->trfs[i].vector_to_global(this->a[i])); - benchmark::ClobberMemory(); + ::benchmark::DoNotOptimize(result1); + ::benchmark::DoNotOptimize(result2); + ::benchmark::DoNotOptimize(result3); + ::benchmark::DoNotOptimize(result4); } } } diff --git a/benchmarks/common/include/benchmark/common/benchmark_vector.hpp b/benchmarks/common/include/benchmark/common/benchmark_vector.hpp index 55ec6aee..7a5b52c1 100644 --- a/benchmarks/common/include/benchmark/common/benchmark_vector.hpp +++ b/benchmarks/common/include/benchmark/common/benchmark_vector.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -37,7 +37,7 @@ struct vector_bm : public benchmark_base { /// Construct from an externally provided configuration @param cfg vector_bm(benchmark_base::configuration cfg) : benchmark_base{cfg} { - const std::size_t n_data{this->m_cfg.n_samples() + this->m_cfg.n_warmup()}; + const std::size_t n_data{this->m_cfg.n_samples()}; a.reserve(n_data); b.reserve(n_data); @@ -67,29 +67,15 @@ struct vector_unaryOP_bm : public vector_bm> { void operator()(::benchmark::State &state) override { - const std::size_t n_samples{this->m_cfg.n_samples()}; - const std::size_t n_warmup{this->m_cfg.n_warmup()}; + using result_t = std::invoke_result_t>; - // Spin down before benchmark (Thread zero is counting the clock) - if (state.thread_index() == 0 && this->m_cfg.do_sleep()) { - std::this_thread::sleep_for(std::chrono::seconds(this->m_cfg.n_sleep())); - } + const std::size_t n_samples{this->m_cfg.n_samples()}; // Run the benchmark for (auto _ : state) { - // Warm-up - state.PauseTiming(); - if (this->m_cfg.do_warmup()) { - for (std::size_t i{0u}; i < n_warmup; ++i) { - ::benchmark::DoNotOptimize(unaryOP{}(this->a[i])); - benchmark::ClobberMemory(); - } - } - state.ResumeTiming(); - - for (std::size_t i{n_warmup}; i < n_samples + n_warmup; ++i) { - ::benchmark::DoNotOptimize(unaryOP{}(this->a[i])); - benchmark::ClobberMemory(); + for (std::size_t i{0}; i < n_samples; ++i) { + result_t result = unaryOP{}(this->a[i]); + ::benchmark::DoNotOptimize(const_cast(result)); } } } @@ -109,29 +95,16 @@ struct vector_binaryOP_bm : public vector_bm> { void operator()(::benchmark::State &state) override { - const std::size_t n_samples{this->m_cfg.n_samples()}; - const std::size_t n_warmup{this->m_cfg.n_warmup()}; + using result_t = + std::invoke_result_t, vector_t>; - // Spin down before benchmark (Thread zero is counting the clock) - if ((state.thread_index() == 0) && this->m_cfg.do_sleep()) { - std::this_thread::sleep_for(std::chrono::seconds(this->m_cfg.n_sleep())); - } + const std::size_t n_samples{this->m_cfg.n_samples()}; // Run the benchmark for (auto _ : state) { - // Warm-up - state.PauseTiming(); - if (this->m_cfg.do_warmup()) { - for (std::size_t i{0u}; i < n_warmup; ++i) { - ::benchmark::DoNotOptimize(binaryOP{}(this->a[i], this->b[i])); - benchmark::ClobberMemory(); - } - } - state.ResumeTiming(); - - for (std::size_t i{n_warmup}; i < n_samples + n_warmup; ++i) { - ::benchmark::DoNotOptimize(binaryOP{}(this->a[i], this->b[i])); - benchmark::ClobberMemory(); + for (std::size_t i{0}; i < n_samples; ++i) { + result_t result = binaryOP{}(this->a[i], this->b[i]); + ::benchmark::DoNotOptimize(const_cast(result)); } } } diff --git a/benchmarks/common/include/benchmark/common/register_benchmark.hpp b/benchmarks/common/include/benchmark/common/register_benchmark.hpp new file mode 100644 index 00000000..6eec7a7b --- /dev/null +++ b/benchmarks/common/include/benchmark/common/register_benchmark.hpp @@ -0,0 +1,28 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Benchmark include +#include + +// System include(s) +#include + +namespace algebra { + +template +void register_benchmark(const config_t& cfg, const std::string& suffix) { + benchmark_t bench{cfg}; + + ::benchmark::RegisterBenchmark((bench.name() + suffix).c_str(), bench) + ->UseRealTime() + ->MeasureProcessCPUTime() + ->ThreadPerCpu(); +} + +} // namespace algebra diff --git a/benchmarks/eigen/eigen_getter.cpp b/benchmarks/eigen/eigen_getter.cpp index 14ce10eb..2761a5b0 100644 --- a/benchmarks/eigen/eigen_getter.cpp +++ b/benchmarks/eigen/eigen_getter.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,6 +8,7 @@ // Project include(s) #include "algebra/eigen_eigen.hpp" #include "benchmark/common/benchmark_getter.hpp" +#include "benchmark/common/register_benchmark.hpp" #include "benchmark/eigen/data_generator.hpp" // Benchmark include @@ -21,71 +22,42 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; - constexpr std::size_t n_warmup{static_cast(0.1 * n_samples)}; - // // Prepare benchmarks // algebra::benchmark_base::configuration cfg{}; - cfg.n_samples(n_samples).n_warmup(n_warmup); - cfg.do_sleep(false); + cfg.n_samples(100000); - vector_unaryOP_bm v_phi_s{cfg}; - vector_unaryOP_bm v_theta_s{cfg}; - vector_unaryOP_bm v_perp_s{cfg}; - vector_unaryOP_bm v_norm_s{cfg}; - vector_unaryOP_bm v_eta_s{cfg}; + using phi_f_t = vector_unaryOP_bm; + using theta_f_t = vector_unaryOP_bm; + using perp_f_t = vector_unaryOP_bm; + using norm_f_t = vector_unaryOP_bm; + using eta_f_t = vector_unaryOP_bm; - vector_unaryOP_bm v_phi_d{cfg}; - vector_unaryOP_bm v_theta_d{cfg}; - vector_unaryOP_bm v_perp_d{cfg}; - vector_unaryOP_bm v_norm_d{cfg}; - vector_unaryOP_bm v_eta_d{cfg}; + using phi_d_t = vector_unaryOP_bm; + using theta_d_t = vector_unaryOP_bm; + using perp_d_t = vector_unaryOP_bm; + using norm_d_t = vector_unaryOP_bm; + using eta_d_t = vector_unaryOP_bm; - std::cout << "Algebra-Plugins 'getter' benchmark (Eigen)\n" + std::cout << "------------------------------------------\n" + << "Algebra-Plugins 'getter' benchmark (Eigen)\n" << "------------------------------------------\n\n" << cfg; // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_phi_s.name() + "_single").c_str(), v_phi_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_phi_d.name() + "_double").c_str(), v_phi_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_theta_s.name() + "_single").c_str(), - v_theta_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_theta_d.name() + "_double").c_str(), - v_theta_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_perp_s.name() + "_single").c_str(), - v_perp_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_perp_d.name() + "_double").c_str(), - v_perp_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_norm_s.name() + "_single").c_str(), - v_norm_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_norm_d.name() + "_double").c_str(), - v_norm_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_eta_s.name() + "_single").c_str(), v_eta_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_eta_d.name() + "_double").c_str(), v_eta_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); diff --git a/benchmarks/eigen/eigen_transform3.cpp b/benchmarks/eigen/eigen_transform3.cpp index 747a526b..414237ec 100644 --- a/benchmarks/eigen/eigen_transform3.cpp +++ b/benchmarks/eigen/eigen_transform3.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,6 +8,7 @@ // Project include(s) #include "algebra/eigen_eigen.hpp" #include "benchmark/common/benchmark_transform3.hpp" +#include "benchmark/common/register_benchmark.hpp" #include "benchmark/eigen/data_generator.hpp" // Benchmark include @@ -18,34 +19,27 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; - constexpr std::size_t n_warmup{static_cast(0.1 * n_samples)}; - // // Prepare benchmarks // algebra::benchmark_base::configuration cfg{}; - cfg.n_samples(n_samples).n_warmup(n_warmup); - cfg.do_sleep(false); + cfg.n_samples(100000); - transform3_bm> v_trf_s{cfg}; - transform3_bm> v_trf_d{cfg}; + using trf_f_t = transform3_bm>; + using trf_d_t = transform3_bm>; - std::cout << "Algebra-Plugins 'transform3' benchmark (Eigen3)\n" + std::cout << "------------------------------------------\n" + << "Algebra-Plugins 'transform3' benchmark (Eigen3)\n" << "-----------------------------------------------\n\n" << cfg; // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_trf_s.name() + "_single").c_str(), v_trf_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_trf_d.name() + "_double").c_str(), v_trf_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); ::benchmark::Shutdown(); -} \ No newline at end of file +} diff --git a/benchmarks/eigen/eigen_vector.cpp b/benchmarks/eigen/eigen_vector.cpp index ba3c03a0..e36fe0e7 100644 --- a/benchmarks/eigen/eigen_vector.cpp +++ b/benchmarks/eigen/eigen_vector.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,6 +8,7 @@ // Project include(s) #include "algebra/eigen_eigen.hpp" #include "benchmark/common/benchmark_vector.hpp" +#include "benchmark/common/register_benchmark.hpp" #include "benchmark/eigen/data_generator.hpp" // Benchmark include @@ -21,71 +22,44 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; - constexpr std::size_t n_warmup{static_cast(0.1 * n_samples)}; - // // Prepare benchmarks // algebra::benchmark_base::configuration cfg{}; - cfg.n_samples(n_samples).n_warmup(n_warmup); - cfg.do_sleep(false); + cfg.n_samples(100000); - vector_binaryOP_bm v_add_s{cfg}; - vector_binaryOP_bm v_sub_s{cfg}; - vector_binaryOP_bm v_dot_s{cfg}; - vector_binaryOP_bm v_cross_s{cfg}; - vector_unaryOP_bm v_normalize_s{ - cfg}; + using add_f_t = vector_binaryOP_bm; + using sub_f_t = vector_binaryOP_bm; + using dot_f_t = vector_binaryOP_bm; + using cross_f_t = vector_binaryOP_bm; + using normlz_f_t = + vector_unaryOP_bm; - vector_binaryOP_bm v_add_d{cfg}; - vector_binaryOP_bm v_sub_d{cfg}; - vector_binaryOP_bm v_dot_d{cfg}; - vector_binaryOP_bm v_cross_d{cfg}; - vector_unaryOP_bm v_normalize_d{ - cfg}; + using add_d_t = vector_binaryOP_bm; + using sub_d_t = vector_binaryOP_bm; + using dot_d_t = vector_binaryOP_bm; + using cross_d_t = vector_binaryOP_bm; + using normlz_d_t = + vector_unaryOP_bm; - std::cout << "Algebra-Plugins 'vector' benchmark (Eigen)\n" + std::cout << "------------------------------------------\n" + << "Algebra-Plugins 'vector' benchmark (Eigen)\n" << "------------------------------------------\n\n" << cfg; // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_add_s.name() + "_single").c_str(), v_add_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_add_d.name() + "_double").c_str(), v_add_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_sub_s.name() + "_single").c_str(), v_sub_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_sub_d.name() + "_double").c_str(), v_sub_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_dot_s.name() + "_single").c_str(), v_dot_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_dot_d.name() + "_double").c_str(), v_dot_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_cross_s.name() + "_single").c_str(), - v_cross_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_cross_d.name() + "_double").c_str(), - v_cross_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_normalize_s.name() + "_single").c_str(), - v_normalize_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_normalize_d.name() + "_double").c_str(), - v_normalize_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); diff --git a/benchmarks/vc_aos/include/benchmark/vc_aos/data_generator.hpp b/benchmarks/vc_aos/include/benchmark/vc_aos/data_generator.hpp new file mode 100644 index 00000000..21874cff --- /dev/null +++ b/benchmarks/vc_aos/include/benchmark/vc_aos/data_generator.hpp @@ -0,0 +1,61 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s) +#include "algebra/vc_aos.hpp" + +// System include(s) +#include +#include + +namespace algebra { + +/// Fill a @c Vc::SimdArray based vector with random values +template +inline void fill_random_vec(std::vector &collection) { + + // Generate a vector of the right type with random values + auto rand_obj = [&]() { + return vector_aos_t{vector_aos_t::array_type::Random()}; + }; + + collection.resize(collection.capacity()); + std::generate(collection.begin(), collection.end(), rand_obj); +} + +/// Fill a @c Vc::SimdArray based transform3 with random values +template +inline void fill_random_trf(std::vector &collection) { + // Generate a random, but valid affine transformation + auto rand_obj = []() { + using vector_t = typename transform3_t::vector3; + vector_t x_axis, z_axis, t; + + x_axis = vector_t{vector_t::array_type::Random()}; + x_axis = vector::normalize(x_axis); + + z_axis = vector_t{vector_t::array_type::Random()}; + z_axis = vector::normalize(z_axis); + + t = vector_t{vector_t::array_type::Random()}; + t = vector::normalize(t); + + // Gram-Schmidt projection + typename transform3_t::scalar_type coeff = + vector::dot(x_axis, z_axis) / getter::norm(x_axis); + z_axis = x_axis - coeff * z_axis; + + return transform3_t{t, x_axis, vector::normalize(z_axis)}; + }; + + collection.resize(collection.capacity()); + std::generate(collection.begin(), collection.end(), rand_obj); +} + +} // namespace algebra diff --git a/benchmarks/vc_aos/vc_aos_getter.cpp b/benchmarks/vc_aos/vc_aos_getter.cpp new file mode 100644 index 00000000..f27bca7d --- /dev/null +++ b/benchmarks/vc_aos/vc_aos_getter.cpp @@ -0,0 +1,65 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2024-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s) +#include "algebra/vc_aos.hpp" +#include "benchmark/common/benchmark_getter.hpp" +#include "benchmark/common/register_benchmark.hpp" +#include "benchmark/vc_aos/data_generator.hpp" + +// Benchmark include +#include + +// System include(s) +#include + +using namespace algebra; + +/// Run vector benchmarks +int main(int argc, char** argv) { + + // + // Prepare benchmarks + // + algebra::benchmark_base::configuration cfg{}; + cfg.n_samples(100000); + + using phi_f_t = vector_unaryOP_bm; + using theta_f_t = vector_unaryOP_bm; + using perp_f_t = vector_unaryOP_bm; + using norm_f_t = vector_unaryOP_bm; + using eta_f_t = vector_unaryOP_bm; + + using phi_d_t = vector_unaryOP_bm; + using theta_d_t = vector_unaryOP_bm; + using perp_d_t = vector_unaryOP_bm; + using norm_d_t = vector_unaryOP_bm; + using eta_d_t = vector_unaryOP_bm; + + std::cout << "-------------------------------------------\n" + << "Algebra-Plugins 'getter' benchmark (Vc AoS)\n" + << "-------------------------------------------\n\n" + << cfg; + + // + // Register all benchmarks + // + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); + ::benchmark::Shutdown(); +} diff --git a/benchmarks/vc_aos/vc_aos_transform3.cpp b/benchmarks/vc_aos/vc_aos_transform3.cpp new file mode 100644 index 00000000..021a2a6e --- /dev/null +++ b/benchmarks/vc_aos/vc_aos_transform3.cpp @@ -0,0 +1,45 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2024-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s) +#include "algebra/vc_aos.hpp" +#include "benchmark/common/benchmark_transform3.hpp" +#include "benchmark/common/register_benchmark.hpp" +#include "benchmark/vc_aos/data_generator.hpp" + +// Benchmark include +#include + +using namespace algebra; + +/// Run vector benchmarks +int main(int argc, char** argv) { + + // + // Prepare benchmarks + // + algebra::benchmark_base::configuration cfg{}; + cfg.n_samples(100000); + + using trf_f_t = transform3_bm>; + using trf_d_t = transform3_bm>; + + std::cout << "-------------------------------------------\n" + << "Algebra-Plugins 'transform3' benchmark (Vc AoS)\n" + << "-------------------------------------------\n\n" + << cfg; + + // + // Register all benchmarks + // + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); + ::benchmark::Shutdown(); +} diff --git a/benchmarks/vc_aos/vc_aos_vector.cpp b/benchmarks/vc_aos/vc_aos_vector.cpp new file mode 100644 index 00000000..39f0e028 --- /dev/null +++ b/benchmarks/vc_aos/vc_aos_vector.cpp @@ -0,0 +1,65 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2024-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Project include(s) +#include "algebra/vc_aos.hpp" +#include "benchmark/common/benchmark_vector.hpp" +#include "benchmark/common/register_benchmark.hpp" +#include "benchmark/vc_aos/data_generator.hpp" + +// Benchmark include +#include + +using namespace algebra; + +/// Run vector benchmarks +int main(int argc, char** argv) { + + // + // Prepare benchmarks + // + algebra::benchmark_base::configuration cfg{}; + cfg.n_samples(100000); + + using add_f_t = vector_binaryOP_bm; + using sub_f_t = vector_binaryOP_bm; + using dot_f_t = vector_binaryOP_bm; + using cross_f_t = vector_binaryOP_bm; + using normlz_f_t = + vector_unaryOP_bm; + + using add_d_t = vector_binaryOP_bm; + using sub_d_t = vector_binaryOP_bm; + using dot_d_t = vector_binaryOP_bm; + using cross_d_t = + vector_binaryOP_bm; + using normlz_d_t = + vector_unaryOP_bm; + + std::cout << "-------------------------------------------\n" + << "Algebra-Plugins 'vector' benchmark (Vc SoA)\n" + << "-------------------------------------------\n\n" + << cfg; + + // + // Register all benchmarks + // + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + algebra::register_benchmark(cfg, "_single"); + algebra::register_benchmark(cfg, "_double"); + + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); + ::benchmark::Shutdown(); +} diff --git a/benchmarks/vc_soa/include/benchmark/vc_soa/data_generator.hpp b/benchmarks/vc_soa/include/benchmark/vc_soa/data_generator.hpp index e0fdd4fe..b519a795 100644 --- a/benchmarks/vc_soa/include/benchmark/vc_soa/data_generator.hpp +++ b/benchmarks/vc_soa/include/benchmark/vc_soa/data_generator.hpp @@ -16,21 +16,6 @@ namespace algebra { -// @todo Leave for later - -/// Fill a @c Vc::SimdArray based vector with random values -/*template -inline void fill_random_vec( - std::vector, allocator_t>> - &collection) { - - using vector_t = vector3_s; - // Generate a vector of the right type with random values - auto rand_obj = [&]() { return vector_t{vector_t::array_type::Random()}; }; - - std::generate(collection.begin(), collection.end(), rand_obj); -}*/ - /// Fill a @c Vc::Vector based vector with random values template inline void fill_random_vec(std::vector &collection) { @@ -80,4 +65,4 @@ inline void fill_random_trf(std::vector &collection) { std::generate(collection.begin(), collection.end(), rand_obj); } -} // namespace algebra \ No newline at end of file +} // namespace algebra diff --git a/benchmarks/vc_soa/vc_soa_getter.cpp b/benchmarks/vc_soa/vc_soa_getter.cpp index 72c6e72f..28a2ead1 100644 --- a/benchmarks/vc_soa/vc_soa_getter.cpp +++ b/benchmarks/vc_soa/vc_soa_getter.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,6 +8,7 @@ // Project include(s) #include "algebra/vc_soa.hpp" #include "benchmark/common/benchmark_getter.hpp" +#include "benchmark/common/register_benchmark.hpp" #include "benchmark/vc_soa/data_generator.hpp" // Benchmark include @@ -21,7 +22,7 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; + constexpr std::size_t n_samples{100000}; // // Prepare benchmarks @@ -29,28 +30,26 @@ int main(int argc, char** argv) { algebra::benchmark_base::configuration cfg_s{}; // Reduce the number of samples, since a single SoA struct contains multiple // vectors - cfg_s.n_samples(n_samples / Vc::float_v::Size) - .n_warmup(static_cast(0.1 * cfg_s.n_samples())); - cfg_s.do_sleep(false); + cfg_s.n_samples(n_samples / Vc::float_v::Size); // For double precision we need more samples (less vectors per SoA) algebra::benchmark_base::configuration cfg_d{cfg_s}; - cfg_d.n_samples(n_samples / Vc::double_v::Size) - .n_warmup(static_cast(0.1 * cfg_d.n_samples())); + cfg_d.n_samples(n_samples / Vc::double_v::Size); - vector_unaryOP_bm v_phi_s{cfg_s}; - vector_unaryOP_bm v_theta_s{cfg_s}; - vector_unaryOP_bm v_perp_s{cfg_s}; - vector_unaryOP_bm v_norm_s{cfg_s}; - vector_unaryOP_bm v_eta_s{cfg_s}; + using phi_f_t = vector_unaryOP_bm; + using theta_f_t = vector_unaryOP_bm; + using perp_f_t = vector_unaryOP_bm; + using norm_f_t = vector_unaryOP_bm; + using eta_f_t = vector_unaryOP_bm; - vector_unaryOP_bm v_phi_d{cfg_d}; - vector_unaryOP_bm v_theta_d{cfg_d}; - vector_unaryOP_bm v_perp_d{cfg_d}; - vector_unaryOP_bm v_norm_d{cfg_d}; - vector_unaryOP_bm v_eta_d{cfg_d}; + using phi_d_t = vector_unaryOP_bm; + using theta_d_t = vector_unaryOP_bm; + using perp_d_t = vector_unaryOP_bm; + using norm_d_t = vector_unaryOP_bm; + using eta_d_t = vector_unaryOP_bm; - std::cout << "Algebra-Plugins 'getter' benchmark (Vc SoA)\n" + std::cout << "-------------------------------------------\n" + << "Algebra-Plugins 'getter' benchmark (Vc SoA)\n" << "-------------------------------------------\n\n" << "(single)\n" << cfg_s << "(double)\n" @@ -59,42 +58,16 @@ int main(int argc, char** argv) { // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_phi_s.name() + "_single").c_str(), v_phi_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_phi_d.name() + "_double").c_str(), v_phi_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_theta_s.name() + "_single").c_str(), - v_theta_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_theta_d.name() + "_double").c_str(), - v_theta_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_perp_s.name() + "_single").c_str(), - v_perp_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_perp_d.name() + "_double").c_str(), - v_perp_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_norm_s.name() + "_single").c_str(), - v_norm_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_norm_d.name() + "_double").c_str(), - v_norm_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_eta_s.name() + "_single").c_str(), v_eta_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_eta_d.name() + "_double").c_str(), v_eta_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); diff --git a/benchmarks/vc_soa/vc_soa_transform3.cpp b/benchmarks/vc_soa/vc_soa_transform3.cpp index 79191685..1abe605d 100644 --- a/benchmarks/vc_soa/vc_soa_transform3.cpp +++ b/benchmarks/vc_soa/vc_soa_transform3.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,6 +8,7 @@ // Project include(s) #include "algebra/vc_soa.hpp" #include "benchmark/common/benchmark_transform3.hpp" +#include "benchmark/common/register_benchmark.hpp" #include "benchmark/vc_soa/data_generator.hpp" // Benchmark include @@ -18,7 +19,7 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; + constexpr std::size_t n_samples{100000}; // // Prepare benchmarks @@ -26,19 +27,17 @@ int main(int argc, char** argv) { algebra::benchmark_base::configuration cfg_s{}; // Reduce the number of samples, since a single SoA struct contains multiple // vectors - cfg_s.n_samples(n_samples / Vc::float_v::Size) - .n_warmup(static_cast(0.1 * cfg_s.n_samples())); - cfg_s.do_sleep(false); + cfg_s.n_samples(n_samples / Vc::float_v::Size); // For double precision we need more samples (less vectors per SoA) algebra::benchmark_base::configuration cfg_d{cfg_s}; - cfg_d.n_samples(n_samples / Vc::double_v::Size) - .n_warmup(static_cast(0.1 * cfg_d.n_samples())); + cfg_d.n_samples(n_samples / Vc::double_v::Size); - transform3_bm> v_trf_s{cfg_s}; - transform3_bm> v_trf_d{cfg_d}; + using trf_f_t = transform3_bm>; + using trf_d_t = transform3_bm>; - std::cout << "Algebra-Plugins 'transform3' benchmark (Vc SoA)\n" + std::cout << "-------------------------------------------\n" + << "Algebra-Plugins 'transform3' benchmark (Vc SoA)\n" << "-----------------------------------------------\n\n" << "(single)\n" << cfg_s << "(double)\n" @@ -47,14 +46,10 @@ int main(int argc, char** argv) { // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_trf_s.name() + "_single").c_str(), v_trf_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_trf_d.name() + "_double").c_str(), v_trf_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); ::benchmark::Shutdown(); -} \ No newline at end of file +} diff --git a/benchmarks/vc_soa/vc_soa_vector.cpp b/benchmarks/vc_soa/vc_soa_vector.cpp index ac5694a7..abdd6413 100644 --- a/benchmarks/vc_soa/vc_soa_vector.cpp +++ b/benchmarks/vc_soa/vc_soa_vector.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,6 +8,7 @@ // Project include(s) #include "algebra/vc_soa.hpp" #include "benchmark/common/benchmark_vector.hpp" +#include "benchmark/common/register_benchmark.hpp" #include "benchmark/vc_soa/data_generator.hpp" // Benchmark include @@ -18,7 +19,7 @@ using namespace algebra; /// Run vector benchmarks int main(int argc, char** argv) { - constexpr std::size_t n_samples{160000}; + constexpr std::size_t n_samples{100000}; // // Prepare benchmarks @@ -26,30 +27,29 @@ int main(int argc, char** argv) { algebra::benchmark_base::configuration cfg_s{}; // Reduce the number of samples, since a single SoA struct contains multiple // vectors - cfg_s.n_samples(n_samples / Vc::float_v::Size) - .n_warmup(static_cast(0.1 * cfg_s.n_samples())); - cfg_s.do_sleep(false); + cfg_s.n_samples(n_samples / Vc::float_v::Size); // For double precision we need more samples (less vectors per SoA) algebra::benchmark_base::configuration cfg_d{cfg_s}; - cfg_d.n_samples(n_samples / Vc::double_v::Size) - .n_warmup(static_cast(0.1 * cfg_d.n_samples())); + cfg_d.n_samples(n_samples / Vc::double_v::Size); - vector_binaryOP_bm v_add_s{cfg_s}; - vector_binaryOP_bm v_sub_s{cfg_s}; - vector_binaryOP_bm v_dot_s{cfg_s}; - vector_binaryOP_bm v_cross_s{cfg_s}; - vector_unaryOP_bm v_normalize_s{ - cfg_s}; + using add_f_t = vector_binaryOP_bm; + using sub_f_t = vector_binaryOP_bm; + using dot_f_t = vector_binaryOP_bm; + using cross_f_t = vector_binaryOP_bm; + using normlz_f_t = + vector_unaryOP_bm; - vector_binaryOP_bm v_add_d{cfg_d}; - vector_binaryOP_bm v_sub_d{cfg_d}; - vector_binaryOP_bm v_dot_d{cfg_d}; - vector_binaryOP_bm v_cross_d{cfg_d}; - vector_unaryOP_bm v_normalize_d{ - cfg_d}; + using add_d_t = vector_binaryOP_bm; + using sub_d_t = vector_binaryOP_bm; + using dot_d_t = vector_binaryOP_bm; + using cross_d_t = + vector_binaryOP_bm; + using normlz_d_t = + vector_unaryOP_bm; - std::cout << "Algebra-Plugins 'vector' benchmark (Vc SoA)\n" + std::cout << "-------------------------------------------\n" + << "Algebra-Plugins 'vector' benchmark (Vc SoA)\n" << "-------------------------------------------\n\n" << "(single)\n" << cfg_s << "(double)\n" @@ -58,42 +58,18 @@ int main(int argc, char** argv) { // // Register all benchmarks // - ::benchmark::RegisterBenchmark((v_add_s.name() + "_single").c_str(), v_add_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_add_d.name() + "_double").c_str(), v_add_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_sub_s.name() + "_single").c_str(), v_sub_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_sub_d.name() + "_double").c_str(), v_sub_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_dot_s.name() + "_single").c_str(), v_dot_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_dot_d.name() + "_double").c_str(), v_dot_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_cross_s.name() + "_single").c_str(), - v_cross_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_cross_d.name() + "_double").c_str(), - v_cross_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_normalize_s.name() + "_single").c_str(), - v_normalize_s) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); - ::benchmark::RegisterBenchmark((v_normalize_d.name() + "_double").c_str(), - v_normalize_d) - ->MeasureProcessCPUTime() - ->ThreadPerCpu(); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); + algebra::register_benchmark(cfg_s, "_single"); + algebra::register_benchmark(cfg_d, "_double"); ::benchmark::Initialize(&argc, argv); ::benchmark::RunSpecifiedBenchmarks(); ::benchmark::Shutdown(); -} \ No newline at end of file +} diff --git a/frontend/CMakeLists.txt b/frontend/CMakeLists.txt index e107071d..268ffb92 100644 --- a/frontend/CMakeLists.txt +++ b/frontend/CMakeLists.txt @@ -18,8 +18,8 @@ if( ALGEBRA_PLUGINS_INCLUDE_SMATRIX ) endif() if( ALGEBRA_PLUGINS_INCLUDE_VC ) + add_subdirectory( vc_aos ) add_subdirectory( vc_cmath ) - add_subdirectory( vc_vc ) if( NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang" ) add_subdirectory( vc_soa ) endif() diff --git a/frontend/vc_aos/CMakeLists.txt b/frontend/vc_aos/CMakeLists.txt new file mode 100644 index 00000000..e00cddff --- /dev/null +++ b/frontend/vc_aos/CMakeLists.txt @@ -0,0 +1,14 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2023 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library( algebra_vc_aos vc_aos + "include/algebra/vc_aos.hpp" ) +target_link_libraries( algebra_vc_aos + INTERFACE algebra::common algebra::vc_aos_storage algebra::cmath_math + algebra::vc_aos_math ) +algebra_test_public_headers( algebra_vc_aos + "algebra/vc_aos.hpp" ) diff --git a/frontend/vc_aos/include/algebra/vc_aos.hpp b/frontend/vc_aos/include/algebra/vc_aos.hpp new file mode 100644 index 00000000..a32c3926 --- /dev/null +++ b/frontend/vc_aos/include/algebra/vc_aos.hpp @@ -0,0 +1,133 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2020-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/math/cmath.hpp" +#include "algebra/math/vc_aos.hpp" +#include "algebra/storage/vc_aos.hpp" + +// System include(s). +#include +#include + +namespace algebra { +namespace vc_aos { + +/// @name Vc based transforms on @c algebra::vc_aos::storage_type +/// @{ + +template +using transform3 = math::transform3; + +/// @} + +} // namespace vc_aos + +namespace getter { + +/// @name Getter functions on @c algebra::vc_aos types +/// @{ + +using vc_aos::math::eta; +using vc_aos::math::norm; +using vc_aos::math::perp; +using vc_aos::math::phi; +using vc_aos::math::theta; + +/// @} + +/// @name Getter functions on @c algebra::vc_aos::matrix_type +/// @{ + +using cmath::element; + +/// Function extracting a slice from matrix44 - const +template class array_t, + typename value_t, std::size_t N, + std::enable_if_t = true> +ALGEBRA_HOST_DEVICE inline const auto& vector( + const storage::matrix44& m, + std::size_t +#ifndef NDEBUG + row +#endif // not NDEBUG + , + std::size_t col) { + + assert(row == 0); + assert(col < 4); + switch (col) { + case 0: + return m.x; + case 1: + return m.y; + case 2: + return m.z; + case 3: + return m.t; + default: +#ifndef _MSC_VER + __builtin_unreachable(); +#else + return m.x; +#endif + } +} + +/// Function extracting a slice from matrix44 - non-const +template class array_t, + typename value_t, std::size_t N, + std::enable_if_t = true> +ALGEBRA_HOST_DEVICE inline auto& vector( + storage::matrix44& m, + std::size_t +#ifndef NDEBUG + row +#endif // not NDEBUG + , + std::size_t col) { + + assert(row == 0); + assert(col < 4); + switch (col) { + case 0: + return m.x; + case 1: + return m.y; + case 2: + return m.z; + case 3: + return m.t; + default: +#ifndef _MSC_VER + __builtin_unreachable(); +#else + return m.x; +#endif + } +} + +/// @} + +} // namespace getter + +namespace vector { + +/// @name Vector functions on @c algebra::vc_aos types +/// @{ + +using vc_aos::math::cross; +using vc_aos::math::dot; +using vc_aos::math::normalize; + +/// @} + +} // namespace vector + +} // namespace algebra diff --git a/frontend/vc_cmath/CMakeLists.txt b/frontend/vc_cmath/CMakeLists.txt index caff5f73..a20065a1 100644 --- a/frontend/vc_cmath/CMakeLists.txt +++ b/frontend/vc_cmath/CMakeLists.txt @@ -8,7 +8,7 @@ algebra_add_library( algebra_vc_cmath vc_cmath "include/algebra/vc_cmath.hpp" ) target_link_libraries( algebra_vc_cmath - INTERFACE algebra::common algebra::vc_storage algebra::cmath_math - algebra::vc_math ) + INTERFACE algebra::common algebra::vc_aos_storage algebra::cmath_math + algebra::vc_aos_math ) algebra_test_public_headers( algebra_vc_cmath "algebra/vc_cmath.hpp" ) diff --git a/frontend/vc_cmath/include/algebra/vc_cmath.hpp b/frontend/vc_cmath/include/algebra/vc_cmath.hpp index 778ef946..4daac5a2 100644 --- a/frontend/vc_cmath/include/algebra/vc_cmath.hpp +++ b/frontend/vc_cmath/include/algebra/vc_cmath.hpp @@ -9,10 +9,10 @@ // Project include(s). #include "algebra/math/cmath.hpp" -#include "algebra/math/vc.hpp" -#include "algebra/storage/vc.hpp" +#include "algebra/math/vc_aos.hpp" +#include "algebra/storage/vc_aos.hpp" -/// @name Operators on @c algebra::vc types +/// @name Operators on @c algebra::vc_aos types /// @{ using algebra::cmath::operator*; @@ -24,7 +24,7 @@ using algebra::cmath::operator+; namespace algebra { namespace getter { -/// @name Getter functions on @c algebra::vc types +/// @name Getter functions on @c algebra::vc_aos types /// @{ using cmath::eta; @@ -33,27 +33,27 @@ using cmath::perp; using cmath::phi; using cmath::theta; -using vc::math::eta; -using vc::math::norm; -using vc::math::perp; -using vc::math::phi; -using vc::math::theta; +using vc_aos::math::eta; +using vc_aos::math::norm; +using vc_aos::math::perp; +using vc_aos::math::phi; +using vc_aos::math::theta; /// @| /// Function extracting a slice from the matrix used by -/// @c algebra::vc::transform3 +/// @c algebra::vc_aos::transform3 template ALGEBRA_HOST_DEVICE inline Vc::array vector( - const vc::matrix_type& m, std::size_t row, + const vc_aos::matrix_type& m, std::size_t row, std::size_t col) { return cmath::vector_getter>()(m, row, col); } -/// @name Getter functions on @c algebra::vc::matrix_type +/// @name Getter functions on @c algebra::vc_aos::matrix_type /// @{ using cmath::element; @@ -64,16 +64,16 @@ using cmath::element; namespace vector { -/// @name Vector functions on @c algebra::vc::storage_type +/// @name Vector functions on @c algebra::vc_aos::storage_type /// @{ using cmath::cross; using cmath::dot; using cmath::normalize; -using vc::math::cross; -using vc::math::dot; -using vc::math::normalize; +using vc_aos::math::cross; +using vc_aos::math::dot; +using vc_aos::math::normalize; /// @} @@ -81,13 +81,13 @@ using vc::math::normalize; namespace matrix { -using size_type = vc::size_type; +using size_type = vc_aos::size_type; template using array_type = Vc::array; template -using matrix_type = vc::matrix_type; +using matrix_type = vc_aos::matrix_type; template using element_getter = cmath::element_getter; @@ -168,7 +168,7 @@ using preset0 = } // namespace matrix -namespace vc { +namespace vc_aos { /// @name cmath based transforms on @c algebra::matrix::actor /// @{ @@ -182,6 +182,6 @@ using transform3 = cmath::transform3>; /// @} -} // namespace vc +} // namespace vc_aos } // namespace algebra diff --git a/frontend/vc_soa/CMakeLists.txt b/frontend/vc_soa/CMakeLists.txt index b6344424..d4980cca 100644 --- a/frontend/vc_soa/CMakeLists.txt +++ b/frontend/vc_soa/CMakeLists.txt @@ -9,6 +9,6 @@ algebra_add_library( algebra_vc_soa vc_soa "include/algebra/vc_soa.hpp" ) target_link_libraries( algebra_vc_soa INTERFACE algebra::common algebra::vc_soa_storage algebra::cmath_math - algebra::vc_soa_math ) + algebra::vc_soa_math algebra::vc_aos_math ) algebra_test_public_headers( algebra_vc_soa "algebra/vc_soa.hpp" ) diff --git a/frontend/vc_soa/include/algebra/vc_soa.hpp b/frontend/vc_soa/include/algebra/vc_soa.hpp index e89eb8aa..89a15ab6 100644 --- a/frontend/vc_soa/include/algebra/vc_soa.hpp +++ b/frontend/vc_soa/include/algebra/vc_soa.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2023 CERN for the benefit of the ACTS project + * (c) 2023-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,6 +8,7 @@ #pragma once // Project include(s). +#include "algebra/math/impl/vc_aos_transform3.hpp" #include "algebra/math/vc_soa.hpp" #include "algebra/storage/vc_soa.hpp" @@ -32,7 +33,7 @@ namespace vc_soa { /// @{ template -using transform3 = math::transform3; +using transform3 = algebra::vc_aos::math::transform3; /// @} @@ -66,7 +67,8 @@ using vc_soa::math::normalize; } // namespace vector -namespace matrix { +// Produces clash with matrix typedefs in other plugins +/*namespace matrix { using size_type = vc_soa::size_type; @@ -76,6 +78,6 @@ using array_type = vc_soa::storage_type; template using matrix_type = vc_soa::matrix_type; -} // namespace matrix +}*/ // namespace matrix } // namespace algebra diff --git a/frontend/vc_vc/CMakeLists.txt b/frontend/vc_vc/CMakeLists.txt deleted file mode 100644 index c2f269da..00000000 --- a/frontend/vc_vc/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Algebra plugins library, part of the ACTS project (R&D line) -# -# (c) 2021-2023 CERN for the benefit of the ACTS project -# -# Mozilla Public License Version 2.0 - -# Set up the library. -algebra_add_library( algebra_vc_vc vc_vc - "include/algebra/vc_vc.hpp" ) -target_link_libraries( algebra_vc_vc - INTERFACE algebra::common algebra::vc_storage algebra::cmath_math - algebra::vc_math ) -algebra_test_public_headers( algebra_vc_vc - "algebra/vc_vc.hpp" ) diff --git a/frontend/vc_vc/include/algebra/vc_vc.hpp b/frontend/vc_vc/include/algebra/vc_vc.hpp deleted file mode 100644 index d5d258b7..00000000 --- a/frontend/vc_vc/include/algebra/vc_vc.hpp +++ /dev/null @@ -1,232 +0,0 @@ -/** Algebra plugins library, part of the ACTS project - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "algebra/math/cmath.hpp" -#include "algebra/math/vc.hpp" -#include "algebra/storage/vc.hpp" - -// System include(s). -#include -#include - -/// @name Operators on @c algebra::vc types -/// @{ - -using algebra::cmath::operator*; -using algebra::cmath::operator-; -using algebra::cmath::operator+; - -/// @} - -namespace algebra { -namespace vc { - -/// @name Vc based transforms on @c algebra::vc::storage_type -/// @{ - -// Pull in the definitions needed by the cmath transforms, into this namespace. -using math::perp; -using math::phi; - -template -using transform3 = math::transform3, point2>; - -/// @} - -} // namespace vc - -namespace getter { - -/// @name Getter functions on @c algebra::vc types -/// @{ - -using cmath::eta; -using cmath::norm; -using cmath::perp; -using cmath::phi; -using cmath::theta; - -using vc::math::eta; -using vc::math::norm; -using vc::math::perp; -using vc::math::phi; -using vc::math::theta; - -/// @} - -/// Function extracting a slice from the matrix used by -/// @c algebra::vc::transform3 -template = true> -ALGEBRA_HOST_DEVICE inline Vc::array vector( - const vc::transform3::matrix44& m, - std::size_t -#ifndef NDEBUG - row -#endif // not NDEBUG - , - std::size_t col) { - - assert(row == 0); - assert(col < 4); - switch (col) { - case 0: - return {m.x[0], m.x[1], m.x[2]}; - case 1: - return {m.y[0], m.y[1], m.y[2]}; - case 2: - return {m.z[0], m.z[1], m.z[2]}; - case 3: - return {m.t[0], m.t[1], m.t[2]}; - default: - return {m.x[0], m.x[1], m.x[2]}; - } -} - -/// Function extracting a slice from the matrix used by -/// @c algebra::vc::transform3 -template = true> -ALGEBRA_HOST_DEVICE inline Vc::array vector( - const vc::transform3::matrix44& m, - std::size_t -#ifndef NDEBUG - row -#endif // not NDEBUG - , - std::size_t col) { - - assert(row == 0); - assert(col < 4); - switch (col) { - case 0: - return {m.x[0], m.x[1], m.x[2]}; - case 1: - return {m.y[0], m.y[1], m.y[2]}; - case 2: - return {m.z[0], m.z[1], m.z[2]}; - case 3: - return {m.t[0], m.t[1], m.t[2]}; - default: - return {m.x[0], m.x[1], m.x[2]}; - } -} - -/// @name Getter functions on @c algebra::vc::matrix_type -/// @{ - -using cmath::element; - -/// @} - -} // namespace getter - -namespace vector { - -/// @name Vector functions on @c algebra::vc types -/// @{ - -using cmath::dot; -using cmath::normalize; -using vc::math::cross; -using vc::math::dot; -using vc::math::normalize; - -/// @} - -} // namespace vector - -namespace matrix { - -using size_type = vc::size_type; - -template -using array_type = vc::storage_type; - -template -using matrix_type = vc::matrix_type; - -template -using element_getter = cmath::element_getter; - -template -using block_getter = cmath::block_getter; - -// matrix actor -template -using actor = - cmath::matrix::actor, block_getter>; - -namespace determinant { - -// determinant aggregation -template -using actor = - cmath::matrix::determinant::actor; - -// determinant::cofactor -template -using cofactor = - cmath::matrix::determinant::cofactor, Ds...>; - -// determinant::partial_pivot_lud -template -using partial_pivot_lud = cmath::matrix::determinant::partial_pivot_lud< - size_type, matrix_type, scalar_t, element_getter, Ds...>; - -// determinant::hard_coded -template -using hard_coded = - cmath::matrix::determinant::hard_coded, Ds...>; - -// preset(s) as standard option(s) for user's convenience -template -using preset0 = - actor, hard_coded>; - -} // namespace determinant - -namespace inverse { - -// inverion aggregation -template -using actor = - cmath::matrix::inverse::actor; - -// inverse::cofactor -template -using cofactor = - cmath::matrix::inverse::cofactor, Ds...>; - -// inverse::partial_pivot_lud -template -using partial_pivot_lud = - cmath::matrix::inverse::partial_pivot_lud, Ds...>; - -// inverse::hard_coded -template -using hard_coded = - cmath::matrix::inverse::hard_coded, Ds...>; - -// preset(s) as standard option(s) for user's convenience -template -using preset0 = - actor, hard_coded>; - -} // namespace inverse - -} // namespace matrix -} // namespace algebra \ No newline at end of file diff --git a/math/CMakeLists.txt b/math/CMakeLists.txt index 54ea4795..42c480ab 100644 --- a/math/CMakeLists.txt +++ b/math/CMakeLists.txt @@ -17,7 +17,7 @@ if( ALGEBRA_PLUGINS_INCLUDE_SMATRIX ) add_subdirectory( smatrix ) endif() if( ALGEBRA_PLUGINS_INCLUDE_VC ) - add_subdirectory( vc ) + add_subdirectory( vc_aos ) if( NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang" ) add_subdirectory( vc_soa ) endif() diff --git a/math/cmath/include/algebra/math/impl/cmath_getter.hpp b/math/cmath/include/algebra/math/impl/cmath_getter.hpp index 6d7b2199..ef0c31b5 100644 --- a/math/cmath/include/algebra/math/impl/cmath_getter.hpp +++ b/math/cmath/include/algebra/math/impl/cmath_getter.hpp @@ -23,7 +23,8 @@ namespace algebra::cmath { * @param v the input vector **/ template class array_t, - typename scalar_t, size_type N, std::enable_if_t= 2, bool> = true> + typename scalar_t, size_type N, + std::enable_if_t<(N >= 2) && std::is_scalar_v, bool> = true> ALGEBRA_HOST_DEVICE inline scalar_t phi( const array_t &v) noexcept { @@ -35,7 +36,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t phi( * @param v the input vector **/ template class array_t, - typename scalar_t, size_type N, std::enable_if_t= 3, bool> = true> + typename scalar_t, size_type N, + std::enable_if_t<(N >= 3) && std::is_scalar_v, bool> = true> ALGEBRA_HOST_DEVICE inline scalar_t theta( const array_t &v) noexcept { @@ -48,7 +50,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t theta( * @param v the input vector **/ template class array_t, - typename scalar_t, size_type N, std::enable_if_t= 2, bool> = true> + typename scalar_t, size_type N, + std::enable_if_t<(N >= 2) && std::is_scalar_v, bool> = true> ALGEBRA_HOST_DEVICE inline scalar_t perp( const array_t &v) noexcept { @@ -60,7 +63,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t perp( * @param v the input vector **/ template class array_t, - typename scalar_t, size_type N, std::enable_if_t = true> + typename scalar_t, size_type N, + std::enable_if_t<(N == 2) && std::is_scalar_v, bool> = true> ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t &v) { return perp(v); @@ -71,7 +75,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t &v) { * @param v the input vector **/ template class array_t, - typename scalar_t, size_type N, std::enable_if_t= 3, bool> = true> + typename scalar_t, size_type N, + std::enable_if_t<(N >= 3) && std::is_scalar_v, bool> = true> ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t &v) { return algebra::math::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); @@ -83,7 +88,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t &v) { * @param v the input vector **/ template class array_t, - typename scalar_t, size_type N, std::enable_if_t= 3, bool> = true> + typename scalar_t, size_type N, + std::enable_if_t<(N >= 3) && std::is_scalar_v, bool> = true> ALGEBRA_HOST_DEVICE inline scalar_t eta( const array_t &v) noexcept { diff --git a/math/vc/CMakeLists.txt b/math/vc/CMakeLists.txt deleted file mode 100644 index 5b5b6a6a..00000000 --- a/math/vc/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Algebra plugins library, part of the ACTS project (R&D line) -# -# (c) 2021-2023 CERN for the benefit of the ACTS project -# -# Mozilla Public License Version 2.0 - -# Set up the library. -algebra_add_library( algebra_vc_math vc_math - "include/algebra/math/vc.hpp" - "include/algebra/math/impl/vc_getter.hpp" - "include/algebra/math/impl/vc_transform3.hpp" - "include/algebra/math/impl/vc_vector.hpp" ) -target_link_libraries( algebra_vc_math - INTERFACE Vc::Vc algebra::common algebra::common_math - algebra::cmath_math ) -algebra_test_public_headers( algebra_vc_math - "algebra/math/vc.hpp" ) diff --git a/math/vc/include/algebra/math/impl/vc_getter.hpp b/math/vc/include/algebra/math/impl/vc_getter.hpp deleted file mode 100644 index 0063d225..00000000 --- a/math/vc/include/algebra/math/impl/vc_getter.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/** Algebra plugins library, part of the ACTS project - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "algebra/math/common.hpp" -#include "algebra/math/impl/vc_vector.hpp" -#include "algebra/qualifiers.hpp" - -namespace algebra::vc::math { - -/** This method retrieves phi from a vector, vector base with rows >= 2 - * - * @param v the input vector - **/ -template -ALGEBRA_HOST_DEVICE inline auto phi(const vector_type &v) noexcept { - - return algebra::math::atan2(v[1], v[0]); -} - -/** This method retrieves theta from a vector, vector base with rows >= 3 - * - * @param v the input vector - **/ -template -ALGEBRA_HOST_DEVICE inline auto theta(const vector_type &v) noexcept { - - return algebra::math::atan2(algebra::math::sqrt(v[0] * v[0] + v[1] * v[1]), - v[2]); -} - -/** This method retrieves the perpendicular magnitude of a vector with rows >= 2 - * - * @param v the input vector - **/ -template -ALGEBRA_HOST_DEVICE inline auto perp(const vector_type &v) noexcept { - - return algebra::math::sqrt(v[0] * v[0] + v[1] * v[1]); -} - -/** This method retrieves the norm of a vector, no dimension restriction - * - * @param v the input vector - **/ -template -ALGEBRA_HOST_DEVICE inline auto norm(const vector_type &v) { - - return algebra::math::sqrt(dot(v, v)); -} - -/** This method retrieves the pseudo-rapidity from a vector or vector base with - * rows >= 3 - * - * @param v the input vector - **/ -template -ALGEBRA_HOST_DEVICE inline auto eta(const vector_type &v) noexcept { - - return algebra::math::atanh(v[2] / norm(v)); -} - -} // namespace algebra::vc::math diff --git a/math/vc/include/algebra/math/impl/vc_transform3.hpp b/math/vc/include/algebra/math/impl/vc_transform3.hpp deleted file mode 100644 index eeb34a24..00000000 --- a/math/vc/include/algebra/math/impl/vc_transform3.hpp +++ /dev/null @@ -1,444 +0,0 @@ -/** Algebra plugins library, part of the ACTS project - * - * (c) 2020-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Project include(s). -#include "algebra/math/cmath.hpp" -#include "algebra/math/impl/vc_vector.hpp" -#include "algebra/qualifiers.hpp" - -// Vc include(s). -#ifdef _MSC_VER -#pragma warning(push, 0) -#endif // MSVC -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif // MSVC - -// System include(s). -#include - -namespace algebra::vc::math { - -using cmath::cross; - -namespace internal { - -/// 4x4 matrix type used by @c algebra::vc::math::transform3 -template -struct matrix44 { - - /// Equality operator between two matrices - bool operator==(const matrix44 &rhs) const { - return ((x == rhs.x).isFull() && (y == rhs.y).isFull() && - (z == rhs.z).isFull() && (t == rhs.t).isFull()); - } - - /// Data variables - Vc::SimdArray x, y, z, t; - -}; // struct matrix44 - -/// Functor used to access elements of Vc matrices -template