alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
stdContainer.hpp
Go to the documentation of this file.
1/* Copyright 2024 René Widera, Bernhard Manfred Gruber
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5
6#pragma once
7
8#include "alpaka/CVec.hpp"
9#include "alpaka/Vec.hpp"
10#include "alpaka/api/api.hpp"
13
14#include <array>
15#include <cstdint>
16#include <span>
17#include <vector>
18
19namespace alpaka
20{
21 namespace internal
22 {
23 template<typename T_Type, typename T_Allocator>
24 struct GetApi::Op<std::vector<T_Type, T_Allocator>>
25 {
26 inline constexpr auto operator()(auto&& stdVector) const
27 {
28 alpaka::unused(stdVector);
29 return api::Host{};
30 }
31 };
32
33 /** The Api is the Api of the caller scope */
34 template<typename T_Type, size_t T_size>
35 struct GetApi::Op<std::array<T_Type, T_size>>
36 {
37 inline constexpr auto operator()(auto&& stdArray) const
38 {
39 alpaka::unused(stdArray);
40 return thisApi();
41 }
42 };
43 } // namespace internal
44
45 namespace onHost::internal
46 {
47 template<typename T_Type, typename T_Allocator>
48 struct GetExtents::Op<std::vector<T_Type, T_Allocator>>
49 {
50 decltype(auto) operator()(auto&& stdVector) const
51 {
52 alpaka::unused(stdVector);
53 return Vec{stdVector.size()};
54 }
55 };
56
57 template<typename T_Type, size_t T_size>
58 struct GetExtents::Op<std::span<T_Type, T_size>>
59 {
60 decltype(auto) operator()(auto&& stdSpan) const
61 {
62 return Vec{stdSpan.size()};
63 }
64 };
65
66 template<typename T_Type, size_t T_size>
67 struct GetExtents::Op<std::array<T_Type, T_size>>
68 {
69 decltype(auto) operator()(auto&& stdArray) const
70 {
71 alpaka::unused(stdArray);
72 return CVec<size_t, T_size>{};
73 }
74 };
75
76 template<typename T_Type, typename T_Allocator>
77 struct GetPitches::Op<std::vector<T_Type, T_Allocator>>
78 {
79 decltype(auto) operator()(auto&& stdVector) const
80 {
81 alpaka::unused(stdVector);
82 return Vec{sizeof(T_Type)};
83 }
84 };
85
86 template<typename T_Type, size_t T_size>
87 struct GetPitches::Op<std::span<T_Type, T_size>>
88 {
89 decltype(auto) operator()(auto&& stdSpan) const
90 {
91 alpaka::unused(stdSpan);
92 return Vec{sizeof(T_Type)};
93 }
94 };
95
96 template<typename T_Type, size_t T_size>
97 struct GetPitches::Op<std::array<T_Type, T_size>>
98 {
99 decltype(auto) operator()(auto&& stdArray) const
100 {
101 alpaka::unused(stdArray);
102 return CVec<size_t, sizeof(T_Type)>{};
103 }
104 };
105 } // namespace onHost::internal
106
107 namespace trait
108 {
109 template<typename T_Type, typename T_Allocator>
110 struct GetValueType<std::vector<T_Type, T_Allocator>>
111 {
112 using type = T_Type;
113 };
114
115 template<typename T_Type, size_t T_size>
116 struct GetValueType<std::span<T_Type, T_size>>
117 {
118 using type = T_Type;
119 };
120
121 template<typename T_Type, size_t T_size>
122 struct GetValueType<std::array<T_Type, T_size>>
123 {
124 using type = T_Type;
125 };
126
127 template<typename T_Type, size_t T_size>
128 struct GetDim<std::span<T_Type, T_size>>
129 {
130 static constexpr uint32_t value = 1u;
131 };
132
133 template<typename T_Type, typename T_Allocator>
134 struct GetDim<std::vector<T_Type, T_Allocator>>
135 {
136 static constexpr uint32_t value = 1u;
137 };
138
139 template<typename T_Type, size_t T_size>
140 struct GetDim<std::array<T_Type, T_size>>
141 {
142 static constexpr uint32_t value = 1u;
143 };
144 } // namespace trait
145} // namespace alpaka
main alpaka namespace.
Definition alpaka.hpp:76
Vec< T, sizeof...(T_values), detail::CVec< T, T_values... > > CVec
A vector with compile-time known values.
Definition CVec.hpp:31
ALPAKA_FN_HOST_ACC Vec(T_1, T_Args...) -> Vec< T_1, uint32_t(sizeof...(T_Args)+1u), ArrayStorage< T_1, uint32_t(sizeof...(T_Args)+1u)> >
constexpr auto thisApi()
provides the API used during the execution of the current code path
Definition api.hpp:26
static constexpr uint32_t value
Definition trait.hpp:31
typename T::value_type type
Definition trait.hpp:46