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