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
7
#include "
alpaka/core/Common.hpp
"
8
#include "
alpaka/dev/DevCpu.hpp
"
9
#include "
alpaka/mem/view/Traits.hpp
"
10
#include "
alpaka/platform/PlatformCpu.hpp
"
11
12
#include <span>
13
14
namespace
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
{
39
using
type
=
DimInt<1u>
;
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
DevCpu.hpp
PlatformCpu.hpp
alpaka::DevCpu
The CPU device handle.
Definition
DevCpu.hpp:56
alpaka::Vec
A n-dimensional vector.
Definition
Vec.hpp:38
Common.hpp
ALPAKA_FN_HOST
#define ALPAKA_FN_HOST
Definition
Common.hpp:40
Traits.hpp
alpaka::trait
The accelerator traits.
Definition
AccCpuOmp2Blocks.hpp:115
alpaka::Idx
typename trait::IdxType< T >::type Idx
Definition
Traits.hpp:29
alpaka::getDevByIdx
ALPAKA_FN_HOST auto getDevByIdx(TPlatform const &platform, std::size_t const &devIdx) -> Dev< TPlatform >
Definition
Traits.hpp:62
alpaka::DimInt
std::integral_constant< std::size_t, N > DimInt
Definition
DimIntegralConst.hpp:15
std
STL namespace.
alpaka::PlatformCpu
The CPU device platform.
Definition
PlatformCpu.hpp:18
alpaka::trait::DevType
The device type trait.
Definition
Traits.hpp:23
alpaka::trait::DimType< std::span< TElem > >::type
DimInt< 1u > type
Definition
ViewStdSpan.hpp:39
alpaka::trait::DimType
The dimension getter type trait.
Definition
Traits.hpp:14
alpaka::trait::ElemType< std::span< TElem > >::type
TElem type
Definition
ViewStdSpan.hpp:46
alpaka::trait::ElemType
The element type trait.
Definition
Traits.hpp:16
alpaka::trait::GetDev< std::span< TElem > >::getDev
static ALPAKA_FN_HOST auto getDev(std::span< TElem > const &) -> DevCpu
Definition
ViewStdSpan.hpp:27
alpaka::trait::GetDev
The device get trait.
Definition
Traits.hpp:27
alpaka::trait::GetExtents< std::span< TElem > >::operator()
ALPAKA_FN_HOST constexpr auto operator()(std::span< TElem > const &a) -> Vec< DimInt< 1 >, Idx< std::span< TElem > > >
Definition
ViewStdSpan.hpp:52
alpaka::trait::GetExtents
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition
Traits.hpp:37
alpaka::trait::GetOffsets< std::span< TElem > >::operator()
ALPAKA_FN_HOST auto operator()(std::span< TElem > const &) -> Vec< DimInt< 1 >, Idx< std::span< TElem > > >
Definition
ViewStdSpan.hpp:77
alpaka::trait::GetOffsets
The GetOffsets trait for getting the offsets of an object as an alpaka::Vec.
Definition
Traits.hpp:33
alpaka::trait::GetPtrNative< std::span< TElem > >::getPtrNative
static ALPAKA_FN_HOST auto getPtrNative(std::span< TElem > &view) -> TElem *
Definition
ViewStdSpan.hpp:67
alpaka::trait::GetPtrNative< std::span< TElem > >::getPtrNative
static ALPAKA_FN_HOST auto getPtrNative(std::span< TElem > const &view) -> TElem const *
Definition
ViewStdSpan.hpp:62
alpaka::trait::GetPtrNative
The native pointer get trait.
Definition
Traits.hpp:80
alpaka::trait::IdxType< std::span< TElem > >::type
std::size_t type
Definition
ViewStdSpan.hpp:87
alpaka::trait::IdxType
The idx type trait.
Definition
Traits.hpp:25
include
alpaka
mem
view
ViewStdSpan.hpp
Generated on Mon Dec 15 2025 08:46:46 for alpaka by
1.9.8