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