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
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 static_assert(
245 "The view and the extent must have compatible index types!");
246
248 std::forward<TViewFwd>(view),
249 byte,
250 extent);
251 }
252
253 template<typename TExtent, typename TViewFwd, typename TValue>
254 ALPAKA_FN_HOST auto createTaskFill(TViewFwd&& view, TValue const& value, TExtent const& extent)
255 {
256 using TView = std::remove_reference_t<TViewFwd>;
257 static_assert(!std::is_const_v<TView>, "The view must not be const!");
258 static_assert(
260 "The view and the extent are required to have the same dimensionality!");
261 static_assert(
263 "The view and the extent must have compatible index types!");
264
266 std::forward<TViewFwd>(view),
267 value,
268 extent);
269 }
270
271 //! Sets the bytes of the memory of view, described by extent, to the given value.
272 //!
273 //! \param queue The queue to enqueue the view fill task into.
274 //! \param[in,out] view The memory view to fill. May be a temporary object.
275 //! \param byte Value to set for each element of the specified view.
276 //! \param extent The extent of the view to fill.
277 template<typename TExtent, typename TViewFwd, typename TQueue>
278 ALPAKA_FN_HOST auto memset(TQueue& queue, TViewFwd&& view, std::uint8_t const& byte, TExtent const& extent) -> void
279 {
280 enqueue(queue, createTaskMemset(std::forward<TViewFwd>(view), byte, extent));
281 }
282
283 //! Sets each byte of the memory of the entire view to the given value.
284 //!
285 //! \param queue The queue to enqueue the view fill task into.
286 //! \param[in,out] view The memory view to fill. May be a temporary object.
287 //! \param byte Value to set for each element of the specified view.
288 template<typename TViewFwd, typename TQueue>
289 ALPAKA_FN_HOST auto memset(TQueue& queue, TViewFwd&& view, std::uint8_t const& byte) -> void
290 {
291 enqueue(queue, createTaskMemset(std::forward<TViewFwd>(view), byte, getExtents(view)));
292 }
293
294 template<typename TViewFwd, typename TValue, typename TQueue>
295 ALPAKA_FN_HOST auto fill(TQueue& queue, TViewFwd&& view, TValue const& value) -> void
296 {
297 enqueue(queue, createTaskFill(std::forward<TViewFwd>(view), value, getExtents(view)));
298 }
299
300 template<typename TExtent, typename TViewFwd, typename TValue, typename TQueue>
301 ALPAKA_FN_HOST auto fill(TQueue& queue, TViewFwd&& view, TValue const& value, TExtent const& extent) -> void
302 {
303 enqueue(queue, createTaskFill(std::forward<TViewFwd>(view), value, extent));
304 }
305
306 //! Creates a memory copy task.
307 //!
308 //! \param viewDst The destination memory view.
309 //! \param viewSrc The source memory view.
310 //! \param extent The extent of the view to copy.
311 template<typename TExtent, typename TViewSrc, typename TViewDstFwd>
312 ALPAKA_FN_HOST auto createTaskMemcpy(TViewDstFwd&& viewDst, TViewSrc const& viewSrc, TExtent const& extent)
313 {
314 using TViewDst = std::remove_reference_t<TViewDstFwd>;
315 using SrcElem = Elem<TViewSrc>;
316 using DstElem = Elem<TViewDst>;
317 using ExtentIdx = Idx<TExtent>;
318 using DstIdx = Idx<TViewDst>;
319 using SrcIdx = Idx<TViewSrc>;
320
321 static_assert(!std::is_const_v<TViewDst>, "The destination view must not be const!");
322 static_assert(!std::is_const_v<DstElem>, "The destination view's element type must not be const!");
323 static_assert(
325 "The source and the destination view must have the same dimensionality!");
326 static_assert(
328 "The destination view and the extent must have the same dimensionality!");
329 static_assert(
330 std::is_same_v<DstElem, std::remove_const_t<SrcElem>>,
331 "The source and destination view must have the same element type!");
332 static_assert(
334 "The destination view and the extent are required to have compatible index types!");
335 static_assert(
337 "The source view and the extent are required to have compatible index types!");
338
340 std::forward<TViewDstFwd>(viewDst),
341 viewSrc,
342 extent);
343 }
344
345 //! Copies memory from a part of viewSrc to viewDst, described by extent. Possibly copies between different memory
346 //! spaces.
347 //!
348 //! \param queue The queue to enqueue the view copy task into.
349 //! \param[in,out] viewDst The destination memory view. May be a temporary object.
350 //! \param viewSrc The source memory view. May be a temporary object.
351 //! \param extent The extent of the view to copy.
352 template<typename TExtent, typename TViewSrc, typename TViewDstFwd, typename TQueue>
353 ALPAKA_FN_HOST auto memcpy(TQueue& queue, TViewDstFwd&& viewDst, TViewSrc const& viewSrc, TExtent const& extent)
354 -> void
355 {
356 enqueue(queue, createTaskMemcpy(std::forward<TViewDstFwd>(viewDst), viewSrc, extent));
357 }
358
359 //! Copies the entire memory of viewSrc to viewDst. Possibly copies between different memory
360 //! spaces.
361 //!
362 //! \param queue The queue to enqueue the view copy task into.
363 //! \param[in,out] viewDst The destination memory view. May be a temporary object.
364 //! \param viewSrc The source memory view. May be a temporary object.
365 template<typename TViewSrc, typename TViewDstFwd, typename TQueue>
366 ALPAKA_FN_HOST auto memcpy(TQueue& queue, TViewDstFwd&& viewDst, TViewSrc const& viewSrc) -> void
367 {
368 enqueue(queue, createTaskMemcpy(std::forward<TViewDstFwd>(viewDst), viewSrc, getExtents(viewSrc)));
369 }
370
371 namespace detail
372 {
373 template<typename TDim, typename TView>
374 struct Print
375 {
377 TView const& view,
378 Elem<TView> const* const ptr,
379 Vec<Dim<TView>, Idx<TView>> const& extent,
380 std::ostream& os,
381 std::string const& elementSeparator,
382 std::string const& rowSeparator,
383 std::string const& rowPrefix,
384 std::string const& rowSuffix) -> void
385 {
386 os << rowPrefix;
387
388 auto const pitch = getPitchesInBytes(view)[TDim::value + 1];
389 auto const lastIdx(extent[TDim::value] - 1u);
390 for(auto i(decltype(lastIdx)(0)); i <= lastIdx; ++i)
391 {
393 view,
394 reinterpret_cast<Elem<TView> const*>(reinterpret_cast<std::uint8_t const*>(ptr) + i * pitch),
395 extent,
396 os,
397 elementSeparator,
398 rowSeparator,
399 rowPrefix,
400 rowSuffix);
401
402 // While we are not at the end of a row, add the row separator.
403 if(i != lastIdx)
404 {
405 os << rowSeparator;
406 }
407 }
408
409 os << rowSuffix;
410 }
411 };
412
413 template<typename TView>
414 struct Print<DimInt<Dim<TView>::value - 1u>, TView>
415 {
417 TView const& /* view */,
418 Elem<TView> const* const ptr,
419 Vec<Dim<TView>, Idx<TView>> const& extent,
420 std::ostream& os,
421 std::string const& elementSeparator,
422 std::string const& /* rowSeparator */,
423 std::string const& rowPrefix,
424 std::string const& rowSuffix) -> void
425 {
426 os << rowPrefix;
427
428 auto const lastIdx(extent[Dim<TView>::value - 1u] - 1u);
429 for(auto i(decltype(lastIdx)(0)); i <= lastIdx; ++i)
430 {
431 // Add the current element.
432 os << *(ptr + i);
433
434 // While we are not at the end of a line, add the element separator.
435 if(i != lastIdx)
436 {
437 os << elementSeparator;
438 }
439 }
440
441 os << rowSuffix;
442 }
443 };
444 } // namespace detail
445
446 //! Prints the content of the view to the given queue.
447 // \TODO: Add precision flag.
448 // \TODO: Add column alignment flag.
449 template<typename TView>
451 TView const& view,
452 std::ostream& os,
453 std::string const& elementSeparator = ", ",
454 std::string const& rowSeparator = "\n",
455 std::string const& rowPrefix = "[",
456 std::string const& rowSuffix = "]") -> void
457 {
459 view,
460 getPtrNative(view),
461 getExtents(view),
462 os,
463 elementSeparator,
464 rowSeparator,
465 rowPrefix,
466 rowSuffix);
467 }
468
469 //! \return The pitch vector.
470 template<typename TView>
471 [[deprecated("Use getPitchesInBytes instead")]] auto getPitchBytesVec(TView const& view)
473 {
474 return getPitchesInBytes(view);
475 }
476
477 //! \return The pitch but only the last N elements.
478 template<typename TDim, typename TView>
479 ALPAKA_FN_HOST auto getPitchBytesVecEnd(TView const& view = TView()) -> Vec<TDim, Idx<TView>>
480 {
481 return subVecEnd<TDim>(getPitchesInBytes(view));
482 }
483
484 //! Creates a view to a device pointer
485 //!
486 //! \param dev Device from where pMem can be accessed.
487 //! \param pMem Pointer to memory. The pointer must be accessible from the given device.
488 //! \param extent Number of elements represented by the pMem.
489 //! Using a multi dimensional extent will result in a multi dimension view to the memory represented
490 //! by pMem.
491 //! \return A view to device memory.
492 template<typename TDev, typename TElem, typename TExtent>
493 auto createView(TDev const& dev, TElem* pMem, TExtent const& extent)
494 {
497 auto const extentVec = Vec<Dim, Idx>(extent);
499 dev,
500 pMem,
501 extentVec,
502 detail::calculatePitchesFromExtents<TElem>(extentVec));
503 }
504
505 //! Creates a view to a device pointer
506 //!
507 //! \param dev Device from where pMem can be accessed.
508 //! \param pMem Pointer to memory. The pointer must be accessible from the given device.
509 //! \param extent Number of elements represented by the pMem.
510 //! Using a multi dimensional extent will result in a multi dimension view to the memory represented
511 //! by pMem.
512 //! \param pitch Pitch in bytes for each dimension. Dimensionality must be equal to extent.
513 //! \return A view to device memory.
514 template<typename TDev, typename TElem, typename TExtent, typename TPitch>
515 auto createView(TDev const& dev, TElem* pMem, TExtent const& extent, TPitch pitch)
516 {
517 return trait::CreateViewPlainPtr<TDev>::createViewPlainPtr(dev, pMem, extent, pitch);
518 }
519
520 //! Creates a view to a contiguous container of device-accessible memory.
521 //!
522 //! \param dev Device from which the container can be accessed.
523 //! \param con Contiguous container. The container must provide a `data()` method. The data held by the container
524 //! must be accessible from the given device. The `GetExtent` trait must be defined for the container.
525 //! \return A view to device memory.
526 template<typename TDev, typename TContainer>
527 auto createView(TDev const& dev, TContainer& con)
528 {
529 return createView(dev, std::data(con), getExtents(con));
530 }
531
532 //! Creates a view to a contiguous container of device-accessible memory.
533 //!
534 //! \param dev Device from which the container can be accessed.
535 //! \param con Contiguous container. The container must provide a `data()` method. The data held by the container
536 //! must be accessible from the given device. The `GetExtent` trait must be defined for the container.
537 //! \param extent Number of elements held by the container. Using a multi-dimensional extent will result in a
538 //! multi-dimensional view to the memory represented by the container.
539 //! \return A view to device memory.
540 template<typename TDev, typename TContainer, typename TExtent>
541 auto createView(TDev const& dev, TContainer& con, TExtent const& extent)
542 {
543 return createView(dev, std::data(con), extent);
544 }
545
546 //! Creates a sub view to an existing view.
547 //!
548 //! \param view The view this view is a sub-view of.
549 //! \param extent Number of elements the resulting view holds.
550 //! \param offset Number of elements skipped in view for the new origin of the resulting view.
551 //! \return A sub view to a existing view.
552 template<typename TView, typename TExtent, typename TOffsets>
553 auto createSubView(TView& view, TExtent const& extent, TOffsets const& offset = TExtent())
554 {
556 }
557
558#ifdef ALPAKA_USE_MDSPAN
559 namespace experimental
560 {
561 // import mdspan into alpaka::experimental namespace. see: https://eel.is/c++draft/mdspan.syn
562 using std::experimental::default_accessor;
563 using std::experimental::dextents;
564 using std::experimental::extents;
565 using std::experimental::layout_left;
566 using std::experimental::layout_right;
567 using std::experimental::layout_stride;
568 using std::experimental::mdspan;
569 // import submdspan as well, which is not standardized yet
570 using std::experimental::full_extent;
571 using std::experimental::submdspan;
572
573 namespace traits
574 {
575 namespace detail
576 {
577 template<typename ElementType>
578 struct ByteIndexedAccessor
579 {
580 using offset_policy = ByteIndexedAccessor;
581 using element_type = ElementType;
582 using reference = ElementType&;
583
584 using data_handle_type
585 = std::conditional_t<std::is_const_v<ElementType>, std::byte const*, std::byte*>;
586
587 constexpr ByteIndexedAccessor() noexcept = default;
588
589 ALPAKA_FN_HOST_ACC constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept
590 {
591 return p + i;
592 }
593
594 ALPAKA_FN_HOST_ACC constexpr reference access(data_handle_type p, size_t i) const noexcept
595 {
596 assert(i % alignof(ElementType) == 0);
597 return *reinterpret_cast<ElementType*>(__builtin_assume_aligned(p + i, alignof(ElementType)));
598 }
599 };
600
601 template<typename TView, std::size_t... Is>
602 ALPAKA_FN_HOST auto makeExtents(TView const& view, std::index_sequence<Is...>)
603 {
604 auto const ex = getExtents(view);
605 return std::experimental::dextents<Idx<TView>, Dim<TView>::value>{ex[Is]...};
606 }
607 } // namespace detail
608
609 //! Customization point for getting an mdspan from a view.
610 template<typename TView, typename TSfinae = void>
611 struct GetMdSpan
612 {
613 ALPAKA_FN_HOST static auto getMdSpan(TView& view)
614 {
615 constexpr auto dim = Dim<TView>::value;
616 using Element = Elem<TView>;
617 auto extents = detail::makeExtents(view, std::make_index_sequence<dim>{});
618 auto* ptr = reinterpret_cast<std::byte*>(getPtrNative(view));
619 auto const strides = toArray(getPitchesInBytes(view));
620 layout_stride::mapping<decltype(extents)> m{extents, strides};
621 return mdspan<Element, decltype(extents), layout_stride, detail::ByteIndexedAccessor<Element>>{
622 ptr,
623 m};
624 }
625
626 ALPAKA_FN_HOST static auto getMdSpanTransposed(TView& view)
627 {
628 constexpr auto dim = Dim<TView>::value;
629 using Element = Elem<TView>;
630 auto extents = detail::makeExtents(view, std::make_index_sequence<dim>{});
631 auto* ptr = reinterpret_cast<std::byte*>(getPtrNative(view));
632 auto strides = toArray(getPitchesInBytes(view));
633 std::reverse(begin(strides), end(strides));
634 layout_stride::mapping<decltype(extents)> m{extents, strides};
635 return mdspan<Element, decltype(extents), layout_stride, detail::ByteIndexedAccessor<Element>>{
636 ptr,
637 m};
638 }
639 };
640 } // namespace traits
641
642 //! Gets a std::mdspan from the given view. The memory layout is determined by the pitches of the view.
643 template<typename TView>
644 ALPAKA_FN_HOST auto getMdSpan(TView& view)
645 {
646 return traits::GetMdSpan<TView>::getMdSpan(view);
647 }
648
649 //! Gets a std::mdspan from the given view. The memory layout is determined by the reversed pitches of the
650 //! view. This effectively also reverses the extents of the view. In order words, if you create a transposed
651 //! mdspan on a 10x5 element view, the mdspan will have an iteration space of 5x10.
652 template<typename TView>
653 ALPAKA_FN_HOST auto getMdSpanTransposed(TView& view)
654 {
655 return traits::GetMdSpan<TView>::getMdSpanTransposed(view);
656 }
657
658 template<typename TElem, typename TIdx, typename TDim>
659 using MdSpan = alpaka::experimental::mdspan<
660 TElem,
661 alpaka::experimental::dextents<TIdx, TDim::value>,
662 alpaka::experimental::layout_stride,
663 alpaka::experimental::traits::detail::ByteIndexedAccessor<TElem>>;
664 } // namespace experimental
665#endif
666} // 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
std::integral_constant< bool, std::is_integral_v< TSuperset > &&std::is_integral_v< TSubset > &&(((std::is_unsigned_v< TSuperset >==std::is_unsigned_v< TSubset >) &&(sizeof(TSuperset) >=sizeof(TSubset)))||((std::is_unsigned_v< TSuperset > !=std::is_unsigned_v< TSubset >) &&(sizeof(TSuperset) > sizeof(TSubset))))> IsIntegralSuperset
The trait is true if all values of TSubset are contained in TSuperset.
Definition Integral.hpp:22
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:479
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:471
ALPAKA_FN_HOST auto createTaskMemcpy(TViewDstFwd &&viewDst, TViewSrc const &viewSrc, TExtent const &extent)
Creates a memory copy task.
Definition Traits.hpp:312
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:553
ALPAKA_FN_HOST auto createTaskFill(TViewFwd &&view, TValue const &value, TExtent const &extent)
Definition Traits.hpp:254
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:450
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:278
ALPAKA_FN_HOST auto fill(TQueue &queue, TViewFwd &&view, TValue const &value) -> void
Definition Traits.hpp:295
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:493
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:416
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:376
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