45#if defined(NEKTAR_ENABLE_CUDA)
46extern bool isSetDeviceMemoryPool;
47#elif defined(NEKTAR_ENABLE_HIP)
48extern bool isSetDeviceMemoryPool;
71#if defined(NEKTAR_ENABLE_CUDA)
72 if (!isSetDeviceMemoryPool)
75 cudaMemPool_t mempool;
79 mempool, cudaMemPoolAttrReleaseThreshold, &threshold));
81#elif defined(NEKTAR_ENABLE_HIP)
82 if (!isSetDeviceMemoryPool)
89 mempool, hipMemPoolAttrReleaseThreshold, &threshold));
94template <
typename TData>
96 const unsigned int streamID);
98template <
typename TData>
100 const size_t compSize,
const size_t nelmt,
101 const unsigned int ndata,
102 const unsigned int width,
103 const unsigned int streamID);
105template <
typename TData>
107 [[maybe_unused]]
const size_t alignment)
111 *src =
static_cast<TData *
>(
112 ::operator
new[](size, std::align_val_t(alignment)));
120template <
typename TData>
125#if defined(NEKTAR_ENABLE_CUDA)
127#elif defined(NEKTAR_ENABLE_HIP)
129#elif defined(NEKTAR_ENABLE_SYCL)
131 *src = (TData *)sycl::malloc_host(size, Q);
132#if defined(SYCL_ENABLE_CPU)
136 *src = (TData *)malloc(size);
145template <
typename TData>
147 TData **src,
const size_t size,
148 [[maybe_unused]]
const unsigned int streamID,
153#if defined(NEKTAR_ENABLE_CUDA)
160 GetDeviceProperties::CheckGlobalMemoryUsage(size);
162 GetDeviceProperties::TotalGlobalMemory() -= size;
166 GetDeviceProperties::CheckGlobalMemoryUsage(size);
168 GetDeviceProperties::TotalGlobalMemory() -= size;
170#elif defined(NEKTAR_ENABLE_HIP)
177 GetDeviceProperties::CheckGlobalMemoryUsage(size);
179 GetDeviceProperties::TotalGlobalMemory() -= size;
183 GetDeviceProperties::CheckGlobalMemoryUsage(size);
185 GetDeviceProperties::TotalGlobalMemory() -= size;
187#elif defined(NEKTAR_ENABLE_SYCL)
188 GetDeviceProperties::CheckGlobalMemoryUsage(size);
190 *src = (TData *)sycl::malloc_device(size, Q);
191 GetDeviceProperties::TotalGlobalMemory() -= size;
192#if defined(SYCL_ENABLE_CPU)
196 *src = (TData *)malloc(size);
205template <
typename TData>
206inline void hostFree(TData *src, [[maybe_unused]]
const size_t alignment)
213 operator delete[](src, std::align_val_t(alignment));
223#if defined(NEKTAR_ENABLE_CUDA)
225#elif defined(NEKTAR_ENABLE_HIP)
227#elif defined(NEKTAR_ENABLE_SYCL)
236template <
typename TData>
238 TData *src, [[maybe_unused]]
const size_t size,
239 [[maybe_unused]]
const unsigned int streamID,
247#if defined(NEKTAR_ENABLE_CUDA)
253 GetDeviceProperties::TotalGlobalMemory() += size;
258 GetDeviceProperties::TotalGlobalMemory() += size;
260#elif defined(NEKTAR_ENABLE_HIP)
266 GetDeviceProperties::TotalGlobalMemory() += size;
271 GetDeviceProperties::TotalGlobalMemory() += size;
273#elif defined(NEKTAR_ENABLE_SYCL)
284 for (
auto &item : Queues)
290 GetDeviceProperties::TotalGlobalMemory() += size;
296template <
typename TData>
298 [[maybe_unused]]
const unsigned int streamID)
305#if defined(NEKTAR_ENABLE_CUDA)
308#elif defined(NEKTAR_ENABLE_HIP)
311#elif defined(NEKTAR_ENABLE_SYCL)
313 sycl::event e = Q.submit([&](sycl::handler &cgh) {
314 setSYCLDefaultExecutionDependency(streamID, cgh);
315 cgh.memset((
void *)dst, val, size);
319 memset((
void *)dst, val, size);
323template <
typename TData>
324inline void deviceFill(TData *dst,
const TData val,
const size_t size,
325 [[maybe_unused]]
const unsigned int streamID)
332#if defined(NEKTAR_ENABLE_CUDA)
334#elif defined(NEKTAR_ENABLE_HIP)
336#elif defined(NEKTAR_ENABLE_SYCL)
338 sycl::event e = Q.submit([&](sycl::handler &cgh) {
339 setSYCLDefaultExecutionDependency(streamID, cgh);
340 cgh.fill(dst, val, size);
344 std::fill(dst, dst + size, val);
352template <
typename TData>
354 const size_t compSize,
const size_t nelmt,
355 const unsigned int ndata,
const unsigned int width)
357 const size_t group0 = nelmt / width;
358 const unsigned int lane0 = nelmt % width;
359 for (
unsigned int n = 0; n < ncomp; ++n, dst += compSize)
363 TData *ptr = dst + group0 * ndata * width;
364 for (
unsigned int pt = 0; lane0 != 0 && pt < ndata; ++pt, ptr += width)
366 std::fill(ptr + lane0, ptr + width, TData(0));
368 std::fill(ptr, dst + compSize, TData(0));
372template <
typename TData>
374 const size_t compSize,
const size_t nelmt,
375 const unsigned int ndata,
376 const unsigned int width,
377 [[maybe_unused]]
const unsigned int streamID)
379 const size_t prefix = (nelmt / width) * width * ndata;
380 if (prefix == compSize)
385#if defined(NEKTAR_ENABLE_CUDA) || defined(NEKTAR_ENABLE_HIP)
388#elif defined(NEKTAR_ENABLE_SYCL)
389 const size_t tail = compSize - prefix;
391 sycl::event e = Q.submit([=](sycl::handler &cgh) {
392 setSYCLDefaultExecutionDependency(streamID, cgh);
393 cgh.parallel_for(sycl::range<1>(ncomp * tail), [=](sycl::id<1> indx) {
394 const size_t idx = indx[0];
395 const size_t i = prefix + idx % tail;
396 if ((i / (ndata * width)) * width + i % width >= nelmt)
398 dst[(idx / tail) * compSize + i] = TData(0);
408template <MemCopyType MemCopy,
typename TData>
409inline void deviceMemcpy(TData *dst,
const TData *src,
const size_t size,
410 [[maybe_unused]]
const unsigned int streamID)
419 memcpy(dst, src, size);
423#if defined(NEKTAR_ENABLE_CUDA)
426 cudaMemcpyAsync(dst, src, size, cudaMemcpyDeviceToHost, stream));
428#elif defined(NEKTAR_ENABLE_HIP)
431 hipMemcpyAsync(dst, src, size, hipMemcpyDeviceToHost, stream));
433#elif defined(NEKTAR_ENABLE_SYCL)
435 sycl::event e = Q.submit([&](sycl::handler &cgh) {
436 setSYCLDefaultExecutionDependency(streamID, cgh);
437 cgh.memcpy(dst, src, size);
442 memcpy(dst, src, size);
447#if defined(NEKTAR_ENABLE_CUDA)
450 cudaMemcpyAsync(dst, src, size, cudaMemcpyHostToDevice, stream));
451#elif defined(NEKTAR_ENABLE_HIP)
454 hipMemcpyAsync(dst, src, size, hipMemcpyHostToDevice, stream));
455#elif defined(NEKTAR_ENABLE_SYCL)
457 sycl::event e = Q.submit([&](sycl::handler &cgh) {
458 setSYCLDefaultExecutionDependency(streamID, cgh);
459 cgh.memcpy(dst, src, size);
463 memcpy(dst, src, size);
468#if defined(NEKTAR_ENABLE_CUDA)
471 cudaMemcpyAsync(dst, src, size, cudaMemcpyDeviceToDevice, stream));
472#elif defined(NEKTAR_ENABLE_HIP)
475 hipMemcpyAsync(dst, src, size, hipMemcpyDeviceToDevice, stream));
476#elif defined(NEKTAR_ENABLE_SYCL)
478 sycl::event e = Q.submit([&](sycl::handler &cgh) {
479 setSYCLDefaultExecutionDependency(streamID, cgh);
480 cgh.memcpy(dst, src, size);
484 memcpy(dst, src, size);
#define CHECK_HIPCUDA_ERROR(err)
static cudaStream_t & GetInstance(unsigned int id)
static hipStream_t & GetInstance(unsigned int id)
static std::unordered_map< unsigned int, sycl::queue * > & GetAllInstances(void)
static sycl::queue & GetInstance(unsigned int id)
static void SetEvent(unsigned int id, sycl::event &e)
void deviceFree(TData *src, const size_t size, const unsigned int streamID, const MemAllocType memAllocType=eHostPageable)
void hostFreePinned(TData *src)
void hostFree(TData *src, const size_t alignment)
static unsigned int nekGetDevice()
void deviceZeroPadding(TData *dst, const unsigned int ncomp, const size_t compSize, const size_t nelmt, const unsigned int ndata, const unsigned int width, const unsigned int streamID)
void deviceMemset(TData *dst, const int val, const size_t size, const unsigned int streamID)
void hostZeroPadding(TData *dst, const unsigned int ncomp, const size_t compSize, const size_t nelmt, const unsigned int ndata, const unsigned int width)
void deviceFillKernelLauncher(TData *dst, const TData val, const size_t size, const unsigned int streamID)
void deviceMalloc(TData **src, const size_t size, const unsigned int streamID, const MemAllocType memAllocType=eHostPageable)
static void SetDeviceMemoryPool(void)
@ eHostPinnedDeviceMemoryPool
void deviceFill(TData *dst, const TData val, const size_t size, const unsigned int streamID)
void deviceMemcpy(TData *dst, const TData *src, const size_t size, const unsigned int streamID)
void hostMallocPinned(TData **src, const size_t size)
void deviceZeroPaddingKernelLauncher(TData *dst, const unsigned int ncomp, const size_t compSize, const size_t nelmt, const unsigned int ndata, const unsigned int width, const unsigned int streamID)
void hostMalloc(TData **src, const size_t size, const size_t alignment)