CMS 3D CMS Logo

Functions
isRocmDeviceSupported.hip.cc File Reference
#include <hip/hip_runtime.h>
#include "isRocmDeviceSupported.h"

Go to the source code of this file.

Functions

bool isRocmDeviceSupported (int device)
 

Function Documentation

◆ isRocmDeviceSupported()

bool isRocmDeviceSupported ( int  device)

Definition at line 9 of file isRocmDeviceSupported.hip.cc.

References mps_update::status.

9  {
10  bool supported = false;
11  bool* supported_d;
12 
13  // select the requested device - will fail if the index is invalid
14  hipError_t status = hipSetDevice(device);
15  if (status != hipSuccess)
16  return false;
17 
18  // allocate memory for the flag on the device
19  status = hipMalloc(&supported_d, sizeof(bool));
20  if (status != hipSuccess)
21  return false;
22 
23  // initialise the flag on the device
24  status = hipMemset(supported_d, 0x00, sizeof(bool));
25  if (status != hipSuccess)
26  return false;
27 
28  // try to set the flag on the device
29  setSupported<<<1, 1>>>(supported_d);
30 
31  // check for an eventual error from launching the kernel on an unsupported device
32  status = hipGetLastError();
33  if (status != hipSuccess)
34  return false;
35 
36  // wait for the kernelto run
37  status = hipDeviceSynchronize();
38  if (status != hipSuccess)
39  return false;
40 
41  // copy the flag back to the host
42  status = hipMemcpy(&supported, supported_d, sizeof(bool), hipMemcpyDeviceToHost);
43  if (status != hipSuccess)
44  return false;
45 
46  // free the device memory
47  status = hipFree(supported_d);
48  if (status != hipSuccess)
49  return false;
50 
51  // reset the device
52  status = hipDeviceReset();
53  if (status != hipSuccess)
54  return false;
55 
56  return supported;
57 }