alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
ConstBufCpuTraits.hpp
Go to the documentation of this file.
1/* Copyright 2022 Alexander Matthes, Axel Huebl, Benjamin Worpitz, Andrea Bocci, Jan Stephan, Bernhard Manfred Gruber,
2 * Anton Reinhard
3 * SPDX-License-Identifier: MPL-2.0
4 */
5#pragma once
6
11
12namespace alpaka::trait
13{
14 //! The CPU device memory const-buffer type trait specialization.
15 template<typename TElem, typename TDim, typename TIdx>
16 struct ConstBufType<DevCpu, TElem, TDim, TIdx>
17 {
19 };
20
21 //! The ConstBufCpu device type trait specialization.
22 template<typename TElem, typename TDim, typename TIdx>
23 struct DevType<ConstBufCpu<TElem, TDim, TIdx>>
24 {
25 using type = DevCpu;
26 };
27
28 //! The ConstBufCpu device get trait specialization.
29 template<typename TElem, typename TDim, typename TIdx>
30 struct GetDev<ConstBufCpu<TElem, TDim, TIdx>>
31 {
33 {
34 return buf.m_spBufImpl->m_dev;
35 }
36 };
37
38 //! The ConstBufCpu dimension getter trait.
39 template<typename TElem, typename TDim, typename TIdx>
40 struct DimType<ConstBufCpu<TElem, TDim, TIdx>>
41 {
42 using type = TDim;
43 };
44
45 //! The ConstBufCpu memory element type get trait specialization.
46 template<typename TElem, typename TDim, typename TIdx>
47 struct ElemType<ConstBufCpu<TElem, TDim, TIdx>>
48 {
49 // const qualify the element type of the inner view
50 using type = TElem const;
51 };
52
53 //! The ConstBufCpu width get trait specialization.
54 template<typename TElem, typename TDim, typename TIdx>
55 struct GetExtents<ConstBufCpu<TElem, TDim, TIdx>>
56 {
58 {
59 return buf.m_spBufImpl->m_extentElements;
60 }
61 };
62
63 //! The ConstBufCpu native pointer get trait specialization.
64 template<typename TElem, typename TDim, typename TIdx>
65 struct GetPtrNative<ConstBufCpu<TElem, TDim, TIdx>>
66 {
67 ALPAKA_FN_HOST static auto getPtrNative(ConstBufCpu<TElem, TDim, TIdx> const& buf) -> TElem const*
68 {
69 return buf.m_spBufImpl->m_pMem;
70 }
71 };
72
73 //! The ConstBufCpu pointer on device get trait specialization.
74 template<typename TElem, typename TDim, typename TIdx>
75 struct GetPtrDev<ConstBufCpu<TElem, TDim, TIdx>, DevCpu>
76 {
78 -> TElem const*
79 {
80 if(dev == getDev(buf))
81 {
82 return buf.m_spBufImpl->m_pMem;
83 }
84 else
85 {
86 throw std::runtime_error("The buffer is not accessible from the given device!");
87 }
88 }
89 };
90
91 //! The ConstBufCpu offset get trait specialization.
92 template<typename TElem, typename TDim, typename TIdx>
93 struct GetOffsets<ConstBufCpu<TElem, TDim, TIdx>>
94 {
99 };
100
101 //! The ConstBufCpu idx type trait specialization.
102 template<typename TElem, typename TDim, typename TIdx>
103 struct IdxType<ConstBufCpu<TElem, TDim, TIdx>>
104 {
105 using type = TIdx;
106 };
107
108 //! The MakeConstBuf trait for constant CPU buffers.
109 template<typename TElem, typename TDim, typename TIdx>
110 struct MakeConstBuf<ConstBufCpu<TElem, TDim, TIdx>>
111 {
114 {
115 return buf;
116 }
117
122 };
123} // namespace alpaka::trait
The CPU memory buffer.
The CPU device handle.
Definition DevCpu.hpp:56
A n-dimensional vector.
Definition Vec.hpp:38
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto zeros() -> Vec< TDim, TVal >
Zero value constructor.
Definition Vec.hpp:99
#define ALPAKA_FN_HOST
Definition Common.hpp:40
The accelerator traits.
ALPAKA_FN_HOST auto getDev(T const &t)
Definition Traits.hpp:68
The memory const-buffer type trait.
Definition Traits.hpp:27
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(ConstBufCpu< TElem, TDim, TIdx > const &buf) -> DevCpu
The device get trait.
Definition Traits.hpp:27
ALPAKA_FN_HOST auto operator()(ConstBufCpu< TElem, TDim, TIdx > const &buf)
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition Traits.hpp:37
ALPAKA_FN_HOST auto operator()(ConstBufCpu< TElem, TDim, TIdx > const &) const -> Vec< TDim, TIdx >
The GetOffsets trait for getting the offsets of an object as an alpaka::Vec.
Definition Traits.hpp:33
static ALPAKA_FN_HOST auto getPtrDev(ConstBufCpu< TElem, TDim, TIdx > const &buf, DevCpu const &dev) -> TElem const *
The pointer on device get trait.
Definition Traits.hpp:58
static ALPAKA_FN_HOST auto getPtrNative(ConstBufCpu< TElem, TDim, TIdx > const &buf) -> TElem const *
The native pointer get trait.
Definition Traits.hpp:54
The idx type trait.
Definition Traits.hpp:25
static ALPAKA_FN_HOST auto makeConstBuf(ConstBufCpu< TElem, TDim, TIdx > const &buf) -> ConstBufCpu< TElem, TDim, TIdx >
static ALPAKA_FN_HOST auto makeConstBuf(ConstBufCpu< TElem, TDim, TIdx > &&buf) -> ConstBufCpu< TElem, TDim, TIdx >
The trait to transform a mutable buffer into a constant one.
Definition Traits.hpp:55