Skip to content

Commit

Permalink
Make AoS and SoA share the matrix44 and transform3 tpyes
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Jul 9, 2024
1 parent 7968a97 commit ee48a3b
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 538 deletions.
42 changes: 26 additions & 16 deletions frontend/vc_aos/include/algebra/vc_aos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace vc_aos {
/// @{

template <typename T>
using transform3 = math::transform3<storage_type, T, vector3<T>, point2<T>>;
using transform3 = math::transform3<storage_type, T>;

/// @}

Expand All @@ -42,11 +42,17 @@ using vc_aos::math::theta;

/// @}

/// Function extracting a slice from the matrix used by
/// @c algebra::vc_aos::transform3<float>
template <std::size_t SIZE, std::enable_if_t<SIZE <= 4, bool> = true>
ALGEBRA_HOST_DEVICE inline vc_aos::vector3<float> vector(
const vc_aos::transform3<float>::matrix44& m,
/// @name Getter functions on @c algebra::vc_aos::matrix_type
/// @{

using cmath::element;

/// Function extracting a slice from matrix44 - const
template <std::size_t SIZE, template <typename, std::size_t> class array_t,
typename value_t, std::size_t N,
std::enable_if_t<SIZE <= 4, bool> = true>
ALGEBRA_HOST_DEVICE inline const auto& vector(
const storage::matrix44<array_t, value_t, N>& m,
std::size_t
#ifndef NDEBUG
row
Expand All @@ -66,15 +72,20 @@ ALGEBRA_HOST_DEVICE inline vc_aos::vector3<float> vector(
case 3:
return m.t;
default:
#ifndef _MSC_VER
__builtin_unreachable();
#else
return m.x;
#endif
}
}

/// Function extracting a slice from the matrix used by
/// @c algebra::vc_aos::transform3<double>
template <std::size_t SIZE, std::enable_if_t<SIZE <= 4, bool> = true>
ALGEBRA_HOST_DEVICE inline vc_aos::vector3<double> vector(
const vc_aos::transform3<double>::matrix44& m,
/// Function extracting a slice from matrix44 - non-const
template <std::size_t SIZE, template <typename, std::size_t> class array_t,
typename value_t, std::size_t N,
std::enable_if_t<SIZE <= 4, bool> = true>
ALGEBRA_HOST_DEVICE inline auto& vector(
storage::matrix44<array_t, value_t, N>& m,
std::size_t
#ifndef NDEBUG
row
Expand All @@ -94,15 +105,14 @@ ALGEBRA_HOST_DEVICE inline vc_aos::vector3<double> vector(
case 3:
return m.t;
default:
#ifndef _MSC_VER
__builtin_unreachable();
#else
return m.x;
#endif
}
}

/// @name Getter functions on @c algebra::vc_aos::matrix_type
/// @{

using cmath::element;

/// @}

} // namespace getter
Expand Down
2 changes: 1 addition & 1 deletion frontend/vc_soa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
10 changes: 6 additions & 4 deletions frontend/vc_soa/include/algebra/vc_soa.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/** 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
*/

#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"

Expand All @@ -32,7 +33,7 @@ namespace vc_soa {
/// @{

template <typename T>
using transform3 = math::transform3<T>;
using transform3 = algebra::vc_aos::math::transform3<storage_type, T>;

/// @}

Expand Down Expand Up @@ -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;
Expand All @@ -76,6 +78,6 @@ using array_type = vc_soa::storage_type<T, N>;
template <typename T, size_type ROWS, size_type COLS>
using matrix_type = vc_soa::matrix_type<T, ROWS, COLS>;
} // namespace matrix
}*/ // namespace matrix

} // namespace algebra
18 changes: 12 additions & 6 deletions math/cmath/include/algebra/math/impl/cmath_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace algebra::cmath {
* @param v the input vector
**/
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type N, std::enable_if_t<N >= 2, bool> = true>
typename scalar_t, size_type N,
std::enable_if_t<(N >= 2) && std::is_scalar_v<scalar_t>, bool> = true>
ALGEBRA_HOST_DEVICE inline scalar_t phi(
const array_t<scalar_t, N> &v) noexcept {

Expand All @@ -35,7 +36,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t phi(
* @param v the input vector
**/
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type N, std::enable_if_t<N >= 3, bool> = true>
typename scalar_t, size_type N,
std::enable_if_t<(N >= 3) && std::is_scalar_v<scalar_t>, bool> = true>
ALGEBRA_HOST_DEVICE inline scalar_t theta(
const array_t<scalar_t, N> &v) noexcept {

Expand All @@ -48,7 +50,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t theta(
* @param v the input vector
**/
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type N, std::enable_if_t<N >= 2, bool> = true>
typename scalar_t, size_type N,
std::enable_if_t<(N >= 2) && std::is_scalar_v<scalar_t>, bool> = true>
ALGEBRA_HOST_DEVICE inline scalar_t perp(
const array_t<scalar_t, N> &v) noexcept {

Expand All @@ -60,7 +63,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t perp(
* @param v the input vector
**/
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type N, std::enable_if_t<N == 2, bool> = true>
typename scalar_t, size_type N,
std::enable_if_t<(N == 2) && std::is_scalar_v<scalar_t>, bool> = true>
ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t<scalar_t, N> &v) {

return perp(v);
Expand All @@ -71,7 +75,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t<scalar_t, N> &v) {
* @param v the input vector
**/
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type N, std::enable_if_t<N >= 3, bool> = true>
typename scalar_t, size_type N,
std::enable_if_t<(N >= 3) && std::is_scalar_v<scalar_t>, bool> = true>
ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t<scalar_t, N> &v) {

return algebra::math::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
Expand All @@ -83,7 +88,8 @@ ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t<scalar_t, N> &v) {
* @param v the input vector
**/
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type N, std::enable_if_t<N >= 3, bool> = true>
typename scalar_t, size_type N,
std::enable_if_t<(N >= 3) && std::is_scalar_v<scalar_t>, bool> = true>
ALGEBRA_HOST_DEVICE inline scalar_t eta(
const array_t<scalar_t, N> &v) noexcept {

Expand Down
3 changes: 1 addition & 2 deletions math/vc_aos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ algebra_add_library( algebra_vc_aos_math vc_aos_math
"include/algebra/math/impl/vc_aos_transform3.hpp"
"include/algebra/math/impl/vc_aos_vector.hpp" )
target_link_libraries( algebra_vc_aos_math
INTERFACE Vc::Vc algebra::common algebra::common_math algebra::vc_storage
algebra::cmath_math )
INTERFACE Vc::Vc algebra::common algebra::common_math algebra::vc_storage )
algebra_test_public_headers( algebra_vc_aos_math
"algebra/math/vc_aos.hpp" )
Loading

0 comments on commit ee48a3b

Please sign in to comment.