23 #include <type_traits>
31 template<
typename TElem,
typename TDim,
typename TIdx>
35 !std::is_const_v<TElem>,
36 "The elem type of the buffer can not be const because the C++ Standard forbids containers of const "
38 static_assert(!std::is_const_v<TIdx>,
"The idx type of the buffer can not be const!");
41 template<
typename TExtent>
45 std::function<
void(TElem*)> deleter,
46 TExtent
const& extent) noexcept
47 :
m_dev(std::move(dev))
56 "The dimensionality of TExtent and the dimensionality of the TDim template parameter have to be "
60 "The idx type of TExtent and the TIdx template parameter have to be identical!");
62 #if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
88 template<
typename TElem,
typename TDim,
typename TIdx>
92 template<
typename TExtent,
typename Deleter>
95 std::make_shared<detail::BufCpuImpl<TElem, TDim, TIdx>>(dev, pMem, std::move(deleter), extent)}
106 template<
typename TElem,
typename TDim,
typename TIdx>
113 template<
typename TElem,
typename TDim,
typename TIdx>
118 return buf.m_spBufCpuImpl->m_dev;
123 template<
typename TElem,
typename TDim,
typename TIdx>
130 template<
typename TElem,
typename TDim,
typename TIdx>
137 template<
typename TElem,
typename TDim,
typename TIdx>
147 template<
typename TElem,
typename TDim,
typename TIdx>
152 return buf.m_spBufCpuImpl->m_pMem;
157 return buf.m_spBufCpuImpl->m_pMem;
162 template<
typename TElem,
typename TDim,
typename TIdx>
170 return buf.m_spBufCpuImpl->m_pMem;
174 throw std::runtime_error(
"The buffer is not accessible from the given device!");
182 return buf.m_spBufCpuImpl->m_pMem;
186 throw std::runtime_error(
"The buffer is not accessible from the given device!");
192 template<
typename TElem,
typename TDim,
typename TIdx>
195 template<
typename TExtent>
203 #if defined(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT)
205 ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT > 0
206 && ((ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT & (ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT - 1)) == 0),
207 "If defined, ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT must be a power of 2.");
208 constexpr std::size_t alignment =
static_cast<std::size_t
>(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT);
214 static_assert(std::is_empty_v<Allocator>,
"AllocCpuAligned is expected to be stateless");
215 auto* memPtr = alpaka::malloc<TElem>(Allocator{},
static_cast<std::size_t
>(
getExtentProduct(extent)));
216 auto deleter = [](TElem* ptr) {
alpaka::free(Allocator{}, ptr); };
223 template<
typename TElem,
typename TDim,
typename TIdx>
226 template<
typename TQueue,
typename TExtent>
233 "The BufCpu buffer can only be used with a queue on a DevCpu device!");
239 #if defined(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT)
241 ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT > 0
242 && ((ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT & (ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT - 1)) == 0),
243 "If defined, ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT must be a power of 2.");
244 constexpr std::size_t alignment =
static_cast<std::size_t
>(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT);
250 static_assert(std::is_empty_v<Allocator>,
"AllocCpuAligned is expected to be stateless");
251 auto* memPtr = alpaka::malloc<TElem>(Allocator{},
static_cast<std::size_t
>(
getExtentProduct(extent)));
252 auto deleter = [l_queue = std::move(queue)](TElem* ptr)
mutable
268 template<
typename TDim>
274 template<
typename TElem,
typename TDim,
typename TIdx>
277 template<
typename TExtent>
284 return allocBuf<TElem, TIdx>(host, extent);
295 template<
typename TElem,
typename TDim,
typename TIdx>
305 template<
typename TElem,
typename TDim,
typename TIdx>
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
The CPU boost aligned allocator.
ALPAKA_FN_HOST BufCpu(DevCpu const &dev, TElem *pMem, Deleter deleter, TExtent const &extent)
std::shared_ptr< detail::BufCpuImpl< TElem, TDim, TIdx > > m_spBufCpuImpl
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto zeros() -> Vec< TDim, TVal >
Zero value constructor.
std::function< void(TElem *)> m_deleter
ALPAKA_FN_HOST ~BufCpuImpl()
ALPAKA_FN_HOST BufCpuImpl(DevCpu dev, TElem *pMem, std::function< void(TElem *)> deleter, TExtent const &extent) noexcept
Vec< TDim, TIdx > const m_extentElements
BufCpuImpl(BufCpuImpl &&)=delete
auto operator=(BufCpuImpl &&) -> BufCpuImpl &=delete
constexpr std::size_t defaultAlignment
The alpaka accelerator library.
typename trait::IdxType< T >::type Idx
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtentProduct(T const &object) -> Idx< T >
ALPAKA_FN_HOST auto free(TAlloc const &alloc, T const *const ptr) -> void
Frees the memory identified by the given pointer.
typename trait::DevType< T >::type Dev
The device type trait alias template to remove the ::type.
ALPAKA_FN_HOST auto getDev(T const &t)
ALPAKA_FN_HOST auto enqueue(TQueue &queue, TTask &&task) -> void
Queues the given task in the given queue.
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
static ALPAKA_FN_HOST auto allocAsyncBuf(TQueue queue, TExtent const &extent) -> BufCpu< TElem, TDim, TIdx >
The stream-ordered memory allocator trait.
The pinned/mapped memory allocator trait.
static ALPAKA_FN_HOST auto allocBuf(DevCpu const &dev, TExtent const &extent) -> BufCpu< TElem, TDim, TIdx >
The memory allocator trait.
The dimension getter type trait.
static ALPAKA_FN_HOST auto getDev(BufCpu< TElem, TDim, TIdx > const &buf) -> DevCpu
ALPAKA_FN_HOST auto operator()(BufCpu< TElem, TDim, TIdx > const &buf)
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
ALPAKA_FN_HOST auto operator()(BufCpu< TElem, TDim, TIdx > const &) const -> Vec< TDim, TIdx >
The GetOffsets trait for getting the offsets of an object as an alpaka::Vec.
static ALPAKA_FN_HOST auto getPtrDev(BufCpu< TElem, TDim, TIdx > &buf, DevCpu const &dev) -> TElem *
static ALPAKA_FN_HOST auto getPtrDev(BufCpu< TElem, TDim, TIdx > const &buf, DevCpu const &dev) -> TElem const *
The pointer on device get trait.
static ALPAKA_FN_HOST auto getPtrNative(BufCpu< TElem, TDim, TIdx > &buf) -> TElem *
static ALPAKA_FN_HOST auto getPtrNative(BufCpu< TElem, TDim, TIdx > const &buf) -> TElem const *
The native pointer get trait.
The stream-ordered memory allocation capability trait.
The pinned/mapped memory allocation capability trait.