Peano 4
Loading...
Searching...
No Matches
accelerator.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
7
8#if !defined(GPUOffloadingOMP) and !defined(GPUOffloadingSYCL) and !defined(GPUOffloadingCPP) and !defined(GPUOffloadingCUDA)
9#define GPUOffloadingOff
10#endif
11
16
17namespace tarch {
18 #if defined(GPUOffloadingHIP)
19 #define GPUCallableMethod __host__ __device__
20 #elif defined(GPUOffloadingSYCL) or defined(SharedSYCL)
21 #define GPUCallableMethod SYCL_EXTERNAL
22 #elif defined(GPUOffloadingCPP) && defined(_NVHPC_STDPAR_GPU)
23 #define GPUCallableMethod __host__ __device__
24 #else
25 #define GPUCallableMethod
26 #endif
27
28 #if defined(GPUOffloadingHIP)
29 #define GPUCallableInlineMethod __host__ __device__ __forceinline__
30 #elif defined(GPUOffloadingSYCL) or defined(SharedSYCL)
31 #define GPUCallableInlineMethod inline
32 #elif defined(GPUOffloadingCPP) && defined(_NVHPC_STDPAR_GPU)
33 #define GPUCallableInlineMethod __host__ __device__ __forceinline__
34 #else
35 #define GPUCallableInlineMethod //inline
36 #endif
37
44#if defined(GPUOffloadingOMP)
45#pragma omp declare target
46 void gpuAbort();
47#pragma omp end declare target
48#elif defined(GPUOffloadingSYCL) or defined(SharedSYCL)
50#elif defined(GPUOffloadingCPP)
52#else
53 void gpuAbort();
54#endif
55
73
74 std::string toString(MemoryLocation value);
75
76
77 namespace internal {
78 void* allocateRawData(int size, MemoryLocation location);
79 } // namespace internal
80
81 template <class T = double>
82 T* allocateMemory(int size, MemoryLocation location, [[maybe_unused]] int device = -1) {
83 return reinterpret_cast<T*>(internal::allocateRawData(size * static_cast<int>(sizeof(T)), location));
84 }
85 void freeMemory(void* data, MemoryLocation location);
86
87 int padSizeToAlignment(int size, int aligment);
88
116 #if defined(GPUOffloadingOMP)
117 #pragma omp declare target
118 #endif
119 double* memset(double* dest, double ch, size_t byteCount);
120 #if defined(GPUOffloadingOMP)
121 #pragma omp end declare target
122 #endif
123} // namespace tarch
#define GPUCallableMethod
Definition accelerator.h:25
void * allocateRawData(int size, MemoryLocation location)
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:17
double * memset(double *dest, double ch, size_t byteCount)
Alternative GPU-ready version of memset.
void gpuAbort()
Delegates to std::abort() if no GPU offloading is active.
std::string toString(MemoryLocation value)
void freeMemory(void *data, MemoryLocation location)
MemoryLocation
Definition accelerator.h:56
@ Heap
Create data on the heap of the local device.
@ ManagedSharedAcceleratorDeviceMemory
To be used on host only.
int padSizeToAlignment(int size, int aligment)
T * allocateMemory(int size, MemoryLocation location, int device=-1)
Definition accelerator.h:82