Skip to content

Commit

Permalink
Move Vc math overloads to algebra-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Nov 25, 2024
1 parent 328dd04 commit be6de46
Show file tree
Hide file tree
Showing 19 changed files with 302 additions and 89 deletions.
15 changes: 11 additions & 4 deletions common/include/algebra/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct get_algebra<T> {
template <typename U>
using simd = typename T::template simd<U>;
using size_type = typename T::size_type;
using boolean = typename T::boolean;
using value = typename T::value_type;
using scalar = typename T::scalar;
using point2D = typename T::point2D;
Expand All @@ -156,11 +157,20 @@ struct get_algebra<T> {
} // namespace traits

template <typename A>
using get_scalar_t = typename traits::get_algebra<A>::scalar;
using get_value_t = typename traits::get_algebra<A>::value;

template <typename A>
using get_boolean_t = typename traits::get_algebra<A>::boolean;

template <typename A, typename T>
using get_simd_t = typename traits::get_algebra<A>::template simd<T>;

template <typename A>
using get_size_t = typename traits::get_algebra<A>::size_type;

template <typename A>
using get_scalar_t = typename traits::get_algebra<A>::scalar;

template <typename A>
using get_point2D_t = typename traits::get_algebra<A>::point2D;

Expand All @@ -173,9 +183,6 @@ using get_vector3D_t = typename traits::get_algebra<A>::vector3D;
template <typename A>
using get_transform3D_t = typename traits::get_algebra<A>::transform3D;

template <typename A>
using get_size_t = typename traits::get_algebra<A>::size_type;

template <typename A, std::size_t R, std::size_t C>
using get_matrix_t = typename traits::get_algebra<A>::template matrix<R, C>;
/// @}
Expand Down
40 changes: 20 additions & 20 deletions frontend/eigen_generic/include/algebra/eigen_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#pragma warning(pop)
#endif // MSVC

/// Print the linear algebra types of this backend
using algebra::operator<<;

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

/// Print the linear algebra types of this backend
using algebra::operator<<;

namespace algebra {

namespace getter {
Expand Down Expand Up @@ -99,25 +99,25 @@ namespace plugin {
/// @{
template <typename V>
struct eigen_generic {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::eigen::size_type;
using transform3D = algebra::eigen::transform3<value_type>;
using point2D = algebra::eigen::point2<value_type>;
using point3D = algebra::eigen::point3<value_type>;
using vector3D = algebra::eigen::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::eigen::matrix_type<value_type, ROWS, COLS>;
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::eigen::size_type;
using transform3D = algebra::eigen::transform3<value_type>;
using point2D = algebra::eigen::point2<value_type>;
using point3D = algebra::eigen::point3<value_type>;
using vector3D = algebra::eigen::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::eigen::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin
} // namespace plugin

} // namespace algebra
2 changes: 2 additions & 0 deletions math/cmath/include/algebra/math/cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma once

// Impl include(s).
#include "algebra/math/boolean.hpp"
#include "algebra/math/common.hpp"
#include "algebra/math/impl/cmath_matrix.hpp"
#include "algebra/math/impl/cmath_operators.hpp"
#include "algebra/math/impl/cmath_vector.hpp"
2 changes: 2 additions & 0 deletions math/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
# Set up the library.
algebra_add_library(algebra_common_math common_math
# Math
"include/algebra/math/boolean.hpp"
"include/algebra/math/common.hpp")
target_link_libraries(algebra_common_math
INTERFACE algebra::common)
algebra_test_public_headers( algebra_common_math
"algebra/math/boolean.hpp"
"algebra/math/common.hpp" )
26 changes: 26 additions & 0 deletions math/common/include/algebra/math/boolean.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

namespace algebra::boolean {

/// Utilities for single booleans: default case
/// @{
constexpr bool any_of(bool b) {
return b;
}
constexpr bool all_of(bool b) {
return b;
}
constexpr bool none_of(bool b) {
return !b;
}
/// @}

} // namespace algebra::boolean
56 changes: 5 additions & 51 deletions math/common/include/algebra/math/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,22 @@

#pragma once

// Project include(s).
#include "algebra/concepts.hpp"
#include "algebra/qualifiers.hpp"

// SYCL include(s).
#if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)
#include <sycl/sycl.hpp>
#include <CL/sycl.hpp>
#endif

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

namespace algebra::math {
namespace algebra {

/// Namespace to pick up math functions from
#if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)
namespace math_ns = ::sycl;
namespace math = cl::sycl;
#else
namespace math_ns = std;
namespace math = std;
#endif // SYCL

/// Absolute value of arg
template <concepts::scalar scalar_t>
ALGEBRA_HOST_DEVICE inline auto fabs(scalar_t arg) {
return math_ns::fabs(arg);
}

/// Fused multiply add
template <concepts::scalar scalar_t>
ALGEBRA_HOST_DEVICE inline auto fma(scalar_t x, scalar_t y, scalar_t z) {
return math_ns::fma(x, y, z);
}

/// Arc tangent of y/x
template <concepts::scalar scalar_t>
ALGEBRA_HOST_DEVICE inline scalar_t atan2(scalar_t y, scalar_t x) {
return math_ns::atan2(y, x);
}

/// Square root of arg
template <concepts::scalar scalar_t>
ALGEBRA_HOST_DEVICE inline scalar_t sqrt(scalar_t arg) {
return math_ns::sqrt(arg);
}

/// Inverse hyperbolic tangent of arg
template <concepts::scalar scalar_t>
ALGEBRA_HOST_DEVICE inline scalar_t atanh(scalar_t arg) {
return math_ns::atanh(arg);
}

/// Minimum of two values
template <concepts::scalar scalar_t>
ALGEBRA_HOST_DEVICE inline scalar_t min(scalar_t a, scalar_t b) {
return math_ns::min(a, b);
}

/// Maximum of two values
template <concepts::scalar scalar_t>
ALGEBRA_HOST_DEVICE inline scalar_t max(scalar_t a, scalar_t b) {
return math_ns::max(a, b);
}

} // namespace algebra::math
} // namespace algebra
2 changes: 2 additions & 0 deletions math/eigen/include/algebra/math/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma once

// Project include(s).
#include "algebra/math/boolean.hpp"
#include "algebra/math/common.hpp"
#include "algebra/math/impl/eigen_matrix.hpp"
#include "algebra/math/impl/eigen_transform3.hpp"
#include "algebra/math/impl/eigen_vector.hpp"
Expand Down
2 changes: 2 additions & 0 deletions math/fastor/include/algebra/math/fastor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma once

// Project include(s).
#include "algebra/math/boolean.hpp"
#include "algebra/math/common.hpp"
#include "algebra/math/impl/fastor_matrix.hpp"
#include "algebra/math/impl/fastor_transform3.hpp"
#include "algebra/math/impl/fastor_vector.hpp"
2 changes: 2 additions & 0 deletions math/generic/include/algebra/math/generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma once

// Impl include(s).
#include "algebra/math/boolean.hpp"
#include "algebra/math/common.hpp"
#include "algebra/math/impl/generic_matrix.hpp"
#include "algebra/math/impl/generic_transform3.hpp"
#include "algebra/math/impl/generic_vector.hpp"
Expand Down
2 changes: 2 additions & 0 deletions math/smatrix/include/algebra/math/smatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma once

// Project include(s).
#include "algebra/math/boolean.hpp"
#include "algebra/math/common.hpp"
#include "algebra/math/impl/smatrix_matrix.hpp"
#include "algebra/math/impl/smatrix_transform3.hpp"
#include "algebra/math/impl/smatrix_vector.hpp"
2 changes: 1 addition & 1 deletion math/vc_aos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Set up the library.
algebra_add_library( algebra_vc_aos_math vc_aos_math
"include/algebra/math/vc_aos.hpp"
"include/algebra/math/impl/vc_aos_getter.hpp"
"include/algebra/math/impl/vc_aos_matrix.hpp"
"include/algebra/math/impl/vc_aos_transform3.hpp"
"include/algebra/math/impl/vc_aos_vector.hpp" )
target_link_libraries( algebra_vc_aos_math
Expand Down
2 changes: 2 additions & 0 deletions math/vc_aos/include/algebra/math/vc_aos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma once

// Project include(s).
#include "algebra/math/boolean.hpp"
#include "algebra/math/common.hpp"
#include "algebra/math/impl/vc_aos_matrix.hpp"
#include "algebra/math/impl/vc_aos_transform3.hpp"
#include "algebra/math/impl/vc_aos_vector.hpp"
3 changes: 3 additions & 0 deletions math/vc_soa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Set up the library.
algebra_add_library( algebra_vc_soa_math vc_soa_math
"include/algebra/math/vc_soa.hpp"
"include/algebra/math/impl/vc_soa_boolean.hpp"
"include/algebra/math/impl/vc_soa_math.hpp"
"include/algebra/math/impl/vc_soa_matrix.hpp"
"include/algebra/math/impl/vc_soa_vector.hpp")
target_link_libraries( algebra_vc_soa_math
INTERFACE algebra::common algebra::common_math algebra::common_storage algebra::vc_soa_storage Vc::Vc )
Expand Down
53 changes: 53 additions & 0 deletions math/vc_soa/include/algebra/math/impl/vc_soa_boolean.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s).
#include "algebra/math/boolean.hpp"

// Vc include(s).
#ifdef _MSC_VER
#pragma warning(push, 0)
#endif // MSVC
#include <Vc/Vc>
#ifdef _MSC_VER
#pragma warning(pop)
#endif // MSVC

namespace algebra::boolean_soa {

/// Boolean utilities on single values
/// @{
using algebra::boolean::all_of;
using algebra::boolean::any_of;
using algebra::boolean::none_of;
/// @}

/// Vc overloads of boolean utilities
/// @{
template <typename T>
requires Vc::Traits::is_simd_mask<T>::value
inline bool any_of(T &&mask) {
return Vc::any_of(std::forward<T>(mask));
}

template <typename T>
requires Vc::Traits::is_simd_mask<T>::value
inline bool all_of(T &&mask) {
return Vc::all_of(std::forward<T>(mask));
}

template <typename T>
requires Vc::Traits::is_simd_mask<T>::value
inline bool none_of(T &&mask) {
return Vc::none_of(std::forward<T>(mask));
}
/// @}

} // namespace algebra::boolean_soa
Loading

0 comments on commit be6de46

Please sign in to comment.