alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
BufUniformCudaHipRtImpl.hpp
Go to the documentation of this file.
1
/* Copyright 2025 Alexander Matthes, Benjamin Worpitz, Matthias Werner, René Widera, Andrea Bocci, Jan Stephan,
2
* Bernhard Manfred Gruber, Antonio Di Pilato, Anton Reinhard
3
* SPDX-License-Identifier: MPL-2.0
4
*/
5
6
#pragma once
7
8
#include "
alpaka/core/Common.hpp
"
9
#include "
alpaka/dev/DevCudaRt.hpp
"
10
#include "
alpaka/dev/DevHipRt.hpp
"
11
#include "
alpaka/mem/buf/Traits.hpp
"
12
#include "
alpaka/vec/Vec.hpp
"
13
14
#include <functional>
15
#include <memory>
16
#include <type_traits>
17
18
#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) || defined(ALPAKA_ACC_GPU_HIP_ENABLED)
19
20
namespace
alpaka::detail
21
{
22
template
<
typename
TDim,
typename
SFINAE =
void
>
23
struct
PitchHolder
24
{
25
explicit
PitchHolder
(std::size_t)
26
{
27
}
28
};
29
30
template
<
typename
TDim>
31
struct
PitchHolder
<TDim,
std
::enable_if_t<TDim::value >= 2>>
32
{
33
std::size_t
m_rowPitchInBytes
;
34
};
35
36
//! The Uniform Cuda/HIP memory buffer implementation.
37
template
<
typename
TApi,
typename
TElem,
typename
TDim,
typename
TIdx>
38
class
BufUniformCudaHipRtImpl
final :
detail::PitchHolder
<TDim>
39
{
40
static_assert
(
41
!std::is_const_v<TElem>,
42
"The elem type of the buffer can not be const because the C++ Standard forbids containers of const "
43
"elements!"
);
44
static_assert
(!std::is_const_v<TIdx>,
"The idx type of the buffer can not be const!"
);
45
46
public
:
47
template
<
typename
TExtent>
48
ALPAKA_FN_HOST
BufUniformCudaHipRtImpl
(
49
DevUniformCudaHipRt<TApi>
dev,
50
TElem* pMem,
51
std::function<
void
(TElem*)> deleter,
52
TExtent
const
& extent,
53
std::size_t pitchBytes)
54
: detail::
PitchHolder
<TDim>{pitchBytes}
55
, m_dev(dev)
56
, m_pMem(pMem)
57
, m_deleter(std::move(deleter))
58
, m_extentElements(
getExtents
(extent))
59
{
60
ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
;
61
62
static_assert
(
63
TDim::value ==
Dim<TExtent>::value
,
64
"The dimensionality of TExtent and the dimensionality of the TDim template parameter have to be "
65
"identical!"
);
66
static_assert
(
67
std::is_same_v<TIdx, Idx<TExtent>>,
68
"The idx type of TExtent and the TIdx template parameter have to be identical!"
);
69
70
# if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
71
std::cout << __func__ <<
" e: "
<< m_extentElements <<
" ptr: "
<<
static_cast<
void
*
>
(m_pMem) << std::endl;
72
# endif
73
}
74
75
BufUniformCudaHipRtImpl
(
BufUniformCudaHipRtImpl
&&) =
delete
;
76
auto
operator=
(
BufUniformCudaHipRtImpl
&&) ->
BufUniformCudaHipRtImpl
& =
delete
;
77
78
ALPAKA_FN_HOST
~BufUniformCudaHipRtImpl
()
79
{
80
ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
;
81
82
// NOTE: m_pMem is allowed to be a nullptr here.
83
m_deleter(m_pMem);
84
}
85
86
private
:
87
DevUniformCudaHipRt<TApi>
const
m_dev;
88
TElem*
const
m_pMem;
89
std::function<void(TElem*)> m_deleter;
90
Vec<TDim, TIdx>
const
m_extentElements;
91
92
// friend declarations to allow usage of these pointers in the respective trait implementations
93
template
<
typename
TBuf,
typename
TSfinae>
94
friend
struct
alpaka::trait::GetDev
;
95
96
template
<
typename
TBuf,
typename
TSfinae>
97
friend
struct
alpaka::trait::GetExtents
;
98
99
template
<
typename
TBuf,
typename
TSfinae>
100
friend
struct
alpaka::trait::GetPtrNative
;
101
102
template
<
typename
TBuf,
typename
TDev,
typename
TSfinae>
103
friend
struct
alpaka::trait::GetPtrDev
;
104
105
template
<
typename
TBuf,
typename
TSfinae>
106
friend
struct
alpaka::trait::GetPitchesInBytes
;
107
};
108
109
}
// namespace alpaka::detail
110
111
#endif
ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
Definition
Debug.hpp:55
DevCudaRt.hpp
DevHipRt.hpp
Vec.hpp
alpaka::DevUniformCudaHipRt
The CUDA/HIP RT device handle.
Definition
DevUniformCudaHipRt.hpp:62
alpaka::Vec
A n-dimensional vector.
Definition
Vec.hpp:38
alpaka::detail::BufUniformCudaHipRtImpl
The Uniform Cuda/HIP memory buffer implementation.
Definition
BufUniformCudaHipRtImpl.hpp:39
alpaka::detail::BufUniformCudaHipRtImpl::BufUniformCudaHipRtImpl
BufUniformCudaHipRtImpl(BufUniformCudaHipRtImpl &&)=delete
alpaka::detail::BufUniformCudaHipRtImpl::operator=
auto operator=(BufUniformCudaHipRtImpl &&) -> BufUniformCudaHipRtImpl &=delete
alpaka::detail::BufUniformCudaHipRtImpl::BufUniformCudaHipRtImpl
ALPAKA_FN_HOST BufUniformCudaHipRtImpl(DevUniformCudaHipRt< TApi > dev, TElem *pMem, std::function< void(TElem *)> deleter, TExtent const &extent, std::size_t pitchBytes)
Definition
BufUniformCudaHipRtImpl.hpp:48
alpaka::detail::BufUniformCudaHipRtImpl::~BufUniformCudaHipRtImpl
ALPAKA_FN_HOST ~BufUniformCudaHipRtImpl()
Definition
BufUniformCudaHipRtImpl.hpp:78
Common.hpp
ALPAKA_FN_HOST
#define ALPAKA_FN_HOST
Definition
Common.hpp:40
Traits.hpp
alpaka::detail
Definition
AccGpuUniformCudaHipRt.hpp:248
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::Dim
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Definition
Traits.hpp:19
std
STL namespace.
alpaka::detail::PitchHolder< TDim, std::enable_if_t< TDim::value >=2 >::m_rowPitchInBytes
std::size_t m_rowPitchInBytes
Definition
BufUniformCudaHipRtImpl.hpp:33
alpaka::detail::PitchHolder
Definition
BufUniformCudaHipRtImpl.hpp:24
alpaka::detail::PitchHolder::PitchHolder
PitchHolder(std::size_t)
Definition
BufUniformCudaHipRtImpl.hpp:25
alpaka::trait::GetDev
The device get trait.
Definition
Traits.hpp:27
alpaka::trait::GetExtents
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition
Traits.hpp:37
alpaka::trait::GetPitchesInBytes
Customization point for getPitchesInBytes. The default implementation uses the extent to calculate th...
Definition
Traits.hpp:103
alpaka::trait::GetPtrDev
The pointer on device get trait.
Definition
Traits.hpp:58
alpaka::trait::GetPtrNative
The native pointer get trait.
Definition
Traits.hpp:54
include
alpaka
mem
buf
uniformCudaHip
BufUniformCudaHipRtImpl.hpp
Generated on Wed Jun 4 2025 11:30:59 for alpaka by
1.9.8