11#ifdef ALPAKA_ACC_SYCL_ENABLED
16 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
17 struct BufType<DevGenericSycl<TTag>, TElem, TDim, TIdx>
19 using type = BufGenericSycl<TElem, TDim, TIdx, TTag>;
23 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
24 struct DevType<BufGenericSycl<TElem, TDim, TIdx, TTag>>
26 using type = DevGenericSycl<TTag>;
30 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
31 struct GetDev<BufGenericSycl<TElem, TDim, TIdx, TTag>>
33 ALPAKA_FN_HOST static auto getDev(BufGenericSycl<TElem, TDim, TIdx, TTag>
const& buf) -> DevGenericSycl<TTag>
35 return buf.m_spBufImpl->m_dev;
40 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
41 struct DimType<BufGenericSycl<TElem, TDim, TIdx, TTag>>
47 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
48 struct ElemType<BufGenericSycl<TElem, TDim, TIdx, TTag>>
54 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
55 struct GetExtents<BufGenericSycl<TElem, TDim, TIdx, TTag>>
57 ALPAKA_FN_HOST auto operator()(BufGenericSycl<TElem, TDim, TIdx, TTag>
const& buf)
59 return buf.m_spBufImpl->m_extentElements;
64 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
65 struct GetPtrNative<BufGenericSycl<TElem, TDim, TIdx, TTag>>
69 return buf.m_spBufImpl->m_pMem;
74 return buf.m_spBufImpl->m_pMem;
79 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
80 struct GetPtrDev<BufGenericSycl<TElem, TDim, TIdx, TTag>, DevGenericSycl<TTag>>
83 BufGenericSycl<TElem, TDim, TIdx, TTag>
const& buf,
84 DevGenericSycl<TTag>
const& dev) -> TElem
const*
88 return buf.m_spBufImpl->m_pMem;
92 throw std::runtime_error(
"The buffer is not accessible from the given device!");
97 BufGenericSycl<TElem, TDim, TIdx, TTag>& buf,
98 DevGenericSycl<TTag>
const& dev) -> TElem*
102 return buf.m_spBufImpl->m_pMem;
106 throw std::runtime_error(
"The buffer is not accessible from the given device!");
112 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
113 struct GetOffsets<BufGenericSycl<TElem, TDim, TIdx, TTag>>
115 ALPAKA_FN_HOST auto operator()(BufGenericSycl<TElem, TDim, TIdx, TTag>
const& )
const -> Vec<TDim, TIdx>
122 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
123 struct IdxType<BufGenericSycl<TElem, TDim, TIdx, TTag>>
129 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
130 struct MakeConstBuf<BufGenericSycl<TElem, TDim, TIdx, TTag>>
133 -> ConstBufGenericSycl<TElem, TDim, TIdx, TTag>
135 return ConstBufGenericSycl<TElem, TDim, TIdx, TTag>(buf);
139 -> ConstBufGenericSycl<TElem, TDim, TIdx, TTag>
141 return ConstBufGenericSycl<TElem, TDim, TIdx, TTag>(std::move(buf));
146 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
147 struct BufAlloc<TElem, TDim, TIdx, DevGenericSycl<TTag>>
149 template<
typename TExtent>
151 -> BufGenericSycl<TElem, TDim, TIdx, TTag>
155# if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
156 if constexpr(TDim::value == 0)
157 std::cout << __func__ <<
" ewb: " <<
sizeof(TElem) <<
'\n';
158 else if constexpr(TDim::value == 1)
160 auto const width =
getWidth(extent);
162 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
163 std::cout << __func__ <<
" ew: " << width <<
" ewb: " << widthBytes <<
'\n';
165 else if constexpr(TDim::value == 2)
167 auto const width =
getWidth(extent);
170 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
171 std::cout << __func__ <<
" ew: " << width <<
" eh: " << height <<
" ewb: " << widthBytes
172 <<
" pitch: " << widthBytes <<
'\n';
174 else if constexpr(TDim::value == 3)
176 auto const width =
getWidth(extent);
178 auto const depth =
getDepth(extent);
180 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
181 std::cout << __func__ <<
" ew: " << width <<
" eh: " << height <<
" ed: " << depth
182 <<
" ewb: " << widthBytes <<
" pitch: " << widthBytes <<
'\n';
186 auto const& [nativeDev, nativeContext] = dev.getNativeHandle();
187 TElem* memPtr = sycl::malloc_device<TElem>(
191 auto deleter = [ctx = nativeContext](TElem* ptr) { sycl::free(ptr, ctx); };
193 return BufGenericSycl<TElem, TDim, TIdx, TTag>(dev, memPtr, std::move(deleter), extent);
198 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag,
typename TAllocator>
199 struct BufAllocWithAllocator<TElem, TDim, TIdx, DevGenericSycl<TTag>, TAllocator>
201 template<
typename TExtent>
203 DevGenericSycl<TTag>
const& dev,
204 TExtent
const& extent,
205 TAllocator allocator) -> BufGenericSycl<TElem, TDim, TIdx, TTag>
209 std::size_t
const bytes =
static_cast<std::size_t
>(
getExtentProduct(extent)) *
sizeof(TElem);
210 void*
const memPtr = allocator.allocate(bytes,
alignof(TElem));
211 auto deleter = [alloc = std::move(allocator)](TElem* ptr)
mutable { alloc.deallocate(ptr); };
212 return BufGenericSycl<TElem, TDim, TIdx, TTag>(
214 static_cast<TElem*
>(memPtr),
221 template<
typename TDim, concepts::Tag TTag>
222 struct HasAsyncBufSupport<TDim, DevGenericSycl<TTag>> : std::true_type
227 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag,
typename TAllocator>
228 struct AsyncBufAllocWithAllocator<TElem, TDim, TIdx, DevGenericSycl<TTag>, TAllocator>
230 template<
bool TBlocking,
typename TExtent>
232 alpaka::detail::QueueGenericSyclBase<TTag, TBlocking> queue,
233 TExtent
const& extent,
234 TAllocator allocator) -> BufGenericSycl<TElem, TDim, TIdx, TTag>
238 auto const dev =
getDev(queue);
239 std::size_t
const bytes =
static_cast<std::size_t
>(
getExtentProduct(extent)) *
sizeof(TElem);
240 void*
const memPtr = allocator.allocate(bytes,
alignof(TElem));
241 auto deleter = [alloc = std::move(allocator)](TElem* ptr)
mutable { alloc.deallocate(ptr); };
242 return BufGenericSycl<TElem, TDim, TIdx, TTag>(
244 static_cast<TElem*
>(memPtr),
251 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
252 struct AsyncBufAlloc<TElem, TDim, TIdx, DevGenericSycl<TTag>>
254 template<
bool TBlocking,
typename TExtent>
256 alpaka::detail::QueueGenericSyclBase<TTag, TBlocking> queue,
257 TExtent
const& extent) -> BufGenericSycl<TElem, TDim, TIdx, TTag>
261# if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
262 if constexpr(TDim::value == 0)
263 std::cout << __func__ <<
" ewb: " <<
sizeof(TElem) <<
'\n';
264 else if constexpr(TDim::value == 1)
266 auto const width =
getWidth(extent);
268 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
269 std::cout << __func__ <<
" ew: " << width <<
" ewb: " << widthBytes <<
'\n';
271 else if constexpr(TDim::value == 2)
273 auto const width =
getWidth(extent);
276 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
277 std::cout << __func__ <<
" ew: " << width <<
" eh: " << height <<
" ewb: " << widthBytes
278 <<
" pitch: " << widthBytes <<
'\n';
280 else if constexpr(TDim::value == 3)
282 auto const width =
getWidth(extent);
284 auto const depth =
getDepth(extent);
286 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
287 std::cout << __func__ <<
" ew: " << width <<
" eh: " << height <<
" ed: " << depth
288 <<
" ewb: " << widthBytes <<
" pitch: " << widthBytes <<
'\n';
292 sycl::queue q = queue.getNativeHandle();
293 TElem* memPtr = sycl::malloc_device<TElem>(
static_cast<std::size_t
>(
getExtentProduct(extent)), q);
294 auto deleter = [q](TElem* ptr)
mutable
296 if constexpr(TBlocking)
308 q.submit([&](sycl::handler& cgh) {
309 cgh.host_task([=]() { sycl::free(ptr, q); });
314 return BufGenericSycl<TElem, TDim, TIdx, TTag>(
getDev(queue), memPtr, std::move(deleter), extent);
319 template<concepts::Tag TTag>
320 struct HasMappedBufSupport<PlatformGenericSycl<TTag>> :
public std::true_type
325 template<concepts::Tag TTag,
typename TElem,
typename TDim,
typename TIdx>
326 struct BufAllocMapped<PlatformGenericSycl<TTag>, TElem, TDim, TIdx>
328 template<
typename TExtent>
331 PlatformGenericSycl<TTag>
const& platform,
332 TExtent
const& extent) -> BufCpu<TElem, TDim, TIdx>
338 auto ctx = platform.syclContext();
339 TElem* memPtr = sycl::malloc_host<TElem>(
static_cast<std::size_t
>(
getExtentProduct(extent)), ctx);
340 auto deleter = [ctx](TElem* ptr) { sycl::free(ptr, ctx); };
342 return BufCpu<TElem, TDim, TIdx>(host, memPtr, std::move(deleter), extent);
347 template<concepts::Tag TTag,
typename TElem,
typename TDim,
typename TIdx>
348 struct BufAllocManaged<PlatformGenericSycl<TTag>, TElem, TDim, TIdx>
350 template<
typename TExtent>
353 PlatformGenericSycl<TTag>
const& platform,
354 TExtent
const& extent) -> BufCpu<TElem, TDim, TIdx>
360 auto devices = platform.syclDevices();
361 auto dev = devices.front();
362 auto ctx = platform.syclContext();
363 TElem* memPtr = sycl::malloc_shared<TElem>(
static_cast<std::size_t
>(
getExtentProduct(extent)), dev, ctx);
364 auto deleter = [ctx](TElem* ptr) { sycl::free(ptr, ctx); };
366 return BufCpu<TElem, TDim, TIdx>(host, memPtr, std::move(deleter), extent);
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto zeros() -> Vec< TDim, TVal >
Zero value constructor.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtentProduct(T const &object) -> Idx< T >
ALPAKA_FN_HOST auto allocManagedBuf(DevCpu const &host, TPlatform const &platform, TExtent const &extent=TExtent())
Allocates unified/managed memory, accessible by all devices in the given platform.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getHeight(TExtent const &extent=TExtent()) -> Idx< TExtent >
ALPAKA_FN_HOST auto makeConstBuf(TBuf const &buf)
Creates a constant buffer from the given mutable buffer.
ALPAKA_FN_HOST auto allocMappedBuf(DevCpu const &host, TPlatform const &platform, TExtent const &extent=TExtent())
Allocates pinned/mapped host memory, accessible by all devices in the given platform.
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
ALPAKA_FN_HOST auto allocBuf(TDev const &dev, TExtent const &extent=TExtent())
Allocates memory on the given device.
ALPAKA_FN_HOST auto getDev(T const &t)
ALPAKA_FN_HOST auto getPtrDev(TView const &view, TDev const &dev) -> Elem< TView > const *
Gets the pointer to the view on the given device.
ALPAKA_FN_HOST auto allocAsyncBuf(TQueue queue, TExtent const &extent=TExtent())
Allocates stream-ordered memory on the given device.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getDepth(TExtent const &extent=TExtent()) -> Idx< TExtent >
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getWidth(TExtent const &extent=TExtent()) -> Idx< TExtent >