alpaka
Abstraction Library for Parallel Kernel Acceleration
ViewStdArray.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, Jan Stephan, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 /* TODO: Once C++20 is available remove this file and replace with a generic ContiguousContainer solution based on
6  * concepts. It should be sufficient to check for the existence of Container.size() and Container.data() */
7 
8 #pragma once
9 
10 #include "alpaka/core/Common.hpp"
11 #include "alpaka/dev/DevCpu.hpp"
14 
15 #include <array>
16 
17 namespace alpaka::trait
18 {
19  //! The std::array device type trait specialization.
20  template<typename TElem, std::size_t Tsize>
21  struct DevType<std::array<TElem, Tsize>>
22  {
23  using type = DevCpu;
24  };
25 
26  //! The std::array device get trait specialization.
27  template<typename TElem, std::size_t Tsize>
28  struct GetDev<std::array<TElem, Tsize>>
29  {
30  ALPAKA_FN_HOST static auto getDev(std::array<TElem, Tsize> const& /* view */) -> DevCpu
31  {
32  // Instantiating the CPU platform here is a hack we can do internally, because we know that the CPU
33  // platform does not contain any data. But it generally does not apply.
34  return getDevByIdx(PlatformCpu{}, 0u);
35  }
36  };
37 
38  //! The std::array dimension getter trait specialization.
39  template<typename TElem, std::size_t Tsize>
40  struct DimType<std::array<TElem, Tsize>>
41  {
42  using type = DimInt<1u>;
43  };
44 
45  //! The std::array memory element type get trait specialization.
46  template<typename TElem, std::size_t Tsize>
47  struct ElemType<std::array<TElem, Tsize>>
48  {
49  using type = TElem;
50  };
51 
52  template<typename TElem, std::size_t Tsize>
53  struct GetExtents<std::array<TElem, Tsize>>
54  {
55  ALPAKA_FN_HOST constexpr auto operator()(std::array<TElem, Tsize> const& a)
57  {
58  return {std::size(a)};
59  }
60  };
61 
62  //! The std::array native pointer get trait specialization.
63  template<typename TElem, std::size_t Tsize>
64  struct GetPtrNative<std::array<TElem, Tsize>>
65  {
66  ALPAKA_FN_HOST static auto getPtrNative(std::array<TElem, Tsize> const& view) -> TElem const*
67  {
68  return std::data(view);
69  }
70 
71  ALPAKA_FN_HOST static auto getPtrNative(std::array<TElem, Tsize>& view) -> TElem*
72  {
73  return std::data(view);
74  }
75  };
76 
77  //! The std::array offset get trait specialization.
78  template<typename TElem, std::size_t Tsize>
79  struct GetOffsets<std::array<TElem, Tsize>>
80  {
81  ALPAKA_FN_HOST auto operator()(std::array<TElem, Tsize> const&)
83  {
84  return {0};
85  }
86  };
87 
88  //! The std::vector idx type trait specialization.
89  template<typename TElem, std::size_t Tsize>
90  struct IdxType<std::array<TElem, Tsize>>
91  {
92  using type = std::size_t;
93  };
94 } // namespace alpaka::trait
The CPU device handle.
Definition: DevCpu.hpp:56
A n-dimensional vector.
Definition: Vec.hpp:38
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
The accelerator traits.
typename trait::IdxType< T >::type Idx
Definition: Traits.hpp:29
ALPAKA_FN_HOST auto getDevByIdx(TPlatform const &platform, std::size_t const &devIdx) -> Dev< TPlatform >
Definition: Traits.hpp:62
std::integral_constant< std::size_t, N > DimInt
The CPU device platform.
Definition: PlatformCpu.hpp:18
The device type trait.
Definition: Traits.hpp:23
The dimension getter type trait.
Definition: Traits.hpp:14
The element type trait.
Definition: Traits.hpp:16
static ALPAKA_FN_HOST auto getDev(std::array< TElem, Tsize > const &) -> DevCpu
The device get trait.
Definition: Traits.hpp:27
constexpr ALPAKA_FN_HOST auto operator()(std::array< TElem, Tsize > const &a) -> Vec< DimInt< 1 >, Idx< std::array< TElem, Tsize >>>
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition: Traits.hpp:37
ALPAKA_FN_HOST auto operator()(std::array< TElem, Tsize > const &) -> Vec< DimInt< 1 >, Idx< std::array< TElem, Tsize >>>
The GetOffsets trait for getting the offsets of an object as an alpaka::Vec.
Definition: Traits.hpp:33
static ALPAKA_FN_HOST auto getPtrNative(std::array< TElem, Tsize > &view) -> TElem *
static ALPAKA_FN_HOST auto getPtrNative(std::array< TElem, Tsize > const &view) -> TElem const *
The native pointer get trait.
Definition: Traits.hpp:54
The idx type trait.
Definition: Traits.hpp:25