Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:46

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