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 TDim, concepts::Tag TTag>
199 struct HasAsyncBufSupport<TDim, DevGenericSycl<TTag>> : std::true_type
204 template<
typename TElem,
typename TDim,
typename TIdx, concepts::Tag TTag>
205 struct AsyncBufAlloc<TElem, TDim, TIdx, DevGenericSycl<TTag>>
207 template<
bool TBlocking,
typename TExtent>
209 detail::QueueGenericSyclBase<TTag, TBlocking> queue,
210 TExtent
const& extent) -> BufGenericSycl<TElem, TDim, TIdx, TTag>
214# if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
215 if constexpr(TDim::value == 0)
216 std::cout << __func__ <<
" ewb: " <<
sizeof(TElem) <<
'\n';
217 else if constexpr(TDim::value == 1)
219 auto const width =
getWidth(extent);
221 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
222 std::cout << __func__ <<
" ew: " << width <<
" ewb: " << widthBytes <<
'\n';
224 else if constexpr(TDim::value == 2)
226 auto const width =
getWidth(extent);
229 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
230 std::cout << __func__ <<
" ew: " << width <<
" eh: " << height <<
" ewb: " << widthBytes
231 <<
" pitch: " << widthBytes <<
'\n';
233 else if constexpr(TDim::value == 3)
235 auto const width =
getWidth(extent);
237 auto const depth =
getDepth(extent);
239 auto const widthBytes = width *
static_cast<TIdx
>(
sizeof(TElem));
240 std::cout << __func__ <<
" ew: " << width <<
" eh: " << height <<
" ed: " << depth
241 <<
" ewb: " << widthBytes <<
" pitch: " << widthBytes <<
'\n';
245 sycl::queue q = queue.getNativeHandle();
246 TElem* memPtr = sycl::malloc_device<TElem>(
static_cast<std::size_t
>(
getExtentProduct(extent)), q);
247 auto deleter = [q](TElem* ptr)
mutable
249 if constexpr(TBlocking)
261 q.submit([&](sycl::handler& cgh) {
262 cgh.host_task([=]() { sycl::free(ptr, q); });
267 return BufGenericSycl<TElem, TDim, TIdx, TTag>(
getDev(queue), memPtr, std::move(deleter), extent);
272 template<concepts::Tag TTag>
273 struct HasMappedBufSupport<PlatformGenericSycl<TTag>> :
public std::true_type
278 template<concepts::Tag TTag,
typename TElem,
typename TDim,
typename TIdx>
279 struct BufAllocMapped<PlatformGenericSycl<TTag>, TElem, TDim, TIdx>
281 template<
typename TExtent>
284 PlatformGenericSycl<TTag>
const& platform,
285 TExtent
const& extent) -> BufCpu<TElem, TDim, TIdx>
291 auto ctx = platform.syclContext();
292 TElem* memPtr = sycl::malloc_host<TElem>(
static_cast<std::size_t
>(
getExtentProduct(extent)), ctx);
293 auto deleter = [ctx](TElem* ptr) { sycl::free(ptr, ctx); };
295 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_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 >