Returns the GPU device name if there is one (with arbitrary tie breaking if there are more than one), or "" otherwise.
| 64 | // Returns the GPU device name if there is one (with arbitrary tie breaking if |
| 65 | // there are more than one), or "" otherwise. |
| 66 | string GPUDeviceName(TF_Session* session) { |
| 67 | std::unique_ptr<TF_Status, decltype(&TF_DeleteStatus)> status( |
| 68 | TF_NewStatus(), TF_DeleteStatus); |
| 69 | TF_Status* s = status.get(); |
| 70 | std::unique_ptr<TF_DeviceList, decltype(&TF_DeleteDeviceList)> list( |
| 71 | TF_SessionListDevices(session, s), TF_DeleteDeviceList); |
| 72 | TF_DeviceList* device_list = list.get(); |
| 73 | |
| 74 | CHECK_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 75 | |
| 76 | const int num_devices = TF_DeviceListCount(device_list); |
| 77 | LOG(INFO) << "There are " << num_devices << " devices."; |
| 78 | for (int i = 0; i < num_devices; ++i) { |
| 79 | const char* device_name = TF_DeviceListName(device_list, i, s); |
| 80 | CHECK_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 81 | const char* device_type = TF_DeviceListType(device_list, i, s); |
| 82 | CHECK_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 83 | LOG(INFO) << "Device " << i << " has name " << device_name << ", type " |
| 84 | << device_type; |
| 85 | if (string(device_type) == DEVICE_GPU) { |
| 86 | return device_name; |
| 87 | } |
| 88 | } |
| 89 | // No GPU device found. |
| 90 | return ""; |
| 91 | } |
| 92 | |
| 93 | string GPUDeviceName() { |
| 94 | std::unique_ptr<TF_Status, decltype(&TF_DeleteStatus)> status( |
no test coverage detected