alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
ViewConst.hpp
Go to the documentation of this file.
1
/* Copyright 2022 Bernhard Manfred Gruber
2
* SPDX-License-Identifier: MPL-2.0
3
*/
4
5
#pragma once
6
7
#include "
alpaka/core/Common.hpp
"
8
#include "
alpaka/dev/Traits.hpp
"
9
#include "
alpaka/dim/Traits.hpp
"
10
#include "
alpaka/extent/Traits.hpp
"
11
#include "
alpaka/idx/Traits.hpp
"
12
#include "
alpaka/mem/view/Traits.hpp
"
13
#include "
alpaka/mem/view/ViewAccessOps.hpp
"
14
#include "
alpaka/offset/Traits.hpp
"
15
16
namespace
alpaka
17
{
18
//! A non-modifiable wrapper around a view. This view acts as the wrapped view, but the underlying data is only
19
//! exposed const-qualified.
20
template
<
typename
TView>
21
struct
ViewConst
:
internal::ViewAccessOps
<ViewConst<TView>>
22
{
23
static_assert
(!std::is_const_v<TView>,
"ViewConst must be instantiated with a non-const type"
);
24
static_assert
(
25
!std::is_reference_v<TView>,
26
"This is not implemented"
);
// It might even be dangerous for ViewConst to store a reference to the wrapped
27
// view, as this decouples the wrapped view's lifetime.
28
29
ALPAKA_FN_HOST
ViewConst
(TView
const
& view) :
m_view
(view)
30
{
31
}
32
33
ALPAKA_FN_HOST
ViewConst
(TView&& view) :
m_view
(
std
::move(view))
34
{
35
}
36
37
TView
m_view
;
38
};
39
40
template
<
typename
TView>
41
ViewConst
(TView) ->
ViewConst<std::decay_t<TView>
>;
42
43
namespace
trait
44
{
45
template
<
typename
TView>
46
struct
DevType
<
ViewConst
<TView>> :
DevType
<TView>
47
{
48
};
49
50
template
<
typename
TView>
51
struct
GetDev
<
ViewConst
<TView>>
52
{
53
ALPAKA_FN_HOST
static
auto
getDev
(
ViewConst<TView>
const
& view)
54
{
55
return
alpaka::getDev
(view.
m_view
);
56
}
57
};
58
59
template
<
typename
TView>
60
struct
DimType
<
ViewConst
<TView>> :
DimType
<TView>
61
{
62
};
63
64
template
<
typename
TView>
65
struct
ElemType
<
ViewConst
<TView>>
66
{
67
// const qualify the element type of the inner view
68
using
type
=
typename
ElemType<TView>::type
const
;
69
};
70
71
template
<
typename
TView>
72
struct
GetExtents
<
ViewConst
<TView>>
73
{
74
ALPAKA_FN_HOST
auto
operator()
(
ViewConst<TView>
const
& view)
const
75
{
76
return
getExtents
(view.
m_view
);
77
}
78
};
79
80
template
<
typename
TView>
81
struct
GetPtrNative
<
ViewConst
<TView>>
82
{
83
using
TElem
=
typename
ElemType<TView>::type
;
84
85
// const qualify the element type of the inner view
86
ALPAKA_FN_HOST
static
auto
getPtrNative
(
ViewConst<TView>
const
& view) ->
TElem
const
*
87
{
88
return
alpaka::getPtrNative
(view.m_view);
89
}
90
};
91
92
template
<
typename
TView>
93
struct
GetPitchesInBytes
<
ViewConst
<TView>>
94
{
95
ALPAKA_FN_HOST
auto
operator()
(
ViewConst<TView>
const
& view)
const
96
{
97
return
alpaka::getPitchesInBytes
(view.
m_view
);
98
}
99
};
100
101
template
<
typename
TView>
102
struct
GetOffsets
<
ViewConst
<TView>>
103
{
104
ALPAKA_FN_HOST
auto
operator()
(
ViewConst<TView>
const
& view)
const
105
{
106
return
alpaka::getOffsets
(view.
m_view
);
107
}
108
};
109
110
template
<
typename
TView>
111
struct
IdxType
<
ViewConst
<TView>> :
IdxType
<TView>
112
{
113
};
114
}
// namespace trait
115
}
// namespace alpaka
ViewAccessOps.hpp
Common.hpp
ALPAKA_FN_HOST
#define ALPAKA_FN_HOST
Definition
Common.hpp:40
Traits.hpp
Traits.hpp
Traits.hpp
Traits.hpp
Traits.hpp
alpaka
The alpaka accelerator library.
Definition
AccCpuOmp2Blocks.hpp:49
alpaka::getPitchesInBytes
ALPAKA_FN_HOST auto getPitchesInBytes(TView const &view) -> Vec< Dim< TView >, Idx< TView > >
Definition
Traits.hpp:196
alpaka::getPtrNative
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
Definition
Traits.hpp:136
alpaka::getExtents
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T > >
Definition
Traits.hpp:59
alpaka::getDev
ALPAKA_FN_HOST auto getDev(T const &t)
Definition
Traits.hpp:68
alpaka::getOffsets
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getOffsets(T const &object) -> Vec< Dim< T >, Idx< T > >
Definition
Traits.hpp:55
std
STL namespace.
Traits.hpp
alpaka::ViewConst
A non-modifiable wrapper around a view. This view acts as the wrapped view, but the underlying data i...
Definition
ViewConst.hpp:22
alpaka::ViewConst::ViewConst
ALPAKA_FN_HOST ViewConst(TView const &view)
Definition
ViewConst.hpp:29
alpaka::ViewConst::m_view
TView m_view
Definition
ViewConst.hpp:37
alpaka::ViewConst::ViewConst
ALPAKA_FN_HOST ViewConst(TView &&view)
Definition
ViewConst.hpp:33
alpaka::internal::ViewAccessOps
Definition
ViewAccessOps.hpp:36
alpaka::trait::DevType
The device type trait.
Definition
Traits.hpp:23
alpaka::trait::DimType
The dimension getter type trait.
Definition
Traits.hpp:14
alpaka::trait::ElemType< ViewConst< TView > >::type
typename ElemType< TView >::type const type
Definition
ViewConst.hpp:68
alpaka::trait::ElemType
The element type trait.
Definition
Traits.hpp:16
alpaka::trait::GetDev< ViewConst< TView > >::getDev
static ALPAKA_FN_HOST auto getDev(ViewConst< TView > const &view)
Definition
ViewConst.hpp:53
alpaka::trait::GetDev
The device get trait.
Definition
Traits.hpp:27
alpaka::trait::GetExtents< ViewConst< TView > >::operator()
ALPAKA_FN_HOST auto operator()(ViewConst< TView > const &view) const
Definition
ViewConst.hpp:74
alpaka::trait::GetExtents
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition
Traits.hpp:37
alpaka::trait::GetOffsets< ViewConst< TView > >::operator()
ALPAKA_FN_HOST auto operator()(ViewConst< TView > const &view) const
Definition
ViewConst.hpp:104
alpaka::trait::GetOffsets
The GetOffsets trait for getting the offsets of an object as an alpaka::Vec.
Definition
Traits.hpp:33
alpaka::trait::GetPitchesInBytes< ViewConst< TView > >::operator()
ALPAKA_FN_HOST auto operator()(ViewConst< TView > const &view) const
Definition
ViewConst.hpp:95
alpaka::trait::GetPitchesInBytes
Customization point for getPitchesInBytes. The default implementation uses the extent to calculate th...
Definition
Traits.hpp:103
alpaka::trait::GetPtrNative< ViewConst< TView > >::getPtrNative
static ALPAKA_FN_HOST auto getPtrNative(ViewConst< TView > const &view) -> TElem const *
Definition
ViewConst.hpp:86
alpaka::trait::GetPtrNative< ViewConst< TView > >::TElem
typename ElemType< TView >::type TElem
Definition
ViewConst.hpp:83
alpaka::trait::GetPtrNative
The native pointer get trait.
Definition
Traits.hpp:54
alpaka::trait::IdxType
The idx type trait.
Definition
Traits.hpp:25
include
alpaka
mem
view
ViewConst.hpp
Generated on Tue Feb 4 2025 09:02:23 for alpaka by
1.9.8