Skip to content

Commit

Permalink
Cleanup matrix actors
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Nov 15, 2024
1 parent 1a51d45 commit c7c9e73
Show file tree
Hide file tree
Showing 78 changed files with 1,824 additions and 1,887 deletions.
13 changes: 13 additions & 0 deletions benchmarks/array/array_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ int main(int argc, char** argv) {
algebra::benchmark_base::configuration cfg{};
cfg.n_samples(100000);

using mat44_transp_f_t =
matrix_unaryOP_bm<array::matrix_type<float, 4, 4>, bench_op::transpose>;
using mat44_transp_d_t =
matrix_unaryOP_bm<array::matrix_type<double, 4, 4>, bench_op::transpose>;
using mat66_transp_f_t =
matrix_unaryOP_bm<array::matrix_type<float, 6, 6>, bench_op::transpose>;
using mat66_transp_d_t =
matrix_unaryOP_bm<array::matrix_type<double, 6, 6>, bench_op::transpose>;
using mat88_transp_f_t =
matrix_unaryOP_bm<array::matrix_type<float, 8, 8>, bench_op::transpose>;
using mat88_transp_d_t =
matrix_unaryOP_bm<array::matrix_type<double, 8, 8>, bench_op::transpose>;

using mat44_add_f_t =
matrix_binaryOP_bm<array::matrix_type<float, 4, 4>, bench_op::add>;
using mat44_add_d_t =
Expand Down
55 changes: 35 additions & 20 deletions benchmarks/common/include/benchmark/common/benchmark_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,29 +182,44 @@ struct mul {
}
};

struct transpose {
inline static const std::string name{"transpose"};
template <typename matrix_t>
auto operator()(const matrix_t& a) const {
return algebra::matrix::transpose(a);
}
};

} // namespace bench_op

// Macro for registering all vector benchmarks
#define ALGEBRA_PLUGINS_REGISTER_MATRIX_BENCH(CFG) \
algebra::register_benchmark<mat44_add_f_t>(CFG, "_4x4_add_single"); \
algebra::register_benchmark<mat44_add_d_t>(CFG, "_4x4_add_double"); \
algebra::register_benchmark<mat66_add_f_t>(CFG, "_6x6_add_single"); \
algebra::register_benchmark<mat66_add_d_t>(CFG, "_6x6_add_double"); \
algebra::register_benchmark<mat88_add_f_t>(CFG, "_8x8_add_single"); \
algebra::register_benchmark<mat88_add_d_t>(CFG, "_8x8_add_double"); \
\
algebra::register_benchmark<mat44_mul_f_t>(CFG, "_4x4_mul_single"); \
algebra::register_benchmark<mat44_mul_d_t>(CFG, "_4x4_mul_double"); \
algebra::register_benchmark<mat66_mul_f_t>(CFG, "_6x6_mul_single"); \
algebra::register_benchmark<mat66_mul_d_t>(CFG, "_6x6_mul_double"); \
algebra::register_benchmark<mat88_mul_f_t>(CFG, "_8x8_mul_single"); \
algebra::register_benchmark<mat88_mul_d_t>(CFG, "_8x8_mul_double"); \
\
algebra::register_benchmark<mat44_vec_f_t>(CFG, "_4x4_vec_single"); \
algebra::register_benchmark<mat44_vec_d_t>(CFG, "_4x4_vec_double"); \
algebra::register_benchmark<mat66_vec_f_t>(CFG, "_6x6_vec_single"); \
algebra::register_benchmark<mat66_vec_d_t>(CFG, "_6x6_vec_double"); \
algebra::register_benchmark<mat88_vec_f_t>(CFG, "_8x8_vec_single"); \
#define ALGEBRA_PLUGINS_REGISTER_MATRIX_BENCH(CFG) \
algebra::register_benchmark<mat44_transp_f_t>(cfg, "_4x4_transpose_single"); \
algebra::register_benchmark<mat44_transp_d_t>(cfg, "_4x4_transpose_double"); \
algebra::register_benchmark<mat66_transp_f_t>(cfg, "_6x6_transpose_single"); \
algebra::register_benchmark<mat66_transp_d_t>(cfg, "_6x6_transpose_double"); \
algebra::register_benchmark<mat88_transp_f_t>(cfg, "_8x8_transpose_single"); \
algebra::register_benchmark<mat88_transp_d_t>(cfg, "_8x8_transpose_double"); \
\
algebra::register_benchmark<mat44_add_f_t>(CFG, "_4x4_add_single"); \
algebra::register_benchmark<mat44_add_d_t>(CFG, "_4x4_add_double"); \
algebra::register_benchmark<mat66_add_f_t>(CFG, "_6x6_add_single"); \
algebra::register_benchmark<mat66_add_d_t>(CFG, "_6x6_add_double"); \
algebra::register_benchmark<mat88_add_f_t>(CFG, "_8x8_add_single"); \
algebra::register_benchmark<mat88_add_d_t>(CFG, "_8x8_add_double"); \
\
algebra::register_benchmark<mat44_mul_f_t>(CFG, "_4x4_mul_single"); \
algebra::register_benchmark<mat44_mul_d_t>(CFG, "_4x4_mul_double"); \
algebra::register_benchmark<mat66_mul_f_t>(CFG, "_6x6_mul_single"); \
algebra::register_benchmark<mat66_mul_d_t>(CFG, "_6x6_mul_double"); \
algebra::register_benchmark<mat88_mul_f_t>(CFG, "_8x8_mul_single"); \
algebra::register_benchmark<mat88_mul_d_t>(CFG, "_8x8_mul_double"); \
\
algebra::register_benchmark<mat44_vec_f_t>(CFG, "_4x4_vec_single"); \
algebra::register_benchmark<mat44_vec_d_t>(CFG, "_4x4_vec_double"); \
algebra::register_benchmark<mat66_vec_f_t>(CFG, "_6x6_vec_single"); \
algebra::register_benchmark<mat66_vec_d_t>(CFG, "_6x6_vec_double"); \
algebra::register_benchmark<mat88_vec_f_t>(CFG, "_8x8_vec_single"); \
algebra::register_benchmark<mat88_vec_d_t>(CFG, "_8x8_vec_double");

} // namespace algebra
13 changes: 13 additions & 0 deletions benchmarks/eigen/eigen_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ int main(int argc, char** argv) {
algebra::benchmark_base::configuration cfg{};
cfg.n_samples(100000);

using mat44_transp_f_t =
matrix_unaryOP_bm<eigen::matrix_type<float, 4, 4>, bench_op::transpose>;
using mat44_transp_d_t =
matrix_unaryOP_bm<eigen::matrix_type<double, 4, 4>, bench_op::transpose>;
using mat66_transp_f_t =
matrix_unaryOP_bm<eigen::matrix_type<float, 6, 6>, bench_op::transpose>;
using mat66_transp_d_t =
matrix_unaryOP_bm<eigen::matrix_type<double, 6, 6>, bench_op::transpose>;
using mat88_transp_f_t =
matrix_unaryOP_bm<eigen::matrix_type<float, 8, 8>, bench_op::transpose>;
using mat88_transp_d_t =
matrix_unaryOP_bm<eigen::matrix_type<double, 8, 8>, bench_op::transpose>;

using mat44_add_f_t =
matrix_binaryOP_bm<eigen::matrix_type<float, 4, 4>, bench_op::add>;
using mat44_add_d_t =
Expand Down
13 changes: 13 additions & 0 deletions benchmarks/vc_aos/vc_aos_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ int main(int argc, char** argv) {
algebra::benchmark_base::configuration cfg{};
cfg.n_samples(100000);

using mat44_transp_f_t =
matrix_unaryOP_bm<vc_aos::matrix_type<float, 4, 4>, bench_op::transpose>;
using mat44_transp_d_t =
matrix_unaryOP_bm<vc_aos::matrix_type<double, 4, 4>, bench_op::transpose>;
using mat66_transp_f_t =
matrix_unaryOP_bm<vc_aos::matrix_type<float, 6, 6>, bench_op::transpose>;
using mat66_transp_d_t =
matrix_unaryOP_bm<vc_aos::matrix_type<double, 6, 6>, bench_op::transpose>;
using mat88_transp_f_t =
matrix_unaryOP_bm<vc_aos::matrix_type<float, 8, 8>, bench_op::transpose>;
using mat88_transp_d_t =
matrix_unaryOP_bm<vc_aos::matrix_type<double, 8, 8>, bench_op::transpose>;

using mat44_add_f_t =
matrix_binaryOP_bm<vc_aos::matrix_type<float, 4, 4>, bench_op::add>;
using mat44_add_d_t =
Expand Down
20 changes: 20 additions & 0 deletions benchmarks/vc_soa/vc_soa_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ int main(int argc, char** argv) {
algebra::benchmark_base::configuration cfg_d{cfg_s};
cfg_d.n_samples(n_samples / Vc::double_v::Size);

using mat44_transp_f_t =
matrix_unaryOP_bm<vc_soa::matrix_type<float, 4, 4>, bench_op::transpose>;
using mat44_transp_d_t =
matrix_unaryOP_bm<vc_soa::matrix_type<double, 4, 4>, bench_op::transpose>;
using mat66_transp_f_t =
matrix_unaryOP_bm<vc_soa::matrix_type<float, 6, 6>, bench_op::transpose>;
using mat66_transp_d_t =
matrix_unaryOP_bm<vc_soa::matrix_type<double, 6, 6>, bench_op::transpose>;
using mat88_transp_f_t =
matrix_unaryOP_bm<vc_soa::matrix_type<float, 8, 8>, bench_op::transpose>;
using mat88_transp_d_t =
matrix_unaryOP_bm<vc_soa::matrix_type<double, 8, 8>, bench_op::transpose>;

using mat44_add_f_t =
matrix_binaryOP_bm<vc_soa::matrix_type<float, 4, 4>, bench_op::add>;
using mat44_add_d_t =
Expand Down Expand Up @@ -85,6 +98,13 @@ int main(int argc, char** argv) {
//
// Register all benchmarks
//
algebra::register_benchmark<mat44_transp_f_t>(cfg_s, "_4x4_transpose_single");
algebra::register_benchmark<mat44_transp_d_t>(cfg_d, "_4x4_transpose_double");
algebra::register_benchmark<mat66_transp_f_t>(cfg_s, "_6x6_transpose_single");
algebra::register_benchmark<mat66_transp_d_t>(cfg_d, "_6x6_transpose_double");
algebra::register_benchmark<mat88_transp_f_t>(cfg_s, "_8x8_transpose_single");
algebra::register_benchmark<mat88_transp_d_t>(cfg_d, "_8x8_transpose_double");

algebra::register_benchmark<mat44_add_f_t>(cfg_s, "_4x4_add_single");
algebra::register_benchmark<mat44_add_d_t>(cfg_d, "_4x4_add_double");
algebra::register_benchmark<mat66_add_f_t>(cfg_s, "_6x6_add_single");
Expand Down
91 changes: 91 additions & 0 deletions common/include/algebra/type_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/** 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

// System include(s).
#include <algorithm>
#include <cmath>
#include <type_traits>

namespace algebra::trait {

/// Matrix traits
/// @{

/// Type of the matrix indices
/// @{
template <class M>
struct index {};

template <class M>
using index_t = typename index<M>::type;
/// @}

/// Value type that is used with the matrix (e.g. float or double precision)
/// @{
template <class M>
struct value {};

template <class M>
using value_t = typename value<M>::type;
/// @}

/// Scalar type that is used with the matrix (can be multiple values in SoA)
/// @{
template <class M>
struct scalar {
using type = value_t<M>;
};

template <class M>
using scalar_t = typename scalar<M>::type;
/// @}

/// Vector type that is compatible with the matrix
/// @{
template <class M>
struct vector {};

template <class M>
using vector_t = typename vector<M>::type;
/// @}

/// Matrix dimensions
/// @{
template <typename M>
struct dimensions {};

/// Specilization for scalar types
template <typename M>
requires std::is_fundamental_v<M> struct dimensions<M> {

using size_type = std::size_t;

static constexpr size_type rows{1};
static constexpr size_type columns{1};
};

template <class M>
inline constexpr index_t<M> rows{dimensions<M>::rows};

template <class M>
inline constexpr index_t<M> columns{dimensions<M>::columns};

template <class M>
inline constexpr index_t<M> rank{std::min(rows<M>, columns<M>)};

template <class M>
inline constexpr index_t<M> size{rows<M> * columns<M>};

template <class M>
inline constexpr bool is_square{(rows<M> == columns<M>)};
/// @}

/// @}

} // namespace algebra::trait
2 changes: 1 addition & 1 deletion extern/vecmem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ message( STATUS "Building VecMem as part of the Algebra Plugins project" )

# Declare where to get VecMem from.
set( ALGEBRA_PLUGINS_VECMEM_SOURCE
"URL;https://github.com/acts-project/vecmem/archive/refs/tags/v1.5.0.tar.gz;URL_MD5;3cc5a3bb14b93f611513535173a6be28"
"URL;https://github.com/acts-project/vecmem/archive/refs/tags/v1.8.0.tar.gz;URL_MD5;afddf52d9568964f25062e1c887246b7"
CACHE STRING "Source for VecMem, when built as part of this project" )
mark_as_advanced( ALGEBRA_PLUGINS_VECMEM_SOURCE )

Expand Down
108 changes: 18 additions & 90 deletions frontend/array_cmath/include/algebra/array_cmath.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Algebra plugins library, part of the ACTS project
*
* (c) 2020-2022 CERN for the benefit of the ACTS project
* (c) 2020-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -70,103 +70,31 @@ using cmath::normalize;

namespace matrix {

using size_type = array::size_type;

template <typename T, size_type N>
using array_type = array::storage_type<T, N>;

template <typename T, size_type ROWS, size_type COLS>
using matrix_type = array::matrix_type<T, ROWS, COLS>;

template <typename scalar_t>
using element_getter = cmath::element_getter<size_type, array_type, scalar_t>;

template <typename scalar_t>
using block_getter = cmath::block_getter<size_type, array_type, scalar_t>;

// matrix actor
template <typename scalar_t, typename determinant_actor_t,
typename inverse_actor_t>
using actor =
cmath::matrix::actor<size_type, array_type, matrix_type, scalar_t,
determinant_actor_t, inverse_actor_t,
element_getter<scalar_t>, block_getter<scalar_t>>;

namespace determinant {

// determinant aggregation
template <typename scalar_t, class... As>
using actor =
cmath::matrix::determinant::actor<size_type, matrix_type, scalar_t, As...>;

// determinant::cofactor
template <typename scalar_t, size_type... Ds>
using cofactor =
cmath::matrix::determinant::cofactor<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;

// determinant::partial_pivot_lud
template <typename scalar_t, size_type... Ds>
using partial_pivot_lud = cmath::matrix::determinant::partial_pivot_lud<
size_type, matrix_type, scalar_t, element_getter<scalar_t>, Ds...>;

// determinant::hard_coded
template <typename scalar_t, size_type... Ds>
using hard_coded =
cmath::matrix::determinant::hard_coded<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;

// preset(s) as standard option(s) for user's convenience
template <typename scalar_t>
using preset0 =
actor<scalar_t, partial_pivot_lud<scalar_t>, hard_coded<scalar_t, 2, 4>>;

} // namespace determinant

namespace inverse {

// inverion aggregation
template <typename scalar_t, class... As>
using actor =
cmath::matrix::inverse::actor<size_type, matrix_type, scalar_t, As...>;

// inverse::cofactor
template <typename scalar_t, size_type... Ds>
using cofactor =
cmath::matrix::inverse::cofactor<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;

// inverse::partial_pivot_lud
template <typename scalar_t, size_type... Ds>
using partial_pivot_lud =
cmath::matrix::inverse::partial_pivot_lud<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;

// inverse::hard_coded
template <typename scalar_t, size_type... Ds>
using hard_coded =
cmath::matrix::inverse::hard_coded<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;

// preset(s) as standard option(s) for user's convenience
template <typename scalar_t>
using preset0 =
actor<scalar_t, partial_pivot_lud<scalar_t>, hard_coded<scalar_t, 2, 4>>;

} // namespace inverse
using cmath::block;
using cmath::determinant;
using cmath::identity;
using cmath::inverse;
using cmath::set_block;
using cmath::set_identity;
using cmath::set_zero;
using cmath::transpose;
using cmath::zero;

} // namespace matrix

namespace array {

/// @name cmath based transforms on @c algebra::matrix::actor
template <typename scalar_t>
using element_getter =
cmath::element_getter<array::size_type, array::storage_type, scalar_t>;

/// @name cmath based transforms on @c algebra::array
/// @{

template <typename T>
using transform3_actor = matrix::actor<T, matrix::determinant::preset0<T>,
matrix::inverse::preset0<T>>;
template <typename T>
using transform3 = cmath::transform3<transform3_actor<T>>;
using transform3 = cmath::transform3<array::size_type, T, array::matrix_type,
array::storage_type, element_getter<T>,
cmath::block_getter>;

/// @}

Expand Down
Loading

0 comments on commit c7c9e73

Please sign in to comment.