1 #ifndef HeterogeneousCore_AlpakaInterface_interface_memory_h 2 #define HeterogeneousCore_AlpakaInterface_interface_memory_h 6 #include <alpaka/alpaka.hpp> 21 template <
typename TDev,
typename T,
typename = std::enable_if_t<cms::alpakatools::is_device_v<TDev>>>
23 using type = alpaka::Buf<TDev, T, Dim0D, Idx>;
26 template <
typename TDev,
typename T>
28 using type = alpaka::Buf<TDev, T, Dim1D, Idx>;
31 template <
typename TDev,
typename T,
int N>
33 using type = alpaka::Buf<TDev, T, Dim1D, Idx>;
36 template <
typename TDev,
typename T,
typename = std::enable_if_t<cms::alpakatools::is_device_v<TDev>>>
38 using type = alpaka::ViewPlainPtr<TDev, T, Dim0D, Idx>;
41 template <
typename TDev,
typename T>
43 using type = alpaka::ViewPlainPtr<TDev, T, Dim1D, Idx>;
46 template <
typename TDev,
typename T,
int N>
48 using type = alpaka::ViewPlainPtr<TDev, T, Dim1D, Idx>;
65 return alpaka::allocBuf<T, Idx>(
host(),
Scalar{});
69 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
71 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(
host(),
Vec1D{extent});
75 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
77 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(
host(),
Vec1D{std::extent_v<T>});
83 template <
typename T,
typename TPlatform>
85 return alpaka::allocMappedBuf<TPlatform, T, Idx>(
host(),
Scalar{});
88 template <
typename T,
typename TPlatform>
89 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
91 return alpaka::allocMappedBuf<TPlatform, std::remove_extent_t<T>,
Idx>(
host(),
Vec1D{extent});
94 template <
typename T,
typename TPlatform>
95 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
97 return alpaka::allocMappedBuf<TPlatform, std::remove_extent_t<T>,
Idx>(
host(),
Vec1D{std::extent_v<T>});
103 template <
typename T,
typename TQueue>
108 return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<TQueue>>,
T,
Idx>(
host(),
Scalar{});
112 template <
typename T,
typename TQueue>
113 std::enable_if_t<is_queue_v<TQueue> and cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>,
117 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(
host(),
queue,
Vec1D{extent});
119 return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<TQueue>>, std::remove_extent_t<T>,
Idx>(
host(),
124 template <
typename T,
typename TQueue>
125 std::enable_if_t<is_queue_v<TQueue> and cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>,
129 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(
host(),
queue,
Vec1D{std::extent_v<T>});
131 return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<TQueue>>, std::remove_extent_t<T>,
Idx>(
138 template <
typename T>
141 template <
typename T>
143 return alpaka::ViewPlainPtr<DevHost, T, Dim0D, Idx>(&
data,
host(),
Scalar{});
146 template <
typename T>
148 return alpaka::ViewPlainPtr<DevHost, T, Dim1D, Idx>(
data,
host(),
Vec1D{extent});
151 template <
typename T>
152 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_view<T>>
154 return alpaka::ViewPlainPtr<DevHost, std::remove_extent_t<T>,
Dim1D,
Idx>(
data,
host(),
Vec1D{extent});
157 template <
typename T>
158 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_view<T>>
160 return alpaka::ViewPlainPtr<DevHost, std::remove_extent_t<T>,
Dim1D,
Idx>(
data,
host(),
Vec1D{std::extent_v<T>});
165 template <
typename TDev,
typename T,
typename = std::enable_if_t<cms::alpakatools::is_device_v<TDev>>>
168 template <
typename TDev,
typename T,
typename = std::enable_if_t<cms::alpakatools::is_device_v<TDev>>>
173 template <
typename T,
typename TDev>
175 TDev
const& device) {
176 return alpaka::allocBuf<T, Idx>(device,
Scalar{});
179 template <
typename T,
typename TDev>
180 std::enable_if_t<is_device_v<TDev> and cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>,
181 device_buffer<TDev, T>>
183 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(device,
Vec1D{extent});
186 template <
typename T,
typename TDev>
187 std::enable_if_t<is_device_v<TDev> and cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>,
188 device_buffer<TDev, T>>
190 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(device,
Vec1D{std::extent_v<T>});
195 template <
typename T,
typename TQueue>
196 std::enable_if_t<is_queue_v<TQueue> and not std::is_array_v<T>, device_buffer<alpaka::Dev<TQueue>,
T>>
202 return alpaka::allocAsyncBuf<T, Idx>(
queue,
Scalar{});
205 return alpaka::allocBuf<T, Idx>(alpaka::getDev(
queue),
Scalar{});
209 template <
typename T,
typename TQueue>
210 std::enable_if_t<is_queue_v<TQueue> and cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>,
211 device_buffer<alpaka::Dev<TQueue>,
T>>
214 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
queue,
Vec1D{extent});
217 return alpaka::allocAsyncBuf<std::remove_extent_t<T>,
Idx>(
queue,
Vec1D{extent});
220 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
Vec1D{extent});
224 template <
typename T,
typename TQueue>
225 std::enable_if_t<is_queue_v<TQueue> and cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>,
226 device_buffer<alpaka::Dev<TQueue>,
T>>
229 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
queue,
Vec1D{std::extent_v<T>});
232 return alpaka::allocAsyncBuf<std::remove_extent_t<T>,
Idx>(
queue,
Vec1D{std::extent_v<T>});
235 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
Vec1D{std::extent_v<T>});
241 template <
typename TDev,
typename T,
typename = std::enable_if_t<cms::alpakatools::is_device_v<TDev>>>
244 template <
typename T,
typename TDev>
246 return alpaka::ViewPlainPtr<TDev, T, Dim0D, Idx>(&
data, device,
Scalar{});
249 template <
typename T,
typename TDev>
251 return alpaka::ViewPlainPtr<TDev, T, Dim1D, Idx>(
data, device,
Vec1D{extent});
254 template <
typename T,
typename TDev>
255 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, device_view<TDev, T>>
257 return alpaka::ViewPlainPtr<TDev, std::remove_extent_t<T>,
Dim1D,
Idx>(
data, device,
Vec1D{extent});
260 template <
typename T,
typename TDev>
261 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, device_view<TDev, T>>
263 return alpaka::ViewPlainPtr<TDev, std::remove_extent_t<T>,
Dim1D,
Idx>(
data, device,
Vec1D{std::extent_v<T>});
268 #endif // HeterogeneousCore_AlpakaInterface_interface_memory_h
alpaka::DimInt< 1u > Dim1D
char data[epos_bytes_allocation]