Peano
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
5#include "Device.h"
6
9
10#if !defined(GPUOffloadingOMP) and !defined(GPUOffloadingSYCL) and !defined(GPUOffloadingCPP)
11#define GPUOffloadingOff
12#endif
13
18
19namespace tarch {
20 #if defined(GPUOffloadingHIP)
21 #define GPUCallableMethod __host__ __device__
22 #elif defined(GPUOffloadingSYCL) or defined(SharedSYCL)
23 #define GPUCallableMethod SYCL_EXTERNAL
24 #elif defined(GPUOffloadingCPP) && defined(_NVHPC_STDPAR_GPU)
25 #define GPUCallableMethod __host__ __device__
26 #else
27 #define GPUCallableMethod
28 #endif
29
30 #if defined(GPUOffloadingHIP)
31 #define GPUCallableInlineMethod __host__ __device__ __forceinline__
32 #elif defined(GPUOffloadingSYCL) or defined(SharedSYCL)
33 #define GPUCallableInlineMethod inline
34 #elif defined(GPUOffloadingCPP) && defined(_NVHPC_STDPAR_GPU)
35 #define GPUCallableInlineMethod __host__ __device__ __forceinline__
36 #else
37 #define GPUCallableInlineMethod //inline
38 #endif
39
46#if defined(GPUOffloadingOMP)
47#pragma omp declare target
48 void gpuAbort();
49#pragma omp end declare target
50#elif defined(GPUOffloadingSYCL) or defined(SharedSYCL)
52#elif defined(GPUOffloadingCPP)
54#else
55 void gpuAbort();
56#endif
57
75
76 std::string toString(MemoryLocation value);
77
78 namespace internal {
79 void* allocateRawData(
80 std::size_t size,
81 MemoryLocation location,
82 int device
83 );
84 } // namespace internal
85
98 template <class T = double>
100 std::size_t count,
101 MemoryLocation location,
103) {
104 return reinterpret_cast<T*>(internal::allocateRawData(
105 count * sizeof(T),
106 location,
107 device
108 ));
109 }
110
120 void freeMemory(
121 void* data,
122 MemoryLocation location,
124 );
125
126 std::size_t padSizeToAlignment(std::size_t size, std::size_t alignment);
127
155 #if defined(GPUOffloadingOMP)
156 #pragma omp declare target
157 #endif
158 double* memset(double* dest, double ch, size_t byteCount);
159 #if defined(GPUOffloadingOMP)
160 #pragma omp end declare target
161 #endif
162} // namespace tarch
#define GPUCallableMethod
Definition accelerator.h:27
static constexpr int HostDevice
Accelerator devices (GPUs) are enumerated starting from 0.
Definition Device.h:48
void * allocateRawData(std::size_t size, MemoryLocation location, int device)
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19
double * memset(double *dest, double ch, size_t byteCount)
Alternative GPU-ready version of memset.
void freeMemory(void *data, MemoryLocation location, int device=accelerator::Device::HostDevice)
Free memory.
void gpuAbort()
Delegates to std::abort() if no GPU offloading is active.
std::size_t padSizeToAlignment(std::size_t size, std::size_t alignment)
std::string toString(MemoryLocation value)
MemoryLocation
Definition accelerator.h:58
@ Heap
Create data on the heap of the local device.
@ ManagedSharedAcceleratorDeviceMemory
To be used on host only.
T * allocateMemory(std::size_t count, MemoryLocation location, int device=accelerator::Device::HostDevice)
Allocates memory on the specified memory location.
Definition accelerator.h:99