alpaka
Abstraction Library for Parallel Kernel Acceleration
Traits.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 
6 #pragma once
7 
8 #include "alpaka/core/Common.hpp"
9 #include "alpaka/dim/Traits.hpp"
10 #include "alpaka/idx/Traits.hpp"
12 
13 #include <utility>
14 
15 namespace alpaka
16 {
17  //! The vec traits.
18  namespace trait
19  {
20  //! Trait for selecting a sub-vector.
21  template<typename TVec, typename TIndexSequence, typename TSfinae = void>
23 
24  //! Trait for casting a vector.
25  template<typename TVal, typename TVec, typename TSfinae = void>
26  struct CastVec;
27 
28  //! Trait for reversing a vector.
29  template<typename TVec, typename TSfinae = void>
30  struct ReverseVec;
31 
32  //! Trait for concatenating two vectors.
33  template<typename TVecL, typename TVecR, typename TSfinae = void>
34  struct ConcatVec;
35  } // namespace trait
36 
37  //! Builds a new vector by selecting the elements of the source vector in the given order.
38  //! Repeating and swizzling elements is allowed.
39  //! \return The sub-vector consisting of the elements specified by the indices.
41  template<typename TIndexSequence, typename TVec>
42  ALPAKA_FN_HOST_ACC constexpr auto subVecFromIndices(TVec const& vec)
43  {
45  }
46 
47  //! \tparam TVec has to specialize SubVecFromIndices.
48  //! \return The sub-vector consisting of the first N elements of the source vector.
50  template<typename TSubDim, typename TVec>
51  ALPAKA_FN_HOST_ACC constexpr auto subVecBegin(TVec const& vec)
52  {
53  static_assert(
54  TSubDim::value <= Dim<TVec>::value,
55  "The sub-Vec has to be smaller (or same size) then the original Vec.");
56 
57  //! A sequence of integers from 0 to dim-1.
58  using IdxSubSequence = std::make_integer_sequence<std::size_t, TSubDim::value>;
59  return subVecFromIndices<IdxSubSequence>(vec);
60  }
61 
62  //! \tparam TVec has to specialize SubVecFromIndices.
63  //! \return The sub-vector consisting of the last N elements of the source vector.
65  template<typename TSubDim, typename TVec>
66  ALPAKA_FN_HOST_ACC constexpr auto subVecEnd(TVec const& vec)
67  {
68  static_assert(
69  TSubDim::value <= Dim<TVec>::value,
70  "The sub-Vec has to be smaller (or same size) then the original Vec.");
71 
72  constexpr std::size_t idxOffset = Dim<TVec>::value - TSubDim::value;
73 
74  //! A sequence of integers from 0 to dim-1.
76  return subVecFromIndices<IdxSubSequence>(vec);
77  }
78 
79  //! \return The casted vector.
81  template<typename TVal, typename TVec>
82  ALPAKA_FN_HOST_ACC constexpr auto castVec(TVec const& vec)
83  {
85  }
86 
87  //! \return The reverseVec vector.
89  template<typename TVec>
90  ALPAKA_FN_HOST_ACC constexpr auto reverseVec(TVec const& vec)
91  {
93  }
94 
95  //! \return The concatenated vector.
97  template<typename TVecL, typename TVecR>
98  ALPAKA_FN_HOST_ACC constexpr auto concatVec(TVecL const& vecL, TVecR const& vecR)
99  {
101  }
102 } // namespace alpaka
#define ALPAKA_FN_HOST_ACC
Definition: Common.hpp:39
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition: Common.hpp:82
typename detail::MakeIntegerSequenceHelper<(Tsize< 0),(Tsize==0), T, Tbegin, std::integral_constant< T, Tbegin+Tsize >, std::integer_sequence< T > >::type MakeIntegerSequenceOffset
The alpaka accelerator library.
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto castVec(TVec const &vec)
Definition: Traits.hpp:82
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto concatVec(TVecL const &vecL, TVecR const &vecR)
Definition: Traits.hpp:98
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto reverseVec(TVec const &vec)
Definition: Traits.hpp:90
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto subVecEnd(TVec const &vec)
Definition: Traits.hpp:66
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto subVecBegin(TVec const &vec)
Definition: Traits.hpp:51
ALPAKA_NO_HOST_ACC_WARNING constexpr ALPAKA_FN_HOST_ACC auto subVecFromIndices(TVec const &vec)
Builds a new vector by selecting the elements of the source vector in the given order....
Definition: Traits.hpp:42
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Definition: Traits.hpp:19
Trait for casting a vector.
Definition: Traits.hpp:26
Trait for concatenating two vectors.
Definition: Traits.hpp:34
Trait for reversing a vector.
Definition: Traits.hpp:30
Trait for selecting a sub-vector.
Definition: Traits.hpp:22