alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
ViewStdSpan.hpp
Go to the documentation of this file.
1/* Copyright 2025 Simone Balducci
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
11
12#include <span>
13
14namespace alpaka::trait
15{
16 //! The std::span device type trait specialization.
17 template<typename TElem>
18 struct DevType<std::span<TElem>>
19 {
20 using type = DevCpu;
21 };
22
23 //! The std::span device get trait specialization.
24 template<typename TElem>
25 struct GetDev<std::span<TElem>>
26 {
27 ALPAKA_FN_HOST static auto getDev(std::span<TElem> const& /* view */) -> DevCpu
28 {
29 // Instantiating the CPU platform here is a hack we can do internally, because we know that the CPU
30 // platform does not contain any data. But it generally does not apply.
31 return getDevByIdx(PlatformCpu{}, 0u);
32 }
33 };
34
35 //! The std::span dimension getter trait specialization.
36 template<typename TElem>
37 struct DimType<std::span<TElem>>
38 {
40 };
41
42 //! The std::span memory element type get trait specialization.
43 template<typename TElem>
44 struct ElemType<std::span<TElem>>
45 {
46 using type = TElem;
47 };
48
49 template<typename TElem>
50 struct GetExtents<std::span<TElem>>
51 {
52 ALPAKA_FN_HOST constexpr auto operator()(std::span<TElem> const& a) -> Vec<DimInt<1>, Idx<std::span<TElem>>>
53 {
54 return {std::size(a)};
55 }
56 };
57
58 //! The std::span native pointer get trait specialization.
59 template<typename TElem>
60 struct GetPtrNative<std::span<TElem>>
61 {
62 ALPAKA_FN_HOST static auto getPtrNative(std::span<TElem> const& view) -> TElem const*
63 {
64 return std::data(view);
65 }
66
67 ALPAKA_FN_HOST static auto getPtrNative(std::span<TElem>& view) -> TElem*
68 {
69 return std::data(view);
70 }
71 };
72
73 //! The std::span offset get trait specialization.
74 template<typename TElem>
75 struct GetOffsets<std::span<TElem>>
76 {
77 ALPAKA_FN_HOST auto operator()(std::span<TElem> const&) -> Vec<DimInt<1>, Idx<std::span<TElem>>>
78 {
79 return {0};
80 }
81 };
82
83 //! The std::span idx type trait specialization.
84 template<typename TElem>
85 struct IdxType<std::span<TElem>>
86 {
87 using type = std::size_t;
88 };
89} // namespace alpaka::trait
The CPU device handle.
Definition DevCpu.hpp:56
A n-dimensional vector.
Definition Vec.hpp:38
#define ALPAKA_FN_HOST
Definition Common.hpp:40
The accelerator traits.
typename trait::IdxType< T >::type Idx
Definition Traits.hpp:29
ALPAKA_FN_HOST auto getDevByIdx(TPlatform const &platform, std::size_t const &devIdx) -> Dev< TPlatform >
Definition Traits.hpp:62
std::integral_constant< std::size_t, N > DimInt
STL namespace.
The CPU device platform.
The device type trait.
Definition Traits.hpp:23
The dimension getter type trait.
Definition Traits.hpp:14
The element type trait.
Definition Traits.hpp:16
static ALPAKA_FN_HOST auto getDev(std::span< TElem > const &) -> DevCpu
The device get trait.
Definition Traits.hpp:27
ALPAKA_FN_HOST constexpr auto operator()(std::span< TElem > const &a) -> Vec< DimInt< 1 >, Idx< std::span< TElem > > >
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition Traits.hpp:37
ALPAKA_FN_HOST auto operator()(std::span< TElem > const &) -> Vec< DimInt< 1 >, Idx< std::span< TElem > > >
The GetOffsets trait for getting the offsets of an object as an alpaka::Vec.
Definition Traits.hpp:33
static ALPAKA_FN_HOST auto getPtrNative(std::span< TElem > &view) -> TElem *
static ALPAKA_FN_HOST auto getPtrNative(std::span< TElem > const &view) -> TElem const *
The native pointer get trait.
Definition Traits.hpp:80
The idx type trait.
Definition Traits.hpp:25