8 #ifdef CUDA_ERROR_CHECK
9 if (cudaSuccess != err) {
10 fprintf(stderr,
"%s failed at %s:%i : %s\n", __func__, file, line, cudaGetErrorString(err));
20 #ifdef CUDA_ERROR_CHECK
21 cudaError err = cudaGetLastError();
22 if (cudaSuccess != err) {
23 fprintf(stderr,
"%s failed at %s:%i : %s\n", __func__, file, line, cudaGetErrorString(err));
29 err = cudaDeviceSynchronize();
30 if (cudaSuccess != err) {
31 fprintf(stderr,
"%s with sync failed at %s:%i : %s\n", __func__, file, line, cudaGetErrorString(err));
45 size_t free_t, total_t;
46 cudaMemGetInfo(&free_t, &total_t);
49 double free_m =
static_cast<double>(free_t) / 1024.0 / 1024.0;
50 double total_m =
static_cast<double>(total_t) / 1024.0 / 1024.0;
51 double used_m = total_m - free_m;
53 printf(
" Memory free %f MB, total memory %f MB, memory used %f MB\n", free_m, total_m, used_m);
61 cudaGetDeviceCount(&nDevices);
65 printf(
"No CUDA devices found");
69 printf(
" Found %i GPUs, currently I only support one GPU\n", nDevices);
87 cudaGetDeviceCount(&deviceCount);
88 if (deviceId < 0 || deviceId >= deviceCount) {
89 printf(
"Invalid device ID: %i \n", deviceId);
93 cudaSetDevice(deviceId);
95 printf(
"GPU device set to ID: %i \n", deviceId);
103 cudaGetDeviceCount(&deviceCount);
105 if (deviceCount == 0) {
106 printf(
"No CUDA devices found");
110 cudaDeviceProp deviceProp;
111 cudaGetDeviceProperties(&deviceProp, Device);
114 int nThreadsBlocks = (deviceProp.multiProcessorCount * deviceProp.maxThreadsPerMultiProcessor);
116 return nThreadsBlocks;
123 cudaError_t err = cudaGetDeviceProperties(&prop, device);
124 if (err != cudaSuccess) {
125 printf(
"No CUDA devices found");
128 return prop.l2CacheSize;
135 cudaError_t err = cudaGetDeviceProperties(&prop, device);
136 if (err != cudaSuccess) {
137 printf(
"No CUDA devices found");
140 return prop.maxTexture1D;
147 cudaError_t err = cudaGetDeviceProperties(&prop, device);
149 if (err != cudaSuccess) {
150 printf(
"No CUDA devices found");
153 return static_cast<size_t>(prop.sharedMemPerBlock);
void __cudaCheckError(const char *file, const int line)
Check if there's been an error.
size_t GetMaxTexture1DSize(const int device)
KS: Get the maximum size for 1D textures on the specified GPU device.
void SetDevice(const int deviceId)
Only useful if using multiple GPU.
void ResetDevice()
KS: Completely clean GPU, this is time consuming and may lead to unexpected behaviour.
void checkGpuMem()
KS: Get some fancy info about VRAM usage.
int GetNumGPUThreads(const int Device)
KS: Get number of GPU threads for currently used GPU.
size_t GetL2CacheSize(const int device)
KS: Get L2 cache size (in bytes) for the specified GPU device.
void PrintNdevices()
KS: Get some fancy info about GPU.
void __cudaSafeCall(cudaError err, const char *file, const int line)
Check for a safe call on GPU.
size_t GetSharedMemoryPerBlock(const int device)
KS: Returns the maximum shared memory per block for a given GPU device.
Common CUDA utilities and definitions for shared GPU functionality.