NAMD
DeviceCUDAkernel.cu
Go to the documentation of this file.
1 #include <stdio.h>
2 #include "CudaUtils.h"
3 
4 #ifdef NAMD_CUDA
5 #include <cuda.h>
6 
7 __global__ void read_CUDA_ARCH_kernel(int *cuda_arch) {
8  if (threadIdx.x == 0) {
9 
10 #if __CUDA_ARCH__ == 100
11  *cuda_arch = 100;
12 #elif __CUDA_ARCH__ == 110
13  *cuda_arch = 110;
14 #elif __CUDA_ARCH__ == 120
15  *cuda_arch = 120;
16 #elif __CUDA_ARCH__ == 130
17  *cuda_arch = 130;
18 #elif __CUDA_ARCH__ == 200
19  *cuda_arch = 200;
20 #elif __CUDA_ARCH__ == 210
21  *cuda_arch = 210;
22 #elif __CUDA_ARCH__ == 300
23  *cuda_arch = 300;
24 #elif __CUDA_ARCH__ == 350
25  *cuda_arch = 350;
26 #elif __CUDA_ARCH__ == 500
27  *cuda_arch = 500;
28 #else
29  *cuda_arch = 500;
30 #endif
31 
32  }
33 }
34 
35 //
36 // Reads the value of __CUDA_ARCH__ from device code
37 //
39  int *d_cuda_arch;
40  int h_cuda_arch;
41  allocate_device<int>(&d_cuda_arch, 1);
42 
43  read_CUDA_ARCH_kernel <<< 1, 1 >>> (d_cuda_arch);
44  cudaError_t err = cudaGetLastError();
45  if (err != cudaSuccess) {
46  char str[1024];
47  sprintf(str, "Error executing CUDA kernel read_CUDA_ARCH_kernel in file %s\nError string: %s\nPossible cause: Device compute capability is less than the compute capability the code was compiled for.\n",
48  __FILE__,cudaGetErrorString(err));
49  cudaDie(str);
50  }
51  cudaCheck(cudaDeviceSynchronize());
52 
53  copy_DtoH_sync<int>(d_cuda_arch, &h_cuda_arch, 1);
54  deallocate_device<int>(&d_cuda_arch);
55 
56  return h_cuda_arch;
57 }
58 
59 #endif // NAMD_CUDA
__global__ void read_CUDA_ARCH_kernel(int *cuda_arch)
void cudaDie(const char *msg, cudaError_t err=cudaSuccess)
Definition: CudaUtils.C:9
int read_CUDA_ARCH()
#define cudaCheck(stmt)
Definition: CudaUtils.h:95