21 #include <type_traits>
23 #ifdef ALPAKA_ACC_SYCL_ENABLED
25 # include <sycl/sycl.hpp>
30 template<
typename TDim,
typename TViewDst,
typename TViewSrc,
typename TExtent>
31 struct TaskCopySyclBase
35 "The source and the destination view are required to have the same element type!");
36 using ExtentSize = Idx<TExtent>;
37 using DstSize = Idx<TViewDst>;
38 using SrcSize = Idx<TViewSrc>;
41 template<
typename TViewFwd>
42 TaskCopySyclBase(TViewFwd&& viewDst, TViewSrc
const& viewSrc, TExtent
const& extent)
44 , m_extentWidthBytes(m_extent.back() * static_cast<ExtentSize>(sizeof(
Elem)))
51 , m_dstMemNative(reinterpret_cast<std::uint8_t*>(
getPtrNative(viewDst)))
52 , m_srcMemNative(reinterpret_cast<std::uint8_t const*>(
getPtrNative(viewSrc)))
54 if constexpr(TDim::value > 0)
61 # if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
62 auto printDebug() const ->
void
64 std::cout << __func__ <<
" e: " << m_extent <<
" ewb: " << this->m_extentWidthBytes
65 <<
" de: " << m_dstExtent <<
" dptr: " <<
reinterpret_cast<void*
>(m_dstMemNative)
66 <<
" se: " << m_srcExtent <<
" sptr: " <<
reinterpret_cast<void const*
>(m_srcMemNative)
71 Vec<TDim, ExtentSize>
const m_extent;
72 ExtentSize
const m_extentWidthBytes;
73 # if(!defined(NDEBUG)) || (ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL)
74 Vec<TDim, DstSize>
const m_dstExtent;
75 Vec<TDim, SrcSize>
const m_srcExtent;
78 Vec<TDim, DstSize>
const m_dstPitchBytes;
79 Vec<TDim, SrcSize>
const m_srcPitchBytes;
80 std::uint8_t*
const m_dstMemNative;
81 std::uint8_t
const*
const m_srcMemNative;
82 static constexpr
auto is_sycl_task =
true;
86 template<
typename TDim,
typename TViewDst,
typename TViewSrc,
typename TExtent>
87 struct TaskCopySycl :
public TaskCopySyclBase<TDim, TViewDst, TViewSrc, TExtent>
89 using DimMin1 =
DimInt<TDim::value - 1u>;
90 using typename TaskCopySyclBase<TDim, TViewDst, TViewSrc, TExtent>::ExtentSize;
91 using typename TaskCopySyclBase<TDim, TViewDst, TViewSrc, TExtent>::DstSize;
92 using typename TaskCopySyclBase<TDim, TViewDst, TViewSrc, TExtent>::SrcSize;
94 using TaskCopySyclBase<TDim, TViewDst, TViewSrc, TExtent>::TaskCopySyclBase;
96 auto operator()(sycl::queue& queue, std::vector<sycl::event>
const& requirements)
const -> sycl::event
100 # if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
105 Vec<DimMin1, ExtentSize>
const extentWithoutInnermost(subVecBegin<DimMin1>(this->m_extent));
106 Vec<DimMin1, DstSize>
const dstPitchBytesWithoutInnermost(subVecBegin<DimMin1>(this->m_dstPitchBytes));
107 Vec<DimMin1, SrcSize>
const srcPitchBytesWithoutInnermost(subVecBegin<DimMin1>(this->m_srcPitchBytes));
110 std::vector<sycl::event> events;
111 events.reserve(
static_cast<std::size_t
>(extentWithoutInnermost.prod()));
113 if(
static_cast<std::size_t
>(this->m_extent.prod()) != 0u)
116 extentWithoutInnermost,
117 [&](Vec<DimMin1, ExtentSize>
const& idx)
119 events.push_back(queue.memcpy(
120 this->m_dstMemNative + (castVec<DstSize>(idx) * dstPitchBytesWithoutInnermost).sum(),
121 this->m_srcMemNative + (castVec<SrcSize>(idx) * srcPitchBytesWithoutInnermost).sum(),
122 static_cast<std::size_t
>(this->m_extentWidthBytes),
128 return queue.ext_oneapi_submit_barrier(events);
133 template<
typename TViewDst,
typename TViewSrc,
typename TExtent>
134 struct TaskCopySycl<
DimInt<1u>, TViewDst, TViewSrc, TExtent>
135 : TaskCopySyclBase<DimInt<1u>, TViewDst, TViewSrc, TExtent>
137 using TaskCopySyclBase<DimInt<1u>, TViewDst, TViewSrc, TExtent>::TaskCopySyclBase;
140 auto operator()(sycl::queue& queue, std::vector<sycl::event>
const& requirements)
const -> sycl::event
144 # if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
147 if(
static_cast<std::size_t
>(this->m_extent.prod()) != 0u)
150 this->m_dstMemNative,
151 this->m_srcMemNative,
152 sizeof(
Elem) *
static_cast<std::size_t
>(this->m_extent.prod()),
157 return queue.ext_oneapi_submit_barrier();
163 template<
typename TViewDst,
typename TViewSrc,
typename TExtent>
164 struct TaskCopySycl<
DimInt<0u>, TViewDst, TViewSrc, TExtent>
168 "The source and the destination view are required to have the same element type!");
172 template<
typename TViewDstFwd>
173 TaskCopySycl(TViewDstFwd&& viewDst, TViewSrc
const& viewSrc, [[maybe_unused]] TExtent
const& extent)
174 : m_dstMemNative(reinterpret_cast<void*>(
getPtrNative(viewDst)))
175 , m_srcMemNative(reinterpret_cast<void const*>(
getPtrNative(viewSrc)))
183 auto operator()(sycl::queue& queue, std::vector<sycl::event>
const& requirements)
const -> sycl::event
185 return queue.memcpy(m_dstMemNative, m_srcMemNative,
sizeof(
Elem), requirements);
188 void* m_dstMemNative;
189 void const* m_srcMemNative;
190 static constexpr
auto is_sycl_task =
true;
198 template<concepts::Tag TTag,
typename TDim>
199 struct CreateTaskMemcpy<TDim, DevGenericSycl<TTag>, DevCpu>
201 template<
typename TExtent,
typename TViewSrc,
typename TViewDstFwd>
202 static auto createTaskMemcpy(TViewDstFwd&& viewDst, TViewSrc
const& viewSrc, TExtent
const& extent)
203 -> alpaka::detail::TaskCopySycl<TDim, std::remove_reference_t<TViewDstFwd>, TViewSrc, TExtent>
207 return {std::forward<TViewDstFwd>(viewDst), viewSrc, extent};
212 template<concepts::Tag TTag,
typename TDim>
213 struct CreateTaskMemcpy<TDim, DevCpu, DevGenericSycl<TTag>>
215 template<
typename TExtent,
typename TViewSrc,
typename TViewDstFwd>
216 static auto createTaskMemcpy(TViewDstFwd&& viewDst, TViewSrc
const& viewSrc, TExtent
const& extent)
217 -> alpaka::detail::TaskCopySycl<TDim, std::remove_reference_t<TViewDstFwd>, TViewSrc, TExtent>
221 return {std::forward<TViewDstFwd>(viewDst), viewSrc, extent};
226 template<concepts::Tag TTagDst, concepts::Tag TTagSrc,
typename TDim>
227 struct CreateTaskMemcpy<TDim, DevGenericSycl<TTagDst>, DevGenericSycl<TTagSrc>>
229 template<
typename TExtent,
typename TViewSrc,
typename TViewDstFwd>
230 static auto createTaskMemcpy(TViewDstFwd&& viewDst, TViewSrc
const& viewSrc, TExtent
const& extent)
231 -> alpaka::detail::TaskCopySycl<TDim, std::remove_reference_t<TViewDstFwd>, TViewSrc, TExtent>
235 return {std::forward<TViewDstFwd>(viewDst), viewSrc, extent};
#define ALPAKA_ASSERT(...)
The assert can be explicit disabled by defining NDEBUG.
#define ALPAKA_DEBUG
Set the minimum log level if it is not defined.
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
#define ALPAKA_DEBUG_FULL_LOG_SCOPE
#define ALPAKA_DEBUG_FULL
The full debug level.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto all(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
ALPAKA_FN_HOST auto createTaskMemcpy(TViewDstFwd &&viewDst, TViewSrc const &viewSrc, TExtent const &extent)
Creates a memory copy task.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T >>
ALPAKA_FN_HOST auto getPitchesInBytes(TView const &view) -> Vec< Dim< TView >, Idx< TView >>
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
std::remove_volatile_t< typename trait::ElemType< TView >::type > Elem
The element type trait alias template to remove the ::type.
std::integral_constant< std::size_t, N > DimInt