14 template<
typename TElem,
typename TDim,
typename TIdx>
21 template<
typename TElem,
typename TDim,
typename TIdx>
28 template<
typename TElem,
typename TDim,
typename TIdx>
33 return buf.m_spBufImpl->m_dev;
38 template<
typename TElem,
typename TDim,
typename TIdx>
45 template<
typename TElem,
typename TDim,
typename TIdx>
52 template<
typename TElem,
typename TDim,
typename TIdx>
62 template<
typename TElem,
typename TDim,
typename TIdx>
67 return buf.m_spBufImpl->m_pMem;
72 return buf.m_spBufImpl->m_pMem;
77 template<
typename TElem,
typename TDim,
typename TIdx>
84 return buf.m_spBufImpl->m_pMem;
88 throw std::runtime_error(
"The buffer is not accessible from the given device!");
96 return buf.m_spBufImpl->m_pMem;
100 throw std::runtime_error(
"The buffer is not accessible from the given device!");
106 template<
typename TElem,
typename TDim,
typename TIdx>
116 template<
typename TElem,
typename TDim,
typename TIdx>
123 template<
typename TElem,
typename TDim,
typename TIdx>
138 template<
typename TElem,
typename TDim,
typename TIdx>
141 template<
typename TExtent>
149#if defined(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT)
151 ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT > 0
152 && ((ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT & (ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT - 1)) == 0),
153 "If defined, ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT must be a power of 2.");
154 constexpr std::size_t alignment =
static_cast<std::size_t
>(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT);
160 static_assert(std::is_empty_v<Allocator>,
"AllocCpuAligned is expected to be stateless");
162 auto deleter = [](TElem* ptr) {
alpaka::free(Allocator{}, ptr); };
169 template<
typename TElem,
typename TDim,
typename TIdx,
typename TAllocator>
172 template<
typename TExtent>
178 std::size_t
const bytes =
static_cast<std::size_t
>(
getExtentProduct(extent)) *
sizeof(TElem);
179 void*
const memPtr = allocator.allocate(bytes,
alignof(TElem));
180 auto deleter = [alloc = std::move(allocator)](TElem* ptr)
mutable { alloc.deallocate(ptr); };
186 template<
typename TDim>
192 template<
typename TElem,
typename TDim,
typename TIdx,
typename TAllocator>
195 template<
typename TQueue,
typename TExtent>
202 std::is_same_v<Dev<TQueue>,
DevCpu>,
203 "The BufCpu buffer can only be used with a queue on a DevCpu device!");
204 auto const dev =
getDev(queue);
205 std::size_t
const bytes =
static_cast<std::size_t
>(
getExtentProduct(extent)) *
sizeof(TElem);
206 void*
const memPtr = allocator.allocate(bytes,
alignof(TElem));
207 auto deleter = [l_queue = std::move(queue), alloc = std::move(allocator)](TElem* ptr)
mutable
208 {
alpaka::enqueue(l_queue, [ptr, alloc]()
mutable { alloc.deallocate(ptr); }); };
214 template<
typename TElem,
typename TDim,
typename TIdx>
217 template<
typename TQueue,
typename TExtent>
223 std::is_same_v<Dev<TQueue>,
DevCpu>,
224 "The BufCpu buffer can only be used with a queue on a DevCpu device!");
230#if defined(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT)
232 ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT > 0
233 && ((ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT & (ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT - 1)) == 0),
234 "If defined, ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT must be a power of 2.");
235 constexpr std::size_t alignment =
static_cast<std::size_t
>(ALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT);
241 static_assert(std::is_empty_v<Allocator>,
"AllocCpuAligned is expected to be stateless");
243 auto deleter = [l_queue = std::move(queue)](TElem* ptr)
mutable
265 template<
typename TElem,
typename TDim,
typename TIdx>
268 template<
typename TExtent>
280 template<
typename TElem,
typename TDim,
typename TIdx>
283 template<
typename TExtent>
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
The CPU boost aligned allocator.
The CPU memory buffer template implementing muting accessors.
std::shared_ptr< TBufImpl > m_spBufImpl
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto zeros() -> Vec< TDim, TVal >
Zero value constructor.
constexpr std::size_t defaultAlignment
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.
ALPAKA_FN_HOST auto malloc(TAlloc const &alloc, std::size_t const &sizeElems) -> T *
ALPAKA_FN_HOST auto allocBuf(TDev const &dev, TExtent const &extent=TExtent())
Allocates memory on the given device.
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.
static ALPAKA_FN_HOST auto allocAsyncBuf(TQueue queue, TExtent const &extent, TAllocator allocator) -> BufCpu< TElem, TDim, TIdx >
The allocator-aware stream-ordered memory allocator trait.
static ALPAKA_FN_HOST auto allocAsyncBuf(TQueue queue, TExtent const &extent) -> BufCpu< TElem, TDim, TIdx >
The stream-ordered memory allocator trait.
The managed (unified) memory allocator trait.
The pinned/mapped memory allocator trait.
static ALPAKA_FN_HOST auto allocBuf(DevCpu const &dev, TExtent const &extent, TAllocator allocator) -> BufCpu< TElem, TDim, TIdx >
The allocator-aware memory allocator trait.
static ALPAKA_FN_HOST auto allocBuf(DevCpu const &dev, TExtent const &extent) -> BufCpu< TElem, TDim, TIdx >
The memory allocator trait.
The memory buffer type 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.
static ALPAKA_FN_HOST auto makeConstBuf(BufCpu< TElem, TDim, TIdx > &&buf) -> ConstBufCpu< TElem, TDim, TIdx >
static ALPAKA_FN_HOST auto makeConstBuf(BufCpu< TElem, TDim, TIdx > const &buf) -> ConstBufCpu< TElem, TDim, TIdx >
The trait to transform a mutable buffer into a constant one.