11#include <kernel/util/cuda_util.hpp>
95 void memcopy_main(
void* dst,
const void* src, std::size_t bytes);
101 memcopy_main(dst, src, std::size_t(count) *
sizeof(T_));
120 template<
typename Tdst_,
typename Tsrc_>
123 if(count <=
Index(0))
131 const char* vdst =
reinterpret_cast<const char*
>(dst);
132 const char* vsrc =
reinterpret_cast<const char*
>(src);
133 XASSERTM((vdst < vsrc) || (vsrc + std::size_t(count)*
sizeof(Tsrc_) <= vdst),
"source and destination memory regions overlap");
134 XASSERTM((vsrc < vdst) || (vdst + std::size_t(count)*
sizeof(Tdst_) <= vsrc),
"source and destination memory regions overlap");
137 for(
Index i = 0u; i < count; ++i)
138 dst[i] = Tdst_(src[i]);
153 template<
typename T_>
156 if(count <=
Index(0))
161 for(
Index i = 0u; i < count; ++i)
169#if defined(FEAT_HAVE_CUDA) || defined(DOXYGEN)
197 void*
alloc_cuda_async(std::size_t bytes,
const Util::StreamWrapper& stream = Util::StreamWrapper{});
217 void free_cuda_async(
void* ptr,
const Util::StreamWrapper& stream = Util::StreamWrapper{});
234 void memset_cuda(
void* ptr,
int value, std::size_t bytes,
const Util::StreamWrapper& stream = Util::StreamWrapper{});
254 void memcopy_cuda(
void* dst,
const void* src, std::size_t bytes,
const Util::StreamWrapper& stream = Util::StreamWrapper{});
287 void memcopy_main_to_cuda(
void* dst,
const void* src, std::size_t bytes,
const Util::StreamWrapper& stream = Util::StreamWrapper{});
315 template<
typename Tdst_,
typename Tsrc_>
319 template<
typename T_>
322 memcopy_cuda(dst, src, std::size_t(count) *
sizeof(T_));
337 template<
typename T_>
346 XABORTM(
"Memory::alloc_cuda: CUDA is not available");
351 XABORTM(
"Memory::free_cuda: CUDA is not available");
356 XABORTM(
"Memory::memset_cuda: CUDA is not available");
359 inline void memcopy_cuda(
void*,
const void*, std::size_t)
361 XABORTM(
"Memory::memcopy_cuda: CUDA is not available");
366 XABORTM(
"Memory::memcopy_cuda_to_main: CUDA is not available");
371 XABORTM(
"Memory::memcopy_main_to_cuda: CUDA is not available");
374 template<
typename Tdst_,
typename Tsrc_>
377 XABORTM(
"Memory::convert_cuda: CUDA is not available");
380 template<
typename T_>
383 XABORTM(
"Memory::format_cuda: CUDA is not available");
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
void memcopy_main(void *dst, const void *src, std::size_t bytes)
Copies a region of a main memory block into another main memory block.
void format_cuda(T_ *dst, const T_ &value, const Index count)
Sets all entries of a cuda memory array to a given value.
void memcopy_main_to_cuda(void *dst, const void *src, std::size_t bytes, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Copies a region of a main memory block into a cuda memory block.
void convert_cuda(Tdst_ *dst, const Tsrc_ *src, const Index count)
Converts the elements of an array into element of another array of a different data type.
void memcopy_cuda_to_main(void *dst, const void *src, std::size_t bytes)
Copies a region of a cuda memory block into a main memory block.
void memset_main(void *ptr, int value, std::size_t bytes)
Formats all bytes of a memory block in main memory to a given value.
void * alloc_cuda(std::size_t bytes)
Allocate a memory block in cuda heap memory.
void memcopy_cuda(void *dst, const void *src, std::size_t bytes, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Copies a region of a cuda memory block into another cuda memory block.
void memset_cuda(void *ptr, int value, std::size_t bytes, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Formats all bytes of a memory block in cuda memory to a given value.
void free_main(void *ptr)
Frees a memory block in main heap memory allocated by alloc_main.
void convert_main(T_ *dst, const T_ *src, const Index count)
overload for Tdst_ = Tsrc_; performs a memcopy internally
void free_cuda(void *ptr)
Frees a memory block in cuda heap memory allocated by alloc_cuda.
void memset_random_main(void *ptr, std::size_t bytes, std::uint64_t seed=0u)
Formats all bytes of a memory block in main memory to random values.
void free_cuda_async(void *ptr, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Frees a memory block in cuda heap memory allocated by alloc_cuda.
void * alloc_main(std::size_t bytes)
Allocate a memory block in main heap memory.
void format_main(T_ *dst, const T_ &value, const Index count)
Sets all entries of a main memory array to a given value.
void * alloc_cuda_async(std::size_t bytes, const Util::StreamWrapper &stream=Util::StreamWrapper{})
Allocates stream ordered memory block in cuda heap memory.
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.