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 float free_m, total_m,used_m;
46 size_t free_t, total_t;
48 cudaMemGetInfo(&free_t, &total_t);
51 free_m =
static_cast<uint
>(free_t)/1048576.0;
52 total_m =
static_cast<uint
>(total_t)/1048576.0;
53 used_m = total_m - free_m;
55 printf(
" Memory free %f MB, total memory %f MB, memory used %f MB\n", free_m, total_m, used_m);
63 cudaGetDeviceCount(&nDevices);
67 printf(
"No CUDA devices found");
71 printf(
" Found %i GPUs, currently I only support one GPU\n", nDevices);
89 cudaGetDeviceCount(&deviceCount);
90 if (deviceId < 0 || deviceId >= deviceCount) {
91 printf(
"Invalid device ID: %i \n", deviceId);
95 cudaSetDevice(deviceId);
97 printf(
"GPU device set to ID: %i \n", deviceId);
105 cudaGetDeviceCount(&deviceCount);
107 if (deviceCount == 0) {
108 printf(
"No CUDA devices found");
112 cudaDeviceProp deviceProp;
113 cudaGetDeviceProperties(&deviceProp, Device);
116 int nThreadsBlocks = (deviceProp.multiProcessorCount * deviceProp.maxThreadsPerMultiProcessor);
118 return nThreadsBlocks;
125 cudaError_t err = cudaGetDeviceProperties(&prop, device);
126 if (err != cudaSuccess) {
127 printf(
"No CUDA devices found");
130 return prop.l2CacheSize;
137 cudaError_t err = cudaGetDeviceProperties(&prop, device);
138 if (err != cudaSuccess) {
139 printf(
"No CUDA devices found");
142 return prop.maxTexture1D;
149 cudaError_t err = cudaGetDeviceProperties(&prop, device);
151 if (err != cudaSuccess) {
152 printf(
"No CUDA devices found");
155 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.