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
7
#include "
alpaka/core/Common.hpp
"
8
#include "
alpaka/dev/DevCpu.hpp
"
9
#include "
alpaka/mem/buf/Traits.hpp
"
10
#include "
alpaka/vec/Vec.hpp
"
11
12
#include <functional>
13
#include <memory>
14
#include <type_traits>
15
16
namespace
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>
30
ALPAKA_FN_HOST
BufCpuImpl
(
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
{
40
ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
;
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
55
BufCpuImpl
(
BufCpuImpl
&&) =
delete
;
56
auto
operator=
(
BufCpuImpl
&&) ->
BufCpuImpl
& =
delete
;
57
58
ALPAKA_FN_HOST
~BufCpuImpl
()
59
{
60
ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
;
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>
77
friend
struct
alpaka::trait::GetExtents
;
78
79
template
<
typename
TBuf,
typename
TSfinae>
80
friend
struct
alpaka::trait::GetPtrNative
;
81
82
template
<
typename
TBuf,
typename
TDev,
typename
TSfinae>
83
friend
struct
alpaka::trait::GetPtrDev
;
84
};
85
}
// namespace alpaka::detail
ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
Definition
Debug.hpp:55
DevCpu.hpp
Vec.hpp
alpaka::DevCpu
The CPU device handle.
Definition
DevCpu.hpp:56
alpaka::Vec
A n-dimensional vector.
Definition
Vec.hpp:38
alpaka::detail::BufCpuImpl
The CPU memory buffer.
Definition
BufCpuImpl.hpp:21
alpaka::detail::BufCpuImpl::~BufCpuImpl
ALPAKA_FN_HOST ~BufCpuImpl()
Definition
BufCpuImpl.hpp:58
alpaka::detail::BufCpuImpl::BufCpuImpl
ALPAKA_FN_HOST BufCpuImpl(DevCpu dev, TElem *pMem, std::function< void(TElem *)> deleter, TExtent const &extent) noexcept
Definition
BufCpuImpl.hpp:30
alpaka::detail::BufCpuImpl::BufCpuImpl
BufCpuImpl(BufCpuImpl &&)=delete
alpaka::detail::BufCpuImpl::operator=
auto operator=(BufCpuImpl &&) -> BufCpuImpl &=delete
Common.hpp
ALPAKA_FN_HOST
#define ALPAKA_FN_HOST
Definition
Common.hpp:40
Traits.hpp
alpaka::detail
Definition
AccGpuUniformCudaHipRt.hpp:265
alpaka::Dim
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Definition
Traits.hpp:19
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::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
cpu
BufCpuImpl.hpp
Generated on Thu Jun 26 2025 08:02:45 for alpaka by
1.9.8