34 template<
typename TElem,
typename TDim,
typename TIdx>
38 constexpr auto dim = TIdx{TDim::value};
40 pitchBytes.
back() =
static_cast<TIdx
>(
sizeof(TElem));
42 for(TIdx i = TDim::value - 1; i > 0; i--)
43 pitchBytes[i - 1] = extent[i] * pitchBytes[i];
44#if ALPAKA_COMP_CLANG >= ALPAKA_VERSION_NUMBER(21, 1, 0)
45# pragma clang diagnostic push
46# pragma clang diagnostic ignored "-Wnrvo"
49#if ALPAKA_COMP_CLANG >= ALPAKA_VERSION_NUMBER(21, 1, 0)
50# pragma clang diagnostic pop
55 template<
typename TElem,
typename TDim,
typename TIdx>
61 constexpr auto dim = TIdx{TDim::value};
63 pitchBytes.
back() =
static_cast<TIdx
>(
sizeof(TElem));
67 pitchBytes[TDim::value - 2] = extent.
back() * pitchBytes.back();
69 pitchBytes[TDim::value - 2] =
static_cast<TIdx
>(
70 (
static_cast<std::size_t
>(extent.
back() * pitchBytes.back()) + pitch - 1) / pitch * pitch);
73 for(TIdx i = TDim::value - 2; i > 0; i--)
74 pitchBytes[i - 1] = extent[i] * pitchBytes[i];
75#if ALPAKA_COMP_CLANG >= ALPAKA_VERSION_NUMBER(21, 1, 0)
76# pragma clang diagnostic push
77# pragma clang diagnostic ignored "-Wnrvo"
80#if ALPAKA_COMP_CLANG >= ALPAKA_VERSION_NUMBER(21, 1, 0)
81# pragma clang diagnostic pop
91 template<
typename TView,
typename TSfinae =
void>
95 template<
typename TView,
typename TDev,
typename TSfinae =
void>
103 template<
typename TIdx,
typename TView,
typename TSfinae =
void>
110 return getPitchBytesDefault(view);
114 static auto getPitchBytesDefault(TView
const& view) -> ViewIdx
116 constexpr auto idx = TIdx::value;
118 if constexpr(idx < viewDim - 1)
120#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
121# pragma GCC diagnostic push
122# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
125#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
126# pragma GCC diagnostic pop
129 else if constexpr(idx == viewDim - 1)
139 template<
typename TView,
typename TSfinae =
void>
151 template<
typename TDim,
typename TDev,
typename TSfinae =
void>
154 template<
typename TDim,
typename TDev,
typename TSfinae =
void>
160 template<
typename TDim,
typename TDevDst,
typename TDevSrc,
typename TSfinae =
void>
164 template<
typename TDev,
typename TSfinae =
void>
168 template<
typename TDev,
typename TSfinae =
void>
176 template<
typename TView>
186 template<
typename TView>
197 template<
typename TView,
typename TDev>
208 template<
typename TView,
typename TDev>
216 template<std::
size_t T
idx,
typename TView>
219#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
220# pragma GCC diagnostic push
221# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
224#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
225# pragma GCC diagnostic pop
236 template<
typename TView>
247 template<
typename TExtent,
typename TViewFwd>
250 using TView = std::remove_reference_t<TViewFwd>;
251 static_assert(!std::is_const_v<TView>,
"The view must not be const!");
254 "The view and the extent are required to have the same dimensionality!");
256 assert((extent <=
getExtents(view)).all() &&
"The memset extent must not be larger than the view's extent!");
259 std::forward<TViewFwd>(view),
264 template<
typename TExtent,
typename TViewFwd,
typename TValue>
267 using TView = std::remove_reference_t<TViewFwd>;
268 static_assert(!std::is_const_v<TView>,
"The view must not be const!");
271 "The view and the extent are required to have the same dimensionality!");
273 assert((extent <=
getExtents(view)).all() &&
"The fill extent must not be larger than the view's extent!");
276 std::forward<TViewFwd>(view),
287 template<
typename TExtent,
typename TViewFwd,
typename TQueue>
288 ALPAKA_FN_HOST auto memset(TQueue& queue, TViewFwd&& view, std::uint8_t
const&
byte, TExtent
const& extent) ->
void
298 template<
typename TViewFwd,
typename TQueue>
304 template<
typename TViewFwd,
typename TValue,
typename TQueue>
310 template<
typename TExtent,
typename TViewFwd,
typename TValue,
typename TQueue>
311 ALPAKA_FN_HOST auto fill(TQueue& queue, TViewFwd&& view, TValue
const& value, TExtent
const& extent) ->
void
321 template<
typename TExtent,
typename TViewSrc,
typename TViewDstFwd>
324 using TViewDst = std::remove_reference_t<TViewDstFwd>;
328 static_assert(!std::is_const_v<TViewDst>,
"The destination view must not be const!");
329 static_assert(!std::is_const_v<DstElem>,
"The destination view's element type must not be const!");
332 "The source and the destination view must have the same dimensionality!");
335 "The destination view and the extent must have the same dimensionality!");
337 std::is_same_v<DstElem, std::remove_const_t<SrcElem>>,
338 "The source and destination view must have the same element type!");
342 [[maybe_unused]]
auto const extents =
getExtents(extent);
343 using SrcCommon [[maybe_unused]] = std::common_type_t<Idx<TExtent>,
Idx<TViewSrc>>;
344 using DstCommon [[maybe_unused]] = std::common_type_t<Idx<TExtent>,
Idx<TViewDst>>;
347 &&
"The memcpy extent must not be larger than the source view's extent!");
350 &&
"The memcpy extent must not be larger than the destination view's extent!");
353 std::forward<TViewDstFwd>(viewDst),
365 template<
typename TExtent,
typename TViewSrc,
typename TViewDstFwd,
typename TQueue>
366 ALPAKA_FN_HOST auto memcpy(TQueue& queue, TViewDstFwd&& viewDst, TViewSrc
const& viewSrc, TExtent
const& extent)
378 template<
typename TViewSrc,
typename TViewDstFwd,
typename TQueue>
392 template<
typename TDim,
typename TView>
400 std::string
const& elementSeparator,
401 std::string
const& rowSeparator,
402 std::string
const& rowPrefix,
403 std::string
const& rowSuffix) ->
void
408 auto const lastIdx(extent[TDim::value] - 1u);
409 for(
auto i(
decltype(lastIdx)(0)); i <= lastIdx; ++i)
413 reinterpret_cast<Elem<TView> const*
>(
reinterpret_cast<std::uint8_t const*
>(ptr) + i * pitch),
432 template<
typename TView>
440 std::string
const& elementSeparator,
442 std::string
const& rowPrefix,
443 std::string
const& rowSuffix) ->
void
448 for(
auto i(
decltype(lastIdx)(0)); i <= lastIdx; ++i)
456 os << elementSeparator;
464 template<
typename TDeviceProv
ider>
482 template<
typename TView>
486 std::string
const& elementSeparator =
", ",
487 std::string
const& rowSeparator =
"\n",
488 std::string
const& rowPrefix =
"[",
489 std::string
const& rowSuffix =
"]") ->
void
503 template<
typename TView>
511 template<
typename TDim,
typename TView>
525 template<concepts::DeviceProv
ider TDev,
typename TElem,
typename TExtent>
526 auto createView(TDev
const& dev, TElem* pMem, TExtent
const& extent)
548 template<concepts::DeviceProv
ider TDev,
typename TElem,
typename TExtent,
typename TPitch>
549 auto createView(TDev
const& dev, TElem* pMem, TExtent
const& extent, TPitch pitch)
561 template<concepts::DeviceProv
ider TDev,
typename TContainer>
576 template<concepts::DeviceProv
ider TDev,
typename TContainer,
typename TExtent>
577 auto createView(TDev
const& dev, TContainer& con, TExtent
const& extent)
580 return createView(device, std::data(con), extent);
589 template<
typename TView,
typename TExtent,
typename TOffsets>
590 auto createSubView(TView& view, TExtent
const& extent, TOffsets
const& offset = TExtent())
595#ifdef ALPAKA_USE_MDSPAN
596 namespace experimental
602 template<
typename ElementType>
603 struct ByteIndexedAccessor
605 using offset_policy = ByteIndexedAccessor;
606 using element_type = ElementType;
607 using reference = ElementType&;
609 using data_handle_type
610 = std::conditional_t<std::is_const_v<ElementType>, std::byte
const*, std::byte*>;
612 constexpr ByteIndexedAccessor() noexcept = default;
614 ALPAKA_FN_HOST_ACC constexpr data_handle_type offset(data_handle_type p,
size_t i) const noexcept
619 ALPAKA_FN_HOST_ACC constexpr reference access(data_handle_type p,
size_t i)
const noexcept
621 assert(i %
alignof(ElementType) == 0);
622 return *
reinterpret_cast<ElementType*
>(__builtin_assume_aligned(p + i,
alignof(ElementType)));
626 template<
typename TView, std::size_t... Is>
627 ALPAKA_FN_HOST auto makeExtents(TView
const& view, std::index_sequence<Is...>)
630 return dextents<Idx<TView>, Dim<TView>::value>{ex[Is]...};
635 template<
typename TView,
typename TSfinae =
void>
640 constexpr auto dim = Dim<TView>::value;
641 using Element = Elem<TView>;
642 auto extents = detail::makeExtents(view, std::make_index_sequence<dim>{});
643 auto* ptr =
reinterpret_cast<std::byte*
>(
getPtrNative(view));
645 layout_stride::mapping<
decltype(extents)> m{extents, strides};
646 return mdspan<Element,
decltype(extents), layout_stride, detail::ByteIndexedAccessor<Element>>{
653 constexpr auto dim = Dim<TView>::value;
654 using Element = Elem<TView>;
655 auto extents = detail::makeExtents(view, std::make_index_sequence<dim>{});
656 auto* ptr =
reinterpret_cast<std::byte*
>(
getPtrNative(view));
658 std::reverse(
begin(strides),
end(strides));
659 layout_stride::mapping<
decltype(extents)> m{extents, strides};
660 return mdspan<Element,
decltype(extents), layout_stride, detail::ByteIndexedAccessor<Element>>{
668 template<
typename TView>
671 return traits::GetMdSpan<TView>::getMdSpan(view);
677 template<
typename TView>
680 return traits::GetMdSpan<TView>::getMdSpanTransposed(view);
683 template<
typename TElem,
typename TIdx,
typename TDim>
684 using MdSpan = alpaka::experimental::mdspan<
686 alpaka::experimental::dextents<TIdx, TDim::value>,
687 alpaka::experimental::layout_stride,
688 alpaka::experimental::traits::detail::ByteIndexedAccessor<TElem>>;
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
ALPAKA_FN_HOST_ACC constexpr auto back() -> TVal &
#define ALPAKA_FN_HOST_ACC
auto getDeviceFromProvider(TDeviceProvider const &provider)
ALPAKA_FN_HOST_ACC constexpr auto calculatePitchesFromExtents(Vec< TDim, TIdx > const &extent)
Calculate the pitches purely from the extents.
ALPAKA_FN_HOST_ACC constexpr auto calculatePitchesFromExtentsAndPitch(Vec< TDim, TIdx > const &extent, std::size_t pitch)
Calculate the pitches from the extents and the one-dimensional pitch.
ALPAKA_FN_HOST auto end(TView &view) -> Iterator< TView >
ALPAKA_FN_HOST auto begin(TView &view) -> Iterator< TView >
The alpaka accelerator library.
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void
std::remove_volatile_t< typename trait::ElemType< TView >::type > Elem
The element type trait alias template to remove the ::type.
ALPAKA_FN_HOST auto getPitchBytesVecEnd(TView const &view=TView()) -> Vec< TDim, Idx< TView > >
ALPAKA_FN_HOST_ACC constexpr auto toArray(Vec< TDim, TVal > const &v) -> std::array< TVal, TDim::value >
Converts a Vec to a std::array.
ALPAKA_FN_HOST auto getPitchesInBytes(TView const &view) -> Vec< Dim< TView >, Idx< TView > >
auto getPitchBytesVec(TView const &view) -> Vec< Dim< TView >, Idx< TView > >
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 constexpr auto castVec(TVec const &vec)
auto createSubView(TView &view, TExtent const &extent, TOffsets const &offset=TExtent())
Creates a sub view to an existing view.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto subVecEnd(TVec const &vec)
ALPAKA_FN_HOST auto createTaskFill(TViewFwd &&view, TValue const &value, TExtent const &extent)
typename trait::IdxType< T >::type Idx
ALPAKA_FN_HOST auto print(TView const &view, std::ostream &os, std::string const &elementSeparator=", ", std::string const &rowSeparator="\n", std::string const &rowPrefix="[", std::string const &rowSuffix="]") -> void
Prints the content of the view to the given queue.
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T > >
typename trait::DevType< T >::type Dev
The device type trait alias template to remove the ::type.
ALPAKA_FN_HOST auto memset(TQueue &queue, TViewFwd &&view, std::uint8_t const &byte, TExtent const &extent) -> void
Sets the bytes of the memory of view, described by extent, to the given value.
ALPAKA_FN_HOST auto fill(TQueue &queue, TViewFwd &&view, TValue const &value) -> void
ALPAKA_FN_HOST auto getDev(T const &t)
ALPAKA_FN_HOST auto enqueue(TQueue &queue, TTask &&task) -> void
Queues the given task in the given queue.
std::integral_constant< std::size_t, N > DimInt
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 createTaskMemset(TViewFwd &&view, std::uint8_t const &byte, TExtent const &extent)
Create a memory set task.
ALPAKA_FN_HOST auto getPitchBytes(TView const &view) -> Idx< TView >
auto createView(TDev const &dev, TElem *pMem, TExtent const &extent)
Creates a view to a device pointer.
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
static ALPAKA_FN_HOST auto print(TView const &, Elem< TView > const *const ptr, Vec< Dim< TView >, Idx< TView > > const &extent, std::ostream &os, std::string const &elementSeparator, std::string const &, std::string const &rowPrefix, std::string const &rowSuffix) -> void
static ALPAKA_FN_HOST auto print(TView const &view, Elem< TView > const *const ptr, Vec< Dim< TView >, Idx< TView > > const &extent, std::ostream &os, std::string const &elementSeparator, std::string const &rowSeparator, std::string const &rowPrefix, std::string const &rowSuffix) -> void
The sub view creation trait.
The memory copy task trait.
The memory set task trait.
The device memory view creation trait.
The pitch in bytes. This is the distance in bytes in the linear memory between two consecutive elemen...
static ALPAKA_FN_HOST auto getPitchBytes(TView const &view) -> ViewIdx
Customization point for getPitchesInBytes. The default implementation uses the extent to calculate th...
ALPAKA_FN_HOST_ACC constexpr auto operator()(TView const &view) const
The pointer on device get trait.
The native pointer get trait.