CMS 3D CMS Logo

vec.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaInterface_interface_vec_h
2 #define HeterogeneousCore_AlpakaInterface_interface_vec_h
3 
4 #include <type_traits>
5 
6 #include <alpaka/alpaka.hpp>
7 
8 namespace alpaka {
9 
11  ALPAKA_NO_HOST_ACC_WARNING
12  template <typename TDim,
13  typename TVal,
14  typename... Vecs,
15  typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
16  ALPAKA_FN_HOST_ACC constexpr auto elementwise_min(Vec<TDim, TVal> const& p, Vecs const&... qs) -> Vec<TDim, TVal> {
17  Vec<TDim, TVal> r;
18  if constexpr (TDim::value > 0) {
19  for (typename TDim::value_type i = 0; i < TDim::value; ++i)
20  r[i] = std::min({p[i], qs[i]...});
21  }
22  return r;
23  }
24 
26  ALPAKA_NO_HOST_ACC_WARNING
27  template <typename TDim,
28  typename TVal,
29  typename... Vecs,
30  typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
31  ALPAKA_FN_HOST_ACC constexpr auto elementwise_max(Vec<TDim, TVal> const& p, Vecs const&... qs) -> Vec<TDim, TVal> {
32  Vec<TDim, TVal> r;
33  if constexpr (TDim::value > 0) {
34  for (typename TDim::value_type i = 0; i < TDim::value; ++i)
35  r[i] = std::max({p[i], qs[i]...});
36  }
37  return r;
38  }
39 
40 } // namespace alpaka
41 
42 #endif // HeterogeneousCore_AlpakaInterface_interface_vec_h
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto elementwise_min(Vec< TDim, TVal > const &p, Vecs const &... qs) -> Vec< TDim, TVal >
Definition: vec.h:16
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto elementwise_max(Vec< TDim, TVal > const &p, Vecs const &... qs) -> Vec< TDim, TVal >
Definition: vec.h:31