alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
BufCpuImpl.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 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
10#include "alpaka/vec/Vec.hpp"
11
12#include <functional>
13#include <memory>
14#include <type_traits>
15
16namespace alpaka::detail
17{
18 //! The CPU memory buffer.
19 template<typename TElem, typename TDim, typename TIdx>
20 class BufCpuImpl final
21 {
22 static_assert(
23 !std::is_const_v<TElem>,
24 "The elem type of the buffer can not be const because the C++ Standard forbids containers of const "
25 "elements!");
26 static_assert(!std::is_const_v<TIdx>, "The idx type of the buffer can not be const!");
27
28 public:
29 template<typename TExtent>
31 DevCpu dev,
32 TElem* pMem,
33 std::function<void(TElem*)> deleter,
34 TExtent const& extent) noexcept
35 : m_dev(std::move(dev))
36 , m_pMem(pMem)
37 , m_deleter(std::move(deleter))
38 , m_extentElements(getExtentVecEnd<TDim>(extent))
39 {
41
42 static_assert(
43 TDim::value == Dim<TExtent>::value,
44 "The dimensionality of TExtent and the dimensionality of the TDim template parameter have to be "
45 "identical!");
46 static_assert(
47 std::is_same_v<TIdx, Idx<TExtent>>,
48 "The idx type of TExtent and the TIdx template parameter have to be identical!");
49
50#if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
51 std::cout << __func__ << " e: " << m_extentElements << " ptr: " << static_cast<void*>(m_pMem) << std::endl;
52#endif
53 }
54
56 auto operator=(BufCpuImpl&&) -> BufCpuImpl& = delete;
57
59 {
61
62 // NOTE: m_pMem is allowed to be a nullptr here.
63 m_deleter(m_pMem);
64 }
65
66 private:
67 DevCpu const m_dev;
68 TElem* const m_pMem;
69 std::function<void(TElem*)> m_deleter;
70 Vec<TDim, TIdx> const m_extentElements;
71
72 // friend declarations to allow usage of these pointers in the respective trait implementations
73 template<typename TBuf, typename TSfinae>
74 friend struct alpaka::trait::GetDev;
75
76 template<typename TBuf, typename TSfinae>
78
79 template<typename TBuf, typename TSfinae>
81
82 template<typename TBuf, typename TDev, typename TSfinae>
84 };
85} // namespace alpaka::detail
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
Definition Debug.hpp:55
The CPU device handle.
Definition DevCpu.hpp:56
A n-dimensional vector.
Definition Vec.hpp:38
The CPU memory buffer.
ALPAKA_FN_HOST ~BufCpuImpl()
ALPAKA_FN_HOST BufCpuImpl(DevCpu dev, TElem *pMem, std::function< void(TElem *)> deleter, TExtent const &extent) noexcept
BufCpuImpl(BufCpuImpl &&)=delete
auto operator=(BufCpuImpl &&) -> BufCpuImpl &=delete
#define ALPAKA_FN_HOST
Definition Common.hpp:40
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Definition Traits.hpp:19
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
The pointer on device get trait.
Definition Traits.hpp:58
The native pointer get trait.
Definition Traits.hpp:54