alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Traits.hpp
Go to the documentation of this file.
1/* Copyright 2024 Axel Hübl, Benjamin Worpitz, Matthias Werner, Andrea Bocci, Jan Stephan, Bernhard Manfred Gruber,
2 * Aurora Perego, Simone Balducci
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
6#pragma once
7
10#include "alpaka/dev/Traits.hpp"
11#include "alpaka/dim/Traits.hpp"
14#include "alpaka/meta/Fold.hpp"
18#include "alpaka/vec/Traits.hpp"
19#include "alpaka/vec/Vec.hpp"
20
21#include <array>
22#include <cassert>
23#include <cstddef>
24#include <iosfwd>
25#include <type_traits>
26#include <vector>
27#ifdef ALPAKA_USE_MDSPAN
28# include <experimental/mdspan>
29#endif
30
31namespace alpaka
32{
33 namespace detail
34 {
35 //! Calculate the pitches purely from the extents.
36 template<typename TElem, typename TDim, typename TIdx>
38 {
39 Vec<TDim, TIdx> pitchBytes{};
40 constexpr auto dim = TIdx{TDim::value};
41 if constexpr(dim > 0)
42 pitchBytes.back() = static_cast<TIdx>(sizeof(TElem));
43 if constexpr(dim > 1)
44 for(TIdx i = TDim::value - 1; i > 0; i--)
45 pitchBytes[i - 1] = extent[i] * pitchBytes[i];
46 return pitchBytes;
47 }
48
49 //! Calculate the pitches from the extents and the one-dimensional pitch.
50 template<typename TElem, typename TDim, typename TIdx>
52 Vec<TDim, TIdx> const& extent,
53 std::size_t pitch)
54 {
55 Vec<TDim, TIdx> pitchBytes{};
56 constexpr auto dim = TIdx{TDim::value};
57 if constexpr(dim > 0)
58 pitchBytes.back() = static_cast<TIdx>(sizeof(TElem));
59 if constexpr(dim > 1)
60 {
61 if(pitch == 0)
62 pitchBytes[TDim::value - 2] = extent.back() * pitchBytes.back();
63 else
64 pitchBytes[TDim::value - 2] = static_cast<TIdx>(
65 (static_cast<std::size_t>(extent.back() * pitchBytes.back()) + pitch - 1) / pitch * pitch);
66 }
67 if constexpr(dim > 2)
68 for(TIdx i = TDim::value - 2; i > 0; i--)
69 pitchBytes[i - 1] = extent[i] * pitchBytes[i];
70 return pitchBytes;
71 }
72
73 } // namespace detail
74
75 //! The view traits.
76 namespace trait
77 {
78 //! The native pointer get trait.
79 template<typename TView, typename TSfinae = void>
81
82 //! The pointer on device get trait.
83 template<typename TView, typename TDev, typename TSfinae = void>
84 struct GetPtrDev;
85
86 //! The pitch in bytes.
87 //! This is the distance in bytes in the linear memory between two consecutive elements in the next higher
88 //! dimension (TIdx-1).
89 //!
90 //! The default implementation uses the extent to calculate the pitch.
91 template<typename TIdx, typename TView, typename TSfinae = void>
92 struct [[deprecated("Use GetPitchesInBytes instead")]] GetPitchBytes
93 {
95
96 ALPAKA_FN_HOST static auto getPitchBytes(TView const& view) -> ViewIdx
97 {
98 return getPitchBytesDefault(view);
99 }
100
101 private:
102 static auto getPitchBytesDefault(TView const& view) -> ViewIdx
103 {
104 constexpr auto idx = TIdx::value;
105 constexpr auto viewDim = Dim<TView>::value;
106 if constexpr(idx < viewDim - 1)
107 {
108#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
109# pragma GCC diagnostic push
110# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
111#endif
112 return getExtents(view)[idx] * GetPitchBytes<DimInt<idx + 1>, TView>::getPitchBytes(view);
113#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
114# pragma GCC diagnostic pop
115#endif
116 }
117 else if constexpr(idx == viewDim - 1)
118 return getExtents(view)[viewDim - 1] * static_cast<ViewIdx>(sizeof(Elem<TView>));
119 else
120 return static_cast<ViewIdx>(sizeof(Elem<TView>));
122 }
123 };
124
125 //! Customization point for \ref getPitchesInBytes.
126 //! The default implementation uses the extent to calculate the pitches.
127 template<typename TView, typename TSfinae = void>
129 {
130 ALPAKA_FN_HOST_ACC constexpr auto operator()(TView const& view) const
131 {
132 return alpaka::detail::calculatePitchesFromExtents<Elem<TView>>(getExtents(view));
133 }
134 };
135
136 //! The memory set task trait.
137 //!
138 //! Fills the view with data.
139 template<typename TDim, typename TDev, typename TSfinae = void>
141
142 template<typename TDim, typename TDev, typename TSfinae = void>
144
145 //! The memory copy task trait.
146 //!
147 //! Copies memory from one view into another view possibly on a different device.
148 template<typename TDim, typename TDevDst, typename TDevSrc, typename TSfinae = void>
150
151 //! The device memory view creation trait.
152 template<typename TDev, typename TSfinae = void>
154
155 //! The sub view creation trait.
156 template<typename TDev, typename TSfinae = void>
157 struct CreateSubView;
158 } // namespace trait
159
160 //! Gets the native pointer of the memory view.
161 //!
162 //! \param view The memory view.
163 //! \return The native pointer.
164 template<typename TView>
165 ALPAKA_FN_HOST auto getPtrNative(TView const& view) -> Elem<TView> const*
166 {
168 }
169
170 //! Gets the native pointer of the memory view.
171 //!
172 //! \param view The memory view.
173 //! \return The native pointer.
174 template<typename TView>
176 {
178 }
179
180 //! Gets the pointer to the view on the given device.
181 //!
182 //! \param view The memory view.
183 //! \param dev The device.
184 //! \return The pointer on the device.
185 template<typename TView, typename TDev>
186 ALPAKA_FN_HOST auto getPtrDev(TView const& view, TDev const& dev) -> Elem<TView> const*
187 {
189 }
190
191 //! Gets the pointer to the view on the given device.
192 //!
193 //! \param view The memory view.
194 //! \param dev The device.
195 //! \return The pointer on the device.
196 template<typename TView, typename TDev>
197 ALPAKA_FN_HOST auto getPtrDev(TView& view, TDev const& dev) -> Elem<TView>*
198 {
200 }
201
202 //! \return The pitch in bytes. This is the distance in bytes between two consecutive elements in the given
203 //! dimension.
204 template<std::size_t Tidx, typename TView>
205 [[deprecated("Use getPitchesInBytes instead")]] ALPAKA_FN_HOST auto getPitchBytes(TView const& view) -> Idx<TView>
206 {
207#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
208# pragma GCC diagnostic push
209# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
210#endif
212#if ALPAKA_COMP_CLANG || ALPAKA_COMP_GNUC
213# pragma GCC diagnostic pop
214#endif
215 }
216
217 //! \return The pitches in bytes as an alpaka::Vec. This is the distance in bytes between two consecutive elements
218 //! in the given dimension.
219 //! E.g. for a 3D view without padding, the 0-dim pitch is the distance in bytes to jump from one element to the
220 //! next within the same row, the 1-dim pitch (aka. the row pitch) is the distance in bytes to jump from one
221 //! element to the neighboring element on the next row. The 2-dim pitch (aka. the slice pitch) is the distance in
222 //! bytes to jump from one element to the neighboring element on the next slice.
223 //! E.g. a 3D view of floats without padding and the extents {42, 10, 2}, would have a pitch vector of {80, 8, 4}.
224 template<typename TView>
226 {
227 return trait::GetPitchesInBytes<TView>{}(view);
228 }
229
230 //! Create a memory set task.
231 //!
232 //! \param view The memory view to fill.
233 //! \param byte Value to set for each element of the specified view.
234 //! \param extent The extent of the view to fill.
235 template<typename TExtent, typename TViewFwd>
236 ALPAKA_FN_HOST auto createTaskMemset(TViewFwd&& view, std::uint8_t const& byte, TExtent const& extent)
237 {
238 using TView = std::remove_reference_t<TViewFwd>;
239 static_assert(!std::is_const_v<TView>, "The view must not be const!");
240 static_assert(
242 "The view and the extent are required to have the same dimensionality!");
243
244 assert((extent <= getExtents(view)).all() && "The memset extent must not be larger than the view's extent!");
245
247 std::forward<TViewFwd>(view),
248 byte,
249 extent);
250 }
251
252 template<typename TExtent, typename TViewFwd, typename TValue>
253 ALPAKA_FN_HOST auto createTaskFill(TViewFwd&& view, TValue const& value, TExtent const& extent)
254 {
255 using TView = std::remove_reference_t<TViewFwd>;
256 static_assert(!std::is_const_v<TView>, "The view must not be const!");
257 static_assert(
259 "The view and the extent are required to have the same dimensionality!");
260
261 assert((extent <= getExtents(view)).all() && "The fill extent must not be larger than the view's extent!");
262
264 std::forward<TViewFwd>(view),
265 value,
266 extent);
267 }
268
269 //! Sets the bytes of the memory of view, described by extent, to the given value.
270 //!
271 //! \param queue The queue to enqueue the view fill task into.
272 //! \param[in,out] view The memory view to fill. May be a temporary object.
273 //! \param byte Value to set for each element of the specified view.
274 //! \param extent The extent of the view to fill.
275 template<typename TExtent, typename TViewFwd, typename TQueue>
276 ALPAKA_FN_HOST auto memset(TQueue& queue, TViewFwd&& view, std::uint8_t const& byte, TExtent const& extent) -> void
277 {
278 enqueue(queue, createTaskMemset(std::forward<TViewFwd>(view), byte, extent));
279 }
280
281 //! Sets each byte of the memory of the entire view to the given value.
282 //!
283 //! \param queue The queue to enqueue the view fill task into.
284 //! \param[in,out] view The memory view to fill. May be a temporary object.
285 //! \param byte Value to set for each element of the specified view.
286 template<typename TViewFwd, typename TQueue>
287 ALPAKA_FN_HOST auto memset(TQueue& queue, TViewFwd&& view, std::uint8_t const& byte) -> void
288 {
289 enqueue(queue, createTaskMemset(std::forward<TViewFwd>(view), byte, getExtents(view)));
290 }
291
292 template<typename TViewFwd, typename TValue, typename TQueue>
293 ALPAKA_FN_HOST auto fill(TQueue& queue, TViewFwd&& view, TValue const& value) -> void
294 {
295 enqueue(queue, createTaskFill(std::forward<TViewFwd>(view), value, getExtents(view)));
296 }
297
298 template<typename TExtent, typename TViewFwd, typename TValue, typename TQueue>
299 ALPAKA_FN_HOST auto fill(TQueue& queue, TViewFwd&& view, TValue const& value, TExtent const& extent) -> void
300 {
301 enqueue(queue, createTaskFill(std::forward<TViewFwd>(view), value, extent));
302 }
303
304 //! Creates a memory copy task.
305 //!
306 //! \param viewDst The destination memory view.
307 //! \param viewSrc The source memory view.
308 //! \param extent The extent of the view to copy.
309 template<typename TExtent, typename TViewSrc, typename TViewDstFwd>
310 ALPAKA_FN_HOST auto createTaskMemcpy(TViewDstFwd&& viewDst, TViewSrc const& viewSrc, TExtent const& extent)
311 {
312 using TViewDst = std::remove_reference_t<TViewDstFwd>;
313 using SrcElem = Elem<TViewSrc>;
314 using DstElem = Elem<TViewDst>;
315
316 static_assert(!std::is_const_v<TViewDst>, "The destination view must not be const!");
317 static_assert(!std::is_const_v<DstElem>, "The destination view's element type must not be const!");
318 static_assert(
320 "The source and the destination view must have the same dimensionality!");
321 static_assert(
323 "The destination view and the extent must have the same dimensionality!");
324 static_assert(
325 std::is_same_v<DstElem, std::remove_const_t<SrcElem>>,
326 "The source and destination view must have the same element type!");
327
328 assert(
329 (extent <= getExtents(viewSrc)).all()
330 && "The memcpy extent must not be larger than the source view's extent!");
331 assert(
332 (extent <= getExtents(viewDst)).all()
333 && "The memcpy extent must not be larger than the destination view's extent!");
334
336 std::forward<TViewDstFwd>(viewDst),
337 viewSrc,
338 extent);
339 }
340
341 //! Copies memory from a part of viewSrc to viewDst, described by extent. Possibly copies between different memory
342 //! spaces.
343 //!
344 //! \param queue The queue to enqueue the view copy task into.
345 //! \param[in,out] viewDst The destination memory view. May be a temporary object.
346 //! \param viewSrc The source memory view. May be a temporary object.
347 //! \param extent The extent of the view to copy.
348 template<typename TExtent, typename TViewSrc, typename TViewDstFwd, typename TQueue>
349 ALPAKA_FN_HOST auto memcpy(TQueue& queue, TViewDstFwd&& viewDst, TViewSrc const& viewSrc, TExtent const& extent)
350 -> void
351 {
352 enqueue(queue, createTaskMemcpy(std::forward<TViewDstFwd>(viewDst), viewSrc, extent));
353 }
354
355 //! Copies the entire memory of viewSrc to viewDst. Possibly copies between different memory
356 //! spaces.
357 //!
358 //! \param queue The queue to enqueue the view copy task into.
359 //! \param[in,out] viewDst The destination memory view. May be a temporary object.
360 //! \param viewSrc The source memory view. May be a temporary object.
361 template<typename TViewSrc, typename TViewDstFwd, typename TQueue>
362 ALPAKA_FN_HOST auto memcpy(TQueue& queue, TViewDstFwd&& viewDst, TViewSrc const& viewSrc) -> void
363 {
364 enqueue(queue, createTaskMemcpy(std::forward<TViewDstFwd>(viewDst), viewSrc, getExtents(viewSrc)));
365 }
366
367 namespace detail
368 {
369 template<typename TDim, typename TView>
370 struct Print
371 {
373 TView const& view,
374 Elem<TView> const* const ptr,
375 Vec<Dim<TView>, Idx<TView>> const& extent,
376 std::ostream& os,
377 std::string const& elementSeparator,
378 std::string const& rowSeparator,
379 std::string const& rowPrefix,
380 std::string const& rowSuffix) -> void
381 {
382 os << rowPrefix;
383
384 auto const pitch = getPitchesInBytes(view)[TDim::value + 1];
385 auto const lastIdx(extent[TDim::value] - 1u);
386 for(auto i(decltype(lastIdx)(0)); i <= lastIdx; ++i)
387 {
389 view,
390 reinterpret_cast<Elem<TView> const*>(reinterpret_cast<std::uint8_t const*>(ptr) + i * pitch),
391 extent,
392 os,
393 elementSeparator,
394 rowSeparator,
395 rowPrefix,
396 rowSuffix);
397
398 // While we are not at the end of a row, add the row separator.
399 if(i != lastIdx)
400 {
401 os << rowSeparator;
402 }
403 }
404
405 os << rowSuffix;
406 }
407 };
408
409 template<typename TView>
410 struct Print<DimInt<Dim<TView>::value - 1u>, TView>
411 {
413 TView const& /* view */,
414 Elem<TView> const* const ptr,
415 Vec<Dim<TView>, Idx<TView>> const& extent,
416 std::ostream& os,
417 std::string const& elementSeparator,
418 std::string const& /* rowSeparator */,
419 std::string const& rowPrefix,
420 std::string const& rowSuffix) -> void
421 {
422 os << rowPrefix;
423
424 auto const lastIdx(extent[Dim<TView>::value - 1u] - 1u);
425 for(auto i(decltype(lastIdx)(0)); i <= lastIdx; ++i)
426 {
427 // Add the current element.
428 os << *(ptr + i);
429
430 // While we are not at the end of a line, add the element separator.
431 if(i != lastIdx)
432 {
433 os << elementSeparator;
434 }
435 }
436
437 os << rowSuffix;
438 }
439 };
440 } // namespace detail
441
442 //! Prints the content of the view to the given queue.
443 // \TODO: Add precision flag.
444 // \TODO: Add column alignment flag.
445 template<typename TView>
447 TView const& view,
448 std::ostream& os,
449 std::string const& elementSeparator = ", ",
450 std::string const& rowSeparator = "\n",
451 std::string const& rowPrefix = "[",
452 std::string const& rowSuffix = "]") -> void
453 {
455 view,
456 getPtrNative(view),
457 getExtents(view),
458 os,
459 elementSeparator,
460 rowSeparator,
461 rowPrefix,
462 rowSuffix);
463 }
464
465 //! \return The pitch vector.
466 template<typename TView>
467 [[deprecated("Use getPitchesInBytes instead")]] auto getPitchBytesVec(TView const& view)
469 {
470 return getPitchesInBytes(view);
471 }
472
473 //! \return The pitch but only the last N elements.
474 template<typename TDim, typename TView>
475 ALPAKA_FN_HOST auto getPitchBytesVecEnd(TView const& view = TView()) -> Vec<TDim, Idx<TView>>
476 {
477 return subVecEnd<TDim>(getPitchesInBytes(view));
478 }
479
480 //! Creates a view to a device pointer
481 //!
482 //! \param dev Device from where pMem can be accessed.
483 //! \param pMem Pointer to memory. The pointer must be accessible from the given device.
484 //! \param extent Number of elements represented by the pMem.
485 //! Using a multi dimensional extent will result in a multi dimension view to the memory represented
486 //! by pMem.
487 //! \return A view to device memory.
488 template<typename TDev, typename TElem, typename TExtent>
489 auto createView(TDev const& dev, TElem* pMem, TExtent const& extent)
490 {
493 auto const extentVec = Vec<Dim, Idx>(extent);
495 dev,
496 pMem,
497 extentVec,
498 detail::calculatePitchesFromExtents<TElem>(extentVec));
499 }
500
501 //! Creates a view to a device pointer
502 //!
503 //! \param dev Device from where pMem can be accessed.
504 //! \param pMem Pointer to memory. The pointer must be accessible from the given device.
505 //! \param extent Number of elements represented by the pMem.
506 //! Using a multi dimensional extent will result in a multi dimension view to the memory represented
507 //! by pMem.
508 //! \param pitch Pitch in bytes for each dimension. Dimensionality must be equal to extent.
509 //! \return A view to device memory.
510 template<typename TDev, typename TElem, typename TExtent, typename TPitch>
511 auto createView(TDev const& dev, TElem* pMem, TExtent const& extent, TPitch pitch)
512 {
513 return trait::CreateViewPlainPtr<TDev>::createViewPlainPtr(dev, pMem, extent, pitch);
514 }
515
516 //! Creates a view to a contiguous container of device-accessible memory.
517 //!
518 //! \param dev Device from which the container can be accessed.
519 //! \param con Contiguous container. The container must provide a `data()` method. The data held by the container
520 //! must be accessible from the given device. The `GetExtent` trait must be defined for the container.
521 //! \return A view to device memory.
522 template<typename TDev, typename TContainer>
523 auto createView(TDev const& dev, TContainer& con)
524 {
525 return createView(dev, std::data(con), getExtents(con));
526 }
527
528 //! Creates a view to a contiguous container of device-accessible memory.
529 //!
530 //! \param dev Device from which the container can be accessed.
531 //! \param con Contiguous container. The container must provide a `data()` method. The data held by the container
532 //! must be accessible from the given device. The `GetExtent` trait must be defined for the container.
533 //! \param extent Number of elements held by the container. Using a multi-dimensional extent will result in a
534 //! multi-dimensional view to the memory represented by the container.
535 //! \return A view to device memory.
536 template<typename TDev, typename TContainer, typename TExtent>
537 auto createView(TDev const& dev, TContainer& con, TExtent const& extent)
538 {
539 return createView(dev, std::data(con), extent);
540 }
541
542 //! Creates a sub view to an existing view.
543 //!
544 //! \param view The view this view is a sub-view of.
545 //! \param extent Number of elements the resulting view holds.
546 //! \param offset Number of elements skipped in view for the new origin of the resulting view.
547 //! \return A sub view to a existing view.
548 template<typename TView, typename TExtent, typename TOffsets>
549 auto createSubView(TView& view, TExtent const& extent, TOffsets const& offset = TExtent())
550 {
552 }
553
554#ifdef ALPAKA_USE_MDSPAN
555 namespace experimental
556 {
557 // import mdspan into alpaka::experimental namespace. see: https://eel.is/c++draft/mdspan.syn
558 using std::experimental::default_accessor;
559 using std::experimental::dextents;
560 using std::experimental::extents;
561 using std::experimental::layout_left;
562 using std::experimental::layout_right;
563 using std::experimental::layout_stride;
564 using std::experimental::mdspan;
565 // import submdspan as well, which is not standardized yet
566 using std::experimental::full_extent;
567 using std::experimental::submdspan;
568
569 namespace traits
570 {
571 namespace detail
572 {
573 template<typename ElementType>
574 struct ByteIndexedAccessor
575 {
576 using offset_policy = ByteIndexedAccessor;
577 using element_type = ElementType;
578 using reference = ElementType&;
579
580 using data_handle_type
581 = std::conditional_t<std::is_const_v<ElementType>, std::byte const*, std::byte*>;
582
583 constexpr ByteIndexedAccessor() noexcept = default;
584
585 ALPAKA_FN_HOST_ACC constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept
586 {
587 return p + i;
588 }
589
590 ALPAKA_FN_HOST_ACC constexpr reference access(data_handle_type p, size_t i) const noexcept
591 {
592 assert(i % alignof(ElementType) == 0);
593 return *reinterpret_cast<ElementType*>(__builtin_assume_aligned(p + i, alignof(ElementType)));
594 }
595 };
596
597 template<typename TView, std::size_t... Is>
598 ALPAKA_FN_HOST auto makeExtents(TView const& view, std::index_sequence<Is...>)
599 {
600 auto const ex = getExtents(view);
601 return std::experimental::dextents<Idx<TView>, Dim<TView>::value>{ex[Is]...};
602 }
603 } // namespace detail
604
605 //! Customization point for getting an mdspan from a view.
606 template<typename TView, typename TSfinae = void>
607 struct GetMdSpan
608 {
609 ALPAKA_FN_HOST static auto getMdSpan(TView& view)
610 {
611 constexpr auto dim = Dim<TView>::value;
612 using Element = Elem<TView>;
613 auto extents = detail::makeExtents(view, std::make_index_sequence<dim>{});
614 auto* ptr = reinterpret_cast<std::byte*>(getPtrNative(view));
615 auto const strides = toArray(getPitchesInBytes(view));
616 layout_stride::mapping<decltype(extents)> m{extents, strides};
617 return mdspan<Element, decltype(extents), layout_stride, detail::ByteIndexedAccessor<Element>>{
618 ptr,
619 m};
620 }
621
622 ALPAKA_FN_HOST static auto getMdSpanTransposed(TView& view)
623 {
624 constexpr auto dim = Dim<TView>::value;
625 using Element = Elem<TView>;
626 auto extents = detail::makeExtents(view, std::make_index_sequence<dim>{});
627 auto* ptr = reinterpret_cast<std::byte*>(getPtrNative(view));
628 auto strides = toArray(getPitchesInBytes(view));
629 std::reverse(begin(strides), end(strides));
630 layout_stride::mapping<decltype(extents)> m{extents, strides};
631 return mdspan<Element, decltype(extents), layout_stride, detail::ByteIndexedAccessor<Element>>{
632 ptr,
633 m};
634 }
635 };
636 } // namespace traits
637
638 //! Gets a std::mdspan from the given view. The memory layout is determined by the pitches of the view.
639 template<typename TView>
640 ALPAKA_FN_HOST auto getMdSpan(TView& view)
641 {
642 return traits::GetMdSpan<TView>::getMdSpan(view);
643 }
644
645 //! Gets a std::mdspan from the given view. The memory layout is determined by the reversed pitches of the
646 //! view. This effectively also reverses the extents of the view. In order words, if you create a transposed
647 //! mdspan on a 10x5 element view, the mdspan will have an iteration space of 5x10.
648 template<typename TView>
649 ALPAKA_FN_HOST auto getMdSpanTransposed(TView& view)
650 {
651 return traits::GetMdSpan<TView>::getMdSpanTransposed(view);
652 }
653
654 template<typename TElem, typename TIdx, typename TDim>
655 using MdSpan = alpaka::experimental::mdspan<
656 TElem,
657 alpaka::experimental::dextents<TIdx, TDim::value>,
658 alpaka::experimental::layout_stride,
659 alpaka::experimental::traits::detail::ByteIndexedAccessor<TElem>>;
660 } // namespace experimental
661#endif
662} // namespace alpaka
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
A n-dimensional vector.
Definition Vec.hpp:38
ALPAKA_FN_HOST_ACC constexpr auto back() -> TVal &
Definition Vec.hpp:141
#define ALPAKA_FN_HOST
Definition Common.hpp:40
#define ALPAKA_FN_HOST_ACC
Definition Common.hpp:39
ALPAKA_FN_HOST_ACC constexpr auto calculatePitchesFromExtents(Vec< TDim, TIdx > const &extent)
Calculate the pitches purely from the extents.
Definition Traits.hpp:37
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.
Definition Traits.hpp:51
ALPAKA_FN_HOST auto end(TView &view) -> Iterator< TView >
Definition Iterator.hpp:133
ALPAKA_FN_HOST auto begin(TView &view) -> Iterator< TView >
Definition Iterator.hpp:127
The alpaka accelerator library.
typename trait::IdxType< T >::type Idx
Definition Traits.hpp:29
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void
ALPAKA_FN_HOST auto getPitchBytesVecEnd(TView const &view=TView()) -> Vec< TDim, Idx< TView > >
Definition Traits.hpp:475
ALPAKA_FN_HOST_ACC constexpr auto toArray(Vec< TDim, TVal > const &v) -> std::array< TVal, TDim::value >
Converts a Vec to a std::array.
Definition Vec.hpp:536
ALPAKA_FN_HOST auto getPitchesInBytes(TView const &view) -> Vec< Dim< TView >, Idx< TView > >
Definition Traits.hpp:225
auto getPitchBytesVec(TView const &view) -> Vec< Dim< TView >, Idx< TView > >
Definition Traits.hpp:467
ALPAKA_FN_HOST auto createTaskMemcpy(TViewDstFwd &&viewDst, TViewSrc const &viewSrc, TExtent const &extent)
Creates a memory copy task.
Definition Traits.hpp:310
typename trait::DevType< T >::type Dev
The device type trait alias template to remove the ::type.
Definition Traits.hpp:56
auto createSubView(TView &view, TExtent const &extent, TOffsets const &offset=TExtent())
Creates a sub view to an existing view.
Definition Traits.hpp:549
ALPAKA_FN_HOST auto createTaskFill(TViewFwd &&view, TValue const &value, TExtent const &extent)
Definition Traits.hpp:253
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.
Definition Traits.hpp:446
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
Definition Traits.hpp:165
std::remove_volatile_t< typename trait::ElemType< TView >::type > Elem
The element type trait alias template to remove the ::type.
Definition Traits.hpp:21
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T > >
Definition Traits.hpp:59
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.
Definition Traits.hpp:276
ALPAKA_FN_HOST auto fill(TQueue &queue, TViewFwd &&view, TValue const &value) -> void
Definition Traits.hpp:293
ALPAKA_FN_HOST auto enqueue(TQueue &queue, TTask &&task) -> void
Queues the given task in the given queue.
Definition Traits.hpp:47
ALPAKA_FN_HOST auto getPtrDev(TView const &view, TDev const &dev) -> Elem< TView > const *
Gets the pointer to the view on the given device.
Definition Traits.hpp:186
std::integral_constant< std::size_t, N > DimInt
ALPAKA_FN_HOST auto createTaskMemset(TViewFwd &&view, std::uint8_t const &byte, TExtent const &extent)
Create a memory set task.
Definition Traits.hpp:236
ALPAKA_FN_HOST auto getPitchBytes(TView const &view) -> Idx< TView >
Definition Traits.hpp:205
auto createView(TDev const &dev, TElem *pMem, TExtent const &extent)
Creates a view to a device pointer.
Definition Traits.hpp:489
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Definition Traits.hpp:19
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
Definition Traits.hpp:412
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
Definition Traits.hpp:372
The sub view creation trait.
The memory copy task trait.
Definition Traits.hpp:149
The memory set task trait.
Definition Traits.hpp:140
The device memory view creation trait.
Definition Traits.hpp:153
The pitch in bytes. This is the distance in bytes in the linear memory between two consecutive elemen...
Definition Traits.hpp:93
static ALPAKA_FN_HOST auto getPitchBytes(TView const &view) -> ViewIdx
Definition Traits.hpp:96
Customization point for getPitchesInBytes. The default implementation uses the extent to calculate th...
Definition Traits.hpp:129
ALPAKA_FN_HOST_ACC constexpr auto operator()(TView const &view) const
Definition Traits.hpp:130
The pointer on device get trait.
Definition Traits.hpp:84
The native pointer get trait.
Definition Traits.hpp:80