MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GPUDeviceName

Function GPUDeviceName

tensorflow/c/c_api_test.cc:66–91  ·  view source on GitHub ↗

Returns the GPU device name if there is one (with arbitrary tie breaking if there are more than one), or "" otherwise.

Source from the content-addressed store, hash-verified

64// Returns the GPU device name if there is one (with arbitrary tie breaking if
65// there are more than one), or "" otherwise.
66string 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
93string GPUDeviceName() {
94 std::unique_ptr<TF_Status, decltype(&TF_DeleteStatus)> status(

Callers 1

TESTFunction · 0.70

Calls 11

TF_NewStatusFunction · 0.85
TF_SessionListDevicesFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TF_DeviceListCountFunction · 0.85
TF_NewGraphFunction · 0.85
TF_NewSessionOptionsFunction · 0.85
TF_NewSessionFunction · 0.85
TF_DeleteSessionOptionsFunction · 0.85
TF_DeleteSessionFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected