Skip to content

Commit

Permalink
Merge pull request #127 from niermann999/feat-matrix-Vc
Browse files Browse the repository at this point in the history
feat: matrix implementation for vc
  • Loading branch information
stephenswat authored Nov 19, 2024
2 parents 5c41d4b + 71b8438 commit 9d722fa
Show file tree
Hide file tree
Showing 36 changed files with 1,627 additions and 483 deletions.
16 changes: 16 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ algebra_add_benchmark( array_transform3
"array/array_transform3.cpp"
LINK_LIBRARIES benchmark::benchmark algebra::bench_common
algebra_bench_array algebra::array_cmath )
algebra_add_benchmark( array_matrix
"array/array_matrix.cpp"
LINK_LIBRARIES benchmark::benchmark algebra::bench_common
algebra_bench_array algebra::array_cmath )

if( ALGEBRA_PLUGINS_INCLUDE_EIGEN )
add_library( algebra_bench_eigen INTERFACE )
Expand All @@ -54,6 +58,10 @@ if( ALGEBRA_PLUGINS_INCLUDE_EIGEN )
"eigen/eigen_transform3.cpp"
LINK_LIBRARIES benchmark::benchmark algebra::bench_common
algebra_bench_eigen algebra::eigen_eigen )
algebra_add_benchmark( eigen_matrix
"eigen/eigen_matrix.cpp"
LINK_LIBRARIES benchmark::benchmark algebra::bench_common
algebra_bench_eigen algebra::eigen_eigen )
endif()

if( ALGEBRA_PLUGINS_INCLUDE_VC )
Expand All @@ -75,6 +83,10 @@ if( ALGEBRA_PLUGINS_INCLUDE_VC )
"vc_aos/vc_aos_transform3.cpp"
LINK_LIBRARIES benchmark::benchmark algebra::bench_common
algebra_bench_vc_aos algebra::vc_aos )
algebra_add_benchmark( vc_aos_matrix
"vc_aos/vc_aos_matrix.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 )
Expand All @@ -95,5 +107,9 @@ if( ALGEBRA_PLUGINS_INCLUDE_VC )
"vc_soa/vc_soa_transform3.cpp"
LINK_LIBRARIES benchmark::benchmark algebra::bench_common
algebra_bench_vc_soa algebra::vc_soa )
algebra_add_benchmark( vc_soa_matrix
"vc_soa/vc_soa_matrix.cpp"
LINK_LIBRARIES benchmark::benchmark algebra::bench_common
algebra_bench_vc_soa algebra::vc_soa )
endif()
endif()
12 changes: 1 addition & 11 deletions benchmarks/array/array_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#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 Down Expand Up @@ -48,16 +47,7 @@ int main(int argc, char** argv) {
//
// Register all benchmarks
//
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");
ALGEBRA_PLUGINS_REGISTER_GETTER_BENCH(cfg)

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
Expand Down
82 changes: 82 additions & 0 deletions benchmarks/array/array_matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/** Algebra plugins library, part of the ACTS project
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Project include(s)
#include "algebra/array_cmath.hpp"
#include "benchmark/array/data_generator.hpp"
#include "benchmark/common/benchmark_matrix.hpp"

// Benchmark include
#include <benchmark/benchmark.h>

// System include(s)
#include <iostream>

using namespace algebra;

/// Run vector benchmarks
int main(int argc, char** argv) {

//
// Prepare benchmarks
//
algebra::benchmark_base::configuration cfg{};
cfg.n_samples(100000);

using mat44_add_f_t =
matrix_binaryOP_bm<array::matrix_type<float, 4, 4>, bench_op::add>;
using mat44_add_d_t =
matrix_binaryOP_bm<array::matrix_type<double, 4, 4>, bench_op::add>;
using mat66_add_f_t =
matrix_binaryOP_bm<array::matrix_type<float, 6, 6>, bench_op::add>;
using mat66_add_d_t =
matrix_binaryOP_bm<array::matrix_type<double, 6, 6>, bench_op::add>;
using mat88_add_f_t =
matrix_binaryOP_bm<array::matrix_type<float, 8, 8>, bench_op::add>;
using mat88_add_d_t =
matrix_binaryOP_bm<array::matrix_type<double, 8, 8>, bench_op::add>;

using mat44_mul_f_t =
matrix_binaryOP_bm<array::matrix_type<float, 4, 4>, bench_op::mul>;
using mat44_mul_d_t =
matrix_binaryOP_bm<array::matrix_type<double, 4, 4>, bench_op::mul>;
using mat66_mul_f_t =
matrix_binaryOP_bm<array::matrix_type<float, 6, 6>, bench_op::mul>;
using mat66_mul_d_t =
matrix_binaryOP_bm<array::matrix_type<double, 6, 6>, bench_op::mul>;
using mat88_mul_f_t =
matrix_binaryOP_bm<array::matrix_type<float, 8, 8>, bench_op::mul>;
using mat88_mul_d_t =
matrix_binaryOP_bm<array::matrix_type<double, 8, 8>, bench_op::mul>;

using mat44_vec_f_t = matrix_vector_bm<array::matrix_type<float, 4, 4>,
array::vector_type<float, 4>>;
using mat44_vec_d_t = matrix_vector_bm<array::matrix_type<double, 4, 4>,
array::vector_type<double, 4>>;
using mat66_vec_f_t = matrix_vector_bm<array::matrix_type<float, 6, 6>,
array::vector_type<float, 6>>;
using mat66_vec_d_t = matrix_vector_bm<array::matrix_type<double, 6, 6>,
array::vector_type<double, 6>>;
using mat88_vec_f_t = matrix_vector_bm<array::matrix_type<float, 8, 8>,
array::vector_type<float, 8>>;
using mat88_vec_d_t = matrix_vector_bm<array::matrix_type<double, 8, 8>,
array::vector_type<double, 8>>;

std::cout << "-----------------------------------------------\n"
<< "Algebra-Plugins 'matrix' benchmark (std::array)\n"
<< "-----------------------------------------------\n\n"
<< cfg;

//
// Register all benchmarks
//
ALGEBRA_PLUGINS_REGISTER_MATRIX_BENCH(cfg)

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();
}
12 changes: 1 addition & 11 deletions benchmarks/array/array_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#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 Down Expand Up @@ -50,16 +49,7 @@ int main(int argc, char** argv) {
//
// Register all benchmarks
//
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");
ALGEBRA_PLUGINS_REGISTER_VECTOR_BENCH(cfg)

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
Expand Down
34 changes: 30 additions & 4 deletions benchmarks/array/include/benchmark/array/data_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ inline void fill_random_vec(std::vector<vector_t> &collection) {
auto rand_obj = [&]() { return vector_t{dist(mt), dist(mt), dist(mt)}; };

collection.resize(collection.capacity());
std::generate(collection.begin(), collection.end(), rand_obj);
std::ranges::generate(collection, rand_obj);
}

/// Fill a @c Vc::Vector based transform3 with random values
/// Fill a @c std::array based transform3 with random values
template <typename transform3_t>
inline void fill_random_trf(std::vector<transform3_t> &collection) {

Expand Down Expand Up @@ -60,7 +60,33 @@ inline void fill_random_trf(std::vector<transform3_t> &collection) {
};

collection.resize(collection.capacity());
std::generate(collection.begin(), collection.end(), rand_obj);
std::ranges::generate(collection, rand_obj);
}

} // namespace algebra
/// Fill a @c std::array based matrix with random values
template <typename matrix_t>
inline void fill_random_matrix(std::vector<matrix_t> &collection) {

using scalar_t = typename matrix_t::value_type::value_type;

// Generate a random, but valid affine transformation
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<scalar_t> dist(0.f, 1.f);
auto rand_obj = [&]() {
matrix_t m;

for (std::size_t j = 0u; j < m.size(); ++j) {
for (std::size_t i = 0u; i < m[0].size(); ++i) {
m[j][i] = dist(mt);
}
}

return m;
};

collection.resize(collection.capacity());
std::ranges::generate(collection, rand_obj);
}

} // namespace algebra
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct benchmark_base {
benchmark_base() = default;

/// Construct from an externally provided configuration @param cfg
benchmark_base(configuration cfg) : m_cfg{cfg} {}
explicit benchmark_base(configuration cfg) : m_cfg{cfg} {}

/// @returns the benchmark configuration
configuration& config() { return m_cfg; }
Expand Down
14 changes: 14 additions & 0 deletions benchmarks/common/include/benchmark/common/benchmark_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// Project include(s)
#include "benchmark_vector.hpp"
#include "register_benchmark.hpp"

namespace algebra::bench_op {

Expand All @@ -29,4 +30,17 @@ ALGEBRA_PLUGINS_BENCH_GETTER(perp)
ALGEBRA_PLUGINS_BENCH_GETTER(norm)
ALGEBRA_PLUGINS_BENCH_GETTER(eta)

// Macro for registering all getter benchmarks
#define ALGEBRA_PLUGINS_REGISTER_GETTER_BENCH(CFG) \
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");

} // namespace algebra::bench_op
Loading

0 comments on commit 9d722fa

Please sign in to comment.