Skip to content

Commit

Permalink
Merge pull request #118 from niermann999/ref-VcAos-plugin
Browse files Browse the repository at this point in the history
This refactors the Vc AoS plugin to use explicitly vectorizing Vc types again. Also adds it to the benchmarks and tests. Since not all functionality is implemented, yet, I split the test suite into three blocks, so that new plugins can be implemented incrementally with testing enabled. Finally, I harmonized the naming between this plugin and the new SoA plugin.

Also removes the warmup from the bencharmks, since google benchmark can be configured to do that for us.

Edit: I refactored the vc_aos::transform3 and matrix44 types, so that are shared between Vc AoS and SoA now
  • Loading branch information
niermann999 authored Aug 26, 2024
2 parents 15599ea + aca0200 commit 4bfcc95
Show file tree
Hide file tree
Showing 66 changed files with 1,642 additions and 2,099 deletions.
43 changes: 28 additions & 15 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,64 +23,77 @@ target_include_directories( algebra_bench_array INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/array/include>" )
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 )
target_include_directories( algebra_bench_eigen INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/eigen/include>" )
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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vc_aos/include>" )
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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vc_soa/include>" )
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()
78 changes: 25 additions & 53 deletions benchmarks/array/array_getter.cpp
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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 <benchmark/benchmark.h>
Expand All @@ -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<std::size_t>(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<array::vector3, float, bench_op::phi> v_phi_s{cfg};
vector_unaryOP_bm<array::vector3, float, bench_op::theta> v_theta_s{cfg};
vector_unaryOP_bm<array::vector3, float, bench_op::perp> v_perp_s{cfg};
vector_unaryOP_bm<array::vector3, float, bench_op::norm> v_norm_s{cfg};
vector_unaryOP_bm<array::vector3, float, bench_op::eta> v_eta_s{cfg};
using phi_f_t = vector_unaryOP_bm<array::vector3, float, bench_op::phi>;
using theta_f_t = vector_unaryOP_bm<array::vector3, float, bench_op::theta>;
using perp_f_t = vector_unaryOP_bm<array::vector3, float, bench_op::perp>;
using norm_f_t = vector_unaryOP_bm<array::vector3, float, bench_op::norm>;
using eta_f_t = vector_unaryOP_bm<array::vector3, float, bench_op::eta>;

vector_unaryOP_bm<array::vector3, double, bench_op::phi> v_phi_d{cfg};
vector_unaryOP_bm<array::vector3, double, bench_op::theta> v_theta_d{cfg};
vector_unaryOP_bm<array::vector3, double, bench_op::perp> v_perp_d{cfg};
vector_unaryOP_bm<array::vector3, double, bench_op::norm> v_norm_d{cfg};
vector_unaryOP_bm<array::vector3, double, bench_op::eta> v_eta_d{cfg};
using phi_d_t = vector_unaryOP_bm<array::vector3, double, bench_op::phi>;
using theta_d_t = vector_unaryOP_bm<array::vector3, double, bench_op::theta>;
using perp_d_t = vector_unaryOP_bm<array::vector3, double, bench_op::perp>;
using norm_d_t = vector_unaryOP_bm<array::vector3, double, bench_op::norm>;
using eta_d_t = vector_unaryOP_bm<array::vector3, double, bench_op::eta>;

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<phi_f_t>(cfg, "_single");
algebra::register_benchmark<phi_d_t>(cfg, "_double");
algebra::register_benchmark<theta_f_t>(cfg, "_single");
algebra::register_benchmark<theta_d_t>(cfg, "_double");
algebra::register_benchmark<perp_f_t>(cfg, "_single");
algebra::register_benchmark<perp_d_t>(cfg, "_double");
algebra::register_benchmark<norm_f_t>(cfg, "_single");
algebra::register_benchmark<norm_d_t>(cfg, "_double");
algebra::register_benchmark<eta_f_t>(cfg, "_single");
algebra::register_benchmark<eta_d_t>(cfg, "_double");

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
Expand Down
26 changes: 10 additions & 16 deletions benchmarks/array/array_transform3.cpp
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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 <benchmark/benchmark.h>
Expand All @@ -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<std::size_t>(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<array::transform3<float>> v_trf_s{cfg};
transform3_bm<array::transform3<double>> v_trf_d{cfg};
using trf_f_t = transform3_bm<array::transform3<float>>;
using trf_d_t = transform3_bm<array::transform3<double>>;

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<trf_f_t>(cfg, "_single");
algebra::register_benchmark<trf_d_t>(cfg, "_double");

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();
}
}
80 changes: 27 additions & 53 deletions benchmarks/array/array_vector.cpp
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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 <benchmark/benchmark.h>
Expand All @@ -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<std::size_t>(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<array::vector3, float, bench_op::add> v_add_s{cfg};
vector_binaryOP_bm<array::vector3, float, bench_op::sub> v_sub_s{cfg};
vector_binaryOP_bm<array::vector3, float, bench_op::dot> v_dot_s{cfg};
vector_binaryOP_bm<array::vector3, float, bench_op::cross> v_cross_s{cfg};
vector_unaryOP_bm<array::vector3, float, bench_op::normalize> v_normalize_s{
cfg};
using add_f_t = vector_binaryOP_bm<array::vector3, float, bench_op::add>;
using sub_f_t = vector_binaryOP_bm<array::vector3, float, bench_op::sub>;
using dot_f_t = vector_binaryOP_bm<array::vector3, float, bench_op::dot>;
using cross_f_t = vector_binaryOP_bm<array::vector3, float, bench_op::cross>;
using normlz_f_t =
vector_unaryOP_bm<array::vector3, float, bench_op::normalize>;

vector_binaryOP_bm<array::vector3, double, bench_op::add> v_add_d{cfg};
vector_binaryOP_bm<array::vector3, double, bench_op::sub> v_sub_d{cfg};
vector_binaryOP_bm<array::vector3, double, bench_op::dot> v_dot_d{cfg};
vector_binaryOP_bm<array::vector3, double, bench_op::cross> v_cross_d{cfg};
vector_unaryOP_bm<array::vector3, double, bench_op::normalize> v_normalize_d{
cfg};
using add_d_t = vector_binaryOP_bm<array::vector3, double, bench_op::add>;
using sub_d_t = vector_binaryOP_bm<array::vector3, double, bench_op::sub>;
using dot_d_t = vector_binaryOP_bm<array::vector3, double, bench_op::dot>;
using cross_d_t = vector_binaryOP_bm<array::vector3, double, bench_op::cross>;
using normlz_d_t =
vector_unaryOP_bm<array::vector3, double, bench_op::normalize>;

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<add_f_t>(cfg, "_single");
algebra::register_benchmark<add_d_t>(cfg, "_double");
algebra::register_benchmark<sub_f_t>(cfg, "_single");
algebra::register_benchmark<sub_d_t>(cfg, "_double");
algebra::register_benchmark<dot_f_t>(cfg, "_single");
algebra::register_benchmark<dot_d_t>(cfg, "_double");
algebra::register_benchmark<cross_f_t>(cfg, "_single");
algebra::register_benchmark<cross_d_t>(cfg, "_double");
algebra::register_benchmark<normlz_f_t>(cfg, "_single");
algebra::register_benchmark<normlz_d_t>(cfg, "_double");

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
Expand Down
Loading

0 comments on commit 4bfcc95

Please sign in to comment.