Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /HeterogeneousCore/CUDAUtilities/bin/isCudaDeviceSupported.cu is written in an unsupported language. File is not indexed.

0001 #include <cuda_runtime.h>
0002 
0003 #include "isCudaDeviceSupported.h"
0004 
0005 __global__ static void setSupported(bool* result) { *result = true; }
0006 
0007 bool isCudaDeviceSupported(int device) {
0008   bool supported = false;
0009   bool* supported_d;
0010 
0011   // select the requested device - will fail if the index is invalid
0012   cudaError_t status = cudaSetDevice(device);
0013   if (status != cudaSuccess)
0014     return false;
0015 
0016   // allocate memory for the flag on the device
0017   status = cudaMalloc(&supported_d, sizeof(bool));
0018   if (status != cudaSuccess)
0019     return false;
0020 
0021   // initialise the flag on the device
0022   status = cudaMemset(supported_d, 0x00, sizeof(bool));
0023   if (status != cudaSuccess)
0024     return false;
0025 
0026   // try to set the flag on the device
0027   setSupported<<<1, 1>>>(supported_d);
0028 
0029   // check for an eventual error from launching the kernel on an unsupported device
0030   status = cudaGetLastError();
0031   if (status != cudaSuccess)
0032     return false;
0033 
0034   // wait for the kernelto run
0035   status = cudaDeviceSynchronize();
0036   if (status != cudaSuccess)
0037     return false;
0038 
0039   // copy the flag back to the host
0040   status = cudaMemcpy(&supported, supported_d, sizeof(bool), cudaMemcpyDeviceToHost);
0041   if (status != cudaSuccess)
0042     return false;
0043 
0044   // free the device memory
0045   status = cudaFree(supported_d);
0046   if (status != cudaSuccess)
0047     return false;
0048 
0049   // reset the device
0050   status = cudaDeviceReset();
0051   if (status != cudaSuccess)
0052     return false;
0053 
0054   return supported;
0055 }