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
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
20namespace alpaka::detail
21{
22 template<typename TDim, typename SFINAE = void>
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>
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>
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 {
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
77
79 {
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>
98
99 template<typename TBuf, typename TSfinae>
101
102 template<typename TBuf, typename TDev, typename TSfinae>
104
105 template<typename TBuf, typename TSfinae>
107 };
108
109} // namespace alpaka::detail
110
111#endif
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
Definition Debug.hpp:55
The CUDA/HIP RT device handle.
A n-dimensional vector.
Definition Vec.hpp:38
The Uniform Cuda/HIP memory buffer implementation.
BufUniformCudaHipRtImpl(BufUniformCudaHipRtImpl &&)=delete
auto operator=(BufUniformCudaHipRtImpl &&) -> BufUniformCudaHipRtImpl &=delete
ALPAKA_FN_HOST BufUniformCudaHipRtImpl(DevUniformCudaHipRt< TApi > dev, TElem *pMem, std::function< void(TElem *)> deleter, TExtent const &extent, std::size_t pitchBytes)
#define ALPAKA_FN_HOST
Definition Common.hpp:40
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T > >
Definition Traits.hpp:59
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Definition Traits.hpp:19
STL namespace.
The device get trait.
Definition Traits.hpp:27
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition Traits.hpp:37
Customization point for getPitchesInBytes. The default implementation uses the extent to calculate th...
Definition Traits.hpp:103
The pointer on device get trait.
Definition Traits.hpp:58
The native pointer get trait.
Definition Traits.hpp:54