11void gpu_memory_pool_alloc(
void **p,
size_t req_size);
12void gpu_memory_pool_free(
void *ptr);
13void gpu_memory_pool_purge();
14void gpu_memory_pool_report();
21void seed_device_rng(
unsigned long long seed);
39#include <cuda_runtime.h>
45using gpuError = cudaError;
46#define gpuSuccess cudaSuccess
51#define gpuMalloc(a, b) gpu_memory_pool_alloc((void **)a, b)
52#define gpuFree(a) gpu_memory_pool_free(a)
53#define gpuMemPoolPurge() gpu_memory_pool_purge()
54#define gpuMemPoolReport() gpu_memory_pool_report()
60#define gpuMemPoolPurge() do { } while (0)
61#define gpuMemPoolReport() do { } while (0)
64#ifdef CUDA_MALLOC_ASYNC
65#define gpuMalloc(a, b) GPU_CHECK(cudaMallocAsync(a, b, 0))
66#define gpuFree(a) GPU_CHECK(cudaFreeAsync(a, 0))
69#define gpuMalloc(a, b) GPU_CHECK(cudaMalloc((void **)a, b))
70#define gpuFree(a) GPU_CHECK(cudaFree(a))
78#define gpuGetLastError cudaGetLastError
79#define gpuMemcpy(a, b, c, d) GPU_CHECK(cudaMemcpy(a, b, c, d))
80#define gpuMemcpyHostToDevice cudaMemcpyHostToDevice
81#define gpuMemcpyDeviceToHost cudaMemcpyDeviceToHost
82#define gpuDeviceSynchronize() GPU_CHECK(cudaDeviceSynchronize())
83#define gpuStreamSynchronize(a) GPU_CHECK(cudaStreamSynchronize(a))
84#define gpuMemset(a,b,c) GPU_CHECK(cudaMemset(a,b,c))
86#define GPUTYPESTR "CUDA"
89#define __GPU_DEVICE_COMPILE__ __CUDA_ARCH__
97#include <hip/hip_runtime.h>
98#include <hiprand/hiprand.h>
105using gpuError = hipError_t;
106#define gpuSuccess hipSuccess
110#ifdef GPU_MEMORY_POOL
111#define gpuMalloc(a, b) gpu_memory_pool_alloc((void **)a, b)
112#define gpuFree(a) gpu_memory_pool_free(a)
113#define gpuMemPoolPurge() gpu_memory_pool_purge()
114#define gpuMemPoolReport() gpu_memory_pool_report()
121#define gpuMemPoolPurge() do {} while (0)
122#define gpuMemPoolReport() do {} while (0)
125#define gpuMalloc(a, b) GPU_CHECK(hipMalloc((void **)a, b))
126#define gpuFree(a) GPU_CHECK(hipFree(a))
130#define gpuGetLastError hipGetLastError
131#define gpuMemcpy(a, b, siz, d) GPU_CHECK(hipMemcpy(a, b, siz, d))
132#define gpuMemcpyHostToDevice hipMemcpyHostToDevice
133#define gpuMemcpyDeviceToHost hipMemcpyDeviceToHost
134#define gpuDeviceSynchronize() GPU_CHECK(hipDeviceSynchronize())
135#define gpuStreamSynchronize(a) GPU_CHECK(hipStreamSynchronize(a))
136#define gpuMemset(a,b,c) GPU_CHECK(hipMemset(a,b,c))
138#define GPUTYPESTR "HIP"
140#ifdef __HIP_DEVICE_COMPILE__
141#define __GPU_DEVICE_COMPILE__ __HIP_DEVICE_COMPILE__
150#define GPU_CHECK(cmd) \
153 gpu_exit_on_error(code, #cmd, __FILE__, __LINE__); \
156#define check_device_error(msg) gpu_exit_on_error(msg, __FILE__, __LINE__)
157#define check_device_error_code(code, msg) \
158 gpu_exit_on_error(code, msg, __FILE__, __LINE__)
159void gpu_exit_on_error(
const char *msg,
const char *file,
int line);
160void gpu_exit_on_error(gpuError code,
const char *msg,
const char *file,
int line);
163inline void synchronize_threads() {
164 gpuDeviceSynchronize();
179#define gpuMalloc(a, b) do {} while(0)
180#define gpuFree(a) do {} while(0)
181#define gpuMemcpy(a, b, siz, d) do {} while(0)
182#define gpuMemPoolPurge() do {} while(0)
183#define gpuMemPoolReport() do {} while(0)
185#define check_device_error(msg) do {} while(0)
186#define check_device_error_code(code, msg) do {} while(0)
188#define gpuStreamSynchronize(a) do {} while(0)
189#define gpuDeviceSynchronize() do {} while(0)
193#define GPUTYPESTR "NONE"
196inline void synchronize_threads() {}
202void initialize_gpu(
int rank,
int device);
203void gpu_device_info();
214struct is_arithmetic : std::integral_constant<bool, std::is_arithmetic<T>::value> {};
216template <
class T,
class U>
217struct is_assignable : std::integral_constant<bool, std::is_assignable<T, U>::value> {};
220struct is_floating_point
221 : std::integral_constant<bool, std::is_floating_point<T>::value> {};
Invert diagonal + const. matrix using Sherman-Morrison formula.
void free_device_rng()
Free GPU RNG state, does nothing on non-GPU archs.