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<alpaka::isDevice<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<alpaka::isDevice<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>
105 TQueue
const&
queue) {
109 return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<TQueue>>,
T,
Idx>(
host(),
Scalar{});
113 template <
typename T,
typename TQueue>
114 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_unbounded_array_v<T> and
115 not std::is_array_v<std::remove_extent_t<T>>,
119 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(
host(),
queue,
Vec1D{extent});
121 return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<TQueue>>, std::remove_extent_t<T>,
Idx>(
host(),
126 template <
typename T,
typename TQueue>
127 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_bounded_array_v<T> and
128 not std::is_array_v<std::remove_extent_t<T>>,
132 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(
host(),
queue,
Vec1D{std::extent_v<T>});
134 return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<TQueue>>, std::remove_extent_t<T>,
Idx>(
141 template <
typename T>
144 template <
typename T>
146 return alpaka::ViewPlainPtr<DevHost, T, Dim0D, Idx>(&
data,
host(),
Scalar{});
149 template <
typename T>
151 return alpaka::ViewPlainPtr<DevHost, T, Dim1D, Idx>(
data,
host(),
Vec1D{extent});
154 template <
typename T>
155 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_view<T>>
157 return alpaka::ViewPlainPtr<DevHost, std::remove_extent_t<T>,
Dim1D,
Idx>(
data,
host(),
Vec1D{extent});
160 template <
typename T>
161 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_view<T>>
163 return alpaka::ViewPlainPtr<DevHost, std::remove_extent_t<T>,
Dim1D,
Idx>(
data,
host(),
Vec1D{std::extent_v<T>});
168 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
171 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
176 template <
typename T,
typename TDev>
178 TDev
const& device) {
179 return alpaka::allocBuf<T, Idx>(device,
Scalar{});
182 template <
typename T,
typename TDev>
183 std::enable_if_t<alpaka::isDevice<TDev> and cms::is_unbounded_array_v<T> and
184 not std::is_array_v<std::remove_extent_t<T>>,
185 device_buffer<TDev, T>>
187 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(device,
Vec1D{extent});
190 template <
typename T,
typename TDev>
191 std::enable_if_t<alpaka::isDevice<TDev> and cms::is_bounded_array_v<T> and
192 not std::is_array_v<std::remove_extent_t<T>>,
193 device_buffer<TDev, T>>
195 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(device,
Vec1D{std::extent_v<T>});
200 template <
typename T,
typename TQueue>
201 std::enable_if_t<alpaka::isQueue<TQueue> and not std::is_array_v<T>, device_buffer<alpaka::Dev<TQueue>,
T>>
207 return alpaka::allocAsyncBuf<T, Idx>(
queue,
Scalar{});
210 return alpaka::allocBuf<T, Idx>(alpaka::getDev(
queue),
Scalar{});
214 template <
typename T,
typename TQueue>
215 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_unbounded_array_v<T> and
216 not std::is_array_v<std::remove_extent_t<T>>,
217 device_buffer<alpaka::Dev<TQueue>,
T>>
220 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
queue,
Vec1D{extent});
223 return alpaka::allocAsyncBuf<std::remove_extent_t<T>,
Idx>(
queue,
Vec1D{extent});
226 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
Vec1D{extent});
230 template <
typename T,
typename TQueue>
231 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_bounded_array_v<T> and
232 not std::is_array_v<std::remove_extent_t<T>>,
233 device_buffer<alpaka::Dev<TQueue>,
T>>
236 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
queue,
Vec1D{std::extent_v<T>});
239 return alpaka::allocAsyncBuf<std::remove_extent_t<T>,
Idx>(
queue,
Vec1D{std::extent_v<T>});
242 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
Vec1D{std::extent_v<T>});
248 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
251 template <
typename T,
typename TDev>
253 return alpaka::ViewPlainPtr<TDev, T, Dim0D, Idx>(&
data, device,
Scalar{});
256 template <
typename T,
typename TDev>
258 return alpaka::ViewPlainPtr<TDev, T, Dim1D, Idx>(
data, device,
Vec1D{extent});
261 template <
typename T,
typename TDev>
262 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>>
264 return alpaka::ViewPlainPtr<TDev, std::remove_extent_t<T>,
Dim1D,
Idx>(
data, device,
Vec1D{extent});
267 template <
typename T,
typename TDev>
268 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>>
270 return alpaka::ViewPlainPtr<TDev, std::remove_extent_t<T>,
Dim1D,
Idx>(
data, device,
Vec1D{std::extent_v<T>});
275 #endif // HeterogeneousCore_AlpakaInterface_interface_memory_h
alpaka::DimInt< 1u > Dim1D
char data[epos_bytes_allocation]