Easiest way to test for existence of cuda-capable GPU from cmake?

前端 未结 5 2030
一个人的身影
一个人的身影 2020-12-30 06:10

We have some nightly build machines that have the cuda libraries installed, but which do not have a cuda-capable GPU installed. These machines are capable of building cuda-

5条回答
  •  甜味超标
    2020-12-30 06:44

    You can compile small GPU query program if cuda was found. here is a simple one you can adopt the needs:

    #include 
    #include 
    #include 
    #include 
    
    int main(int argc, char** argv) {
      int ct,dev;
      cudaError_t code;
      struct cudaDeviceProp prop;
    
     cudaGetDeviceCount(&ct);
     code = cudaGetLastError();
     if(code)  printf("%s\n", cudaGetErrorString(code));
    
    
    if(ct == 0) {
       printf("Cuda device not found.\n");
       exit(0);
    }
     printf("Found %i Cuda device(s).\n",ct);
    
    for (dev = 0; dev < ct; ++dev) {
    printf("Cuda device %i\n", dev);
    
    cudaGetDeviceProperties(&prop,dev);
    printf("\tname : %s\n", prop.name);
     printf("\ttotalGlobablMem: %lu\n", (unsigned long)prop.totalGlobalMem);
    printf("\tsharedMemPerBlock: %i\n", prop.sharedMemPerBlock);
    printf("\tregsPerBlock: %i\n", prop.regsPerBlock);
    printf("\twarpSize: %i\n", prop.warpSize);
    printf("\tmemPitch: %i\n", prop.memPitch);
    printf("\tmaxThreadsPerBlock: %i\n", prop.maxThreadsPerBlock);
    printf("\tmaxThreadsDim: %i, %i, %i\n", prop.maxThreadsDim[0], prop.maxThreadsDim[1], prop.maxThreadsDim[2]);
    printf("\tmaxGridSize: %i, %i, %i\n", prop.maxGridSize[0], prop.maxGridSize[1], prop.maxGridSize[2]);
    printf("\tclockRate: %i\n", prop.clockRate);
    printf("\ttotalConstMem: %i\n", prop.totalConstMem);
    printf("\tmajor: %i\n", prop.major);
    printf("\tminor: %i\n", prop.minor);
    printf("\ttextureAlignment: %i\n", prop.textureAlignment);
    printf("\tdeviceOverlap: %i\n", prop.deviceOverlap);
    printf("\tmultiProcessorCount: %i\n", prop.multiProcessorCount);
    }
    }
    

提交回复
热议问题