1 #ifndef HeterogeneousCore_AlpakaInterface_interface_memory_h 2 #define HeterogeneousCore_AlpakaInterface_interface_memory_h 6 #include <alpaka/alpaka.hpp> 22 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
24 using type = alpaka::Buf<TDev, T, Dim0D, Idx>;
27 template <
typename TDev,
typename T>
29 using type = alpaka::Buf<TDev, T, Dim1D, Idx>;
32 template <
typename TDev,
typename T,
int N>
34 using type = alpaka::Buf<TDev, T, Dim1D, Idx>;
37 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
39 using type = alpaka::ViewPlainPtr<TDev, T, Dim0D, Idx>;
42 template <
typename TDev,
typename T>
44 using type = alpaka::ViewPlainPtr<TDev, T, Dim1D, Idx>;
47 template <
typename TDev,
typename T,
int N>
49 using type = alpaka::ViewPlainPtr<TDev, T, Dim1D, Idx>;
66 return alpaka::allocBuf<T, Idx>(
host(),
Scalar{});
70 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
72 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(
host(),
Vec1D{extent});
76 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
78 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(
host(),
Vec1D{std::extent_v<T>});
84 template <
typename T,
typename TPlatform>
86 using Platform = TPlatform;
87 return alpaka::allocMappedBuf<Platform, T, Idx>(
host(), platform<Platform>(),
Scalar{});
90 template <
typename T,
typename TPlatform>
91 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
93 using Platform = TPlatform;
94 return alpaka::allocMappedBuf<Platform, std::remove_extent_t<T>,
Idx>(
host(), platform<Platform>(),
Vec1D{extent});
97 template <
typename T,
typename TPlatform>
98 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_buffer<T>>
100 using Platform = TPlatform;
101 return alpaka::allocMappedBuf<Platform, std::remove_extent_t<T>,
Idx>(
102 host(), platform<Platform>(),
Vec1D{std::extent_v<T>});
108 template <
typename T,
typename TQueue>
110 TQueue
const&
queue) {
114 using Platform = alpaka::Platform<alpaka::Dev<TQueue>>;
115 return alpaka::allocMappedBuf<Platform, T, Idx>(
host(), platform<Platform>(),
Scalar{});
119 template <
typename T,
typename TQueue>
120 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_unbounded_array_v<T> and
121 not std::is_array_v<std::remove_extent_t<T>>,
125 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(
host(),
queue,
Vec1D{extent});
127 using Platform = alpaka::Platform<alpaka::Dev<TQueue>>;
128 return alpaka::allocMappedBuf<Platform, std::remove_extent_t<T>,
Idx>(
129 host(), platform<Platform>(),
Vec1D{extent});
133 template <
typename T,
typename TQueue>
134 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_bounded_array_v<T> and
135 not std::is_array_v<std::remove_extent_t<T>>,
139 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(
host(),
queue,
Vec1D{std::extent_v<T>});
141 using Platform = alpaka::Platform<alpaka::Dev<TQueue>>;
142 return alpaka::allocMappedBuf<Platform, std::remove_extent_t<T>,
Idx>(
143 host(), platform<Platform>(),
Vec1D{std::extent_v<T>});
149 template <
typename T>
152 template <
typename T>
154 return alpaka::ViewPlainPtr<DevHost, T, Dim0D, Idx>(&
data,
host(),
Scalar{});
157 template <
typename T>
159 return alpaka::ViewPlainPtr<DevHost, T, Dim1D, Idx>(
data,
host(),
Vec1D{extent});
162 template <
typename T>
163 std::enable_if_t<cms::is_unbounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_view<T>>
165 return alpaka::ViewPlainPtr<DevHost, std::remove_extent_t<T>,
Dim1D,
Idx>(
data,
host(),
Vec1D{extent});
168 template <
typename T>
169 std::enable_if_t<cms::is_bounded_array_v<T> and not std::is_array_v<std::remove_extent_t<T>>, host_view<T>>
171 return alpaka::ViewPlainPtr<DevHost, std::remove_extent_t<T>,
Dim1D,
Idx>(
data,
host(),
Vec1D{std::extent_v<T>});
176 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
179 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
184 template <
typename T,
typename TDev>
186 TDev
const& device) {
187 return alpaka::allocBuf<T, Idx>(device,
Scalar{});
190 template <
typename T,
typename TDev>
191 std::enable_if_t<alpaka::isDevice<TDev> and cms::is_unbounded_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{extent});
198 template <
typename T,
typename TDev>
199 std::enable_if_t<alpaka::isDevice<TDev> and cms::is_bounded_array_v<T> and
200 not std::is_array_v<std::remove_extent_t<T>>,
201 device_buffer<TDev, T>>
203 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(device,
Vec1D{std::extent_v<T>});
208 template <
typename T,
typename TQueue>
209 std::enable_if_t<alpaka::isQueue<TQueue> and not std::is_array_v<T>, device_buffer<alpaka::Dev<TQueue>,
T>>
215 return alpaka::allocAsyncBuf<T, Idx>(
queue,
Scalar{});
218 return alpaka::allocBuf<T, Idx>(alpaka::getDev(
queue),
Scalar{});
222 template <
typename T,
typename TQueue>
223 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_unbounded_array_v<T> and
224 not std::is_array_v<std::remove_extent_t<T>>,
225 device_buffer<alpaka::Dev<TQueue>,
T>>
228 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
queue,
Vec1D{extent});
231 return alpaka::allocAsyncBuf<std::remove_extent_t<T>,
Idx>(
queue,
Vec1D{extent});
234 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
Vec1D{extent});
238 template <
typename T,
typename TQueue>
239 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_bounded_array_v<T> and
240 not std::is_array_v<std::remove_extent_t<T>>,
241 device_buffer<alpaka::Dev<TQueue>,
T>>
244 return allocCachedBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
queue,
Vec1D{std::extent_v<T>});
247 return alpaka::allocAsyncBuf<std::remove_extent_t<T>,
Idx>(
queue,
Vec1D{std::extent_v<T>});
250 return alpaka::allocBuf<std::remove_extent_t<T>,
Idx>(alpaka::getDev(
queue),
Vec1D{std::extent_v<T>});
256 template <
typename TDev,
typename T,
typename = std::enable_if_t<alpaka::isDevice<TDev>>>
259 template <
typename T,
typename TDev>
261 TDev
const& device,
T&
data) {
262 return alpaka::ViewPlainPtr<TDev, T, Dim0D, Idx>(&
data, device,
Scalar{});
265 template <
typename T,
typename TDev>
269 return alpaka::ViewPlainPtr<TDev, T, Dim1D, Idx>(
data, device,
Vec1D{extent});
272 template <
typename T,
typename TDev>
273 std::enable_if_t<alpaka::isDevice<TDev> and cms::is_unbounded_array_v<T> and
274 not std::is_array_v<std::remove_extent_t<T>>,
275 device_view<TDev, T>>
277 return alpaka::ViewPlainPtr<TDev, std::remove_extent_t<T>,
Dim1D,
Idx>(
data, device,
Vec1D{extent});
280 template <
typename T,
typename TDev>
281 std::enable_if_t<alpaka::isDevice<TDev> and cms::is_bounded_array_v<T> and
282 not std::is_array_v<std::remove_extent_t<T>>,
283 device_view<TDev, T>>
285 return alpaka::ViewPlainPtr<TDev, std::remove_extent_t<T>,
Dim1D,
Idx>(
data, device,
Vec1D{std::extent_v<T>});
288 template <
typename T,
typename TQueue>
289 std::enable_if_t<alpaka::isQueue<TQueue> and not std::is_array_v<T>, device_view<alpaka::Dev<TQueue>,
T>>
294 template <
typename T,
typename TQueue>
301 template <
typename T,
typename TQueue>
302 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_unbounded_array_v<T> and
303 not std::is_array_v<std::remove_extent_t<T>>,
304 device_view<alpaka::Dev<TQueue>,
T>>
306 return alpaka::ViewPlainPtr<alpaka::Dev<TQueue>, std::remove_extent_t<T>,
Dim1D,
Idx>(
310 template <
typename T,
typename TQueue>
311 std::enable_if_t<alpaka::isQueue<TQueue> and cms::is_bounded_array_v<T> and
312 not std::is_array_v<std::remove_extent_t<T>>,
313 device_view<alpaka::Dev<TQueue>,
T>>
315 return alpaka::ViewPlainPtr<alpaka::Dev<TQueue>, std::remove_extent_t<T>,
Dim1D,
Idx>(
321 #endif // HeterogeneousCore_AlpakaInterface_interface_memory_h
alpaka::DimInt< 0u > Dim0D
alpaka::DimInt< 1u > Dim1D
char data[epos_bytes_allocation]