Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit f684e69

Browse files
committed
fix: add vendor in gpu info
1 parent 4be3a74 commit f684e69

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

engine/common/hardware_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct GPU {
7979
int64_t total_vram;
8080
std::string uuid;
8181
bool is_activated = true;
82+
std::string vendor;
8283
};
8384

8485
inline Json::Value ToJson(const std::vector<GPU>& gpus) {
@@ -100,6 +101,7 @@ inline Json::Value ToJson(const std::vector<GPU>& gpus) {
100101
gpu["total_vram"] = gpus[i].total_vram;
101102
gpu["uuid"] = gpus[i].uuid;
102103
gpu["activated"] = gpus[i].is_activated;
104+
gpu["vendor"] = gpus[i].vendor;
103105
if (gpus[i].total_vram > 0) {
104106
res.append(gpu);
105107
}

engine/utils/hardware/gpu/vulkan/vulkan_gpu.h

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
#endif
2525

2626
namespace cortex::hw {
27+
inline std::string GetVendorStr(uint32_t vendor_id) {
28+
switch (vendor_id) {
29+
case 0x1002:
30+
return "AMD";
31+
case 0x10DE:
32+
return "NVIDIA";
33+
case 0x8086:
34+
return "INTEL";
35+
case 0x13B5:
36+
return "ARM";
37+
default:
38+
return std::to_string(vendor_id);
39+
}
40+
}
41+
2742
#if defined(_WIN32)
2843
// Definitions of the used function pointers. Add more if you use other ADL APIs
2944
typedef int (*ADL_MAIN_CONTROL_CREATE)(ADL_MAIN_MALLOC_CALLBACK, int);
@@ -335,7 +350,8 @@ inline cpp::result<std::vector<cortex::hw::GPU>, std::string> GetGpuInfoList() {
335350

336351
// Get the physical devices
337352
uint32_t physical_device_count = 0;
338-
result = vkEnumeratePhysicalDevices(instance, &physical_device_count, nullptr);
353+
result =
354+
vkEnumeratePhysicalDevices(instance, &physical_device_count, nullptr);
339355
if (result != VK_SUCCESS) {
340356
vkDestroyInstance(instance, nullptr);
341357
FreeLibrary(vulkan_library);
@@ -376,7 +392,8 @@ inline cpp::result<std::vector<cortex::hw::GPU>, std::string> GetGpuInfoList() {
376392
VkPhysicalDeviceProperties2 device_properties2 = {};
377393
device_properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
378394
device_properties2.pNext = &device_id_properties;
379-
device_id_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
395+
device_id_properties.sType =
396+
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
380397

381398
vkGetPhysicalDeviceProperties2(physical_device, &device_properties2);
382399

@@ -404,15 +421,18 @@ inline cpp::result<std::vector<cortex::hw::GPU>, std::string> GetGpuInfoList() {
404421
#endif
405422
int free_vram_MiB =
406423
total_vram_MiB > used_vram_MiB ? total_vram_MiB - used_vram_MiB : 0;
407-
gpus.emplace_back(cortex::hw::GPU{
408-
.id = std::to_string(id),
409-
.device_id = device_properties.deviceID,
410-
.name = device_properties.deviceName,
411-
.version = std::to_string(device_properties.driverVersion),
412-
.add_info = cortex::hw::AmdAddInfo{},
413-
.free_vram = free_vram_MiB,
414-
.total_vram = total_vram_MiB,
415-
.uuid = uuid_to_string(device_id_properties.deviceUUID)});
424+
if (total_vram_MiB > 0) {
425+
gpus.emplace_back(cortex::hw::GPU{
426+
.id = std::to_string(id),
427+
.device_id = device_properties.deviceID,
428+
.name = device_properties.deviceName,
429+
.version = std::to_string(device_properties.driverVersion),
430+
.add_info = cortex::hw::AmdAddInfo{},
431+
.free_vram = free_vram_MiB,
432+
.total_vram = total_vram_MiB,
433+
.uuid = uuid_to_string(device_id_properties.deviceUUID),
434+
.vendor = GetVendorStr(device_properties.vendorID)});
435+
}
416436
id++;
417437
}
418438

engine/utils/hardware/gpu_info.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ inline std::vector<GPU> GetGPUInfo() {
2424
.compute_cap = nvidia_gpus[i].compute_cap.value_or("unknown")};
2525
vulkan_gpus[j].free_vram = std::stoll(nvidia_gpus[i].vram_free);
2626
vulkan_gpus[j].total_vram = std::stoll(nvidia_gpus[i].vram_total);
27+
vulkan_gpus[j].vendor = nvidia_gpus[i].vendor;
2728
}
2829
}
2930
}
30-
31+
3132
if (use_vulkan_info) {
3233
return vulkan_gpus;
3334
} else {
@@ -43,7 +44,8 @@ inline std::vector<GPU> GetGPUInfo() {
4344
.compute_cap = n.compute_cap.value_or("unknown")},
4445
.free_vram = std::stoi(n.vram_free),
4546
.total_vram = std::stoi(n.vram_total),
46-
.uuid = n.uuid});
47+
.uuid = n.uuid,
48+
.vendor = n.vendor});
4749
}
4850
return res;
4951
}

engine/utils/system_info_utils.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,16 @@ std::vector<GpuInfo> GetGpuInfoList() {
124124

125125
while (
126126
std::regex_search(search_start, output.cend(), match, gpu_info_reg)) {
127-
GpuInfo gpuInfo = {
128-
match[1].str(), // id
129-
match[2].str(), // vram_total
130-
match[3].str(), // vram_free
131-
match[4].str(), // name
132-
GetGpuArch(match[4].str()), // arch
133-
driver_version, // driver_version
134-
cuda_version, // cuda_driver_version
135-
need_fallback ? "0" : match[5].str(), // compute_cap
136-
match[rg_count].str() // uuid
137-
};
127+
GpuInfo gpuInfo = {match[1].str(), // id
128+
match[2].str(), // vram_total
129+
match[3].str(), // vram_free
130+
match[4].str(), // name
131+
GetGpuArch(match[4].str()), // arch
132+
driver_version, // driver_version
133+
cuda_version, // cuda_driver_version
134+
need_fallback ? "0" : match[5].str(), // compute_cap
135+
match[rg_count].str(), // uuid
136+
"NVIDIA"};
138137
gpuInfoList.push_back(gpuInfo);
139138
search_start = match.suffix().first;
140139
}

engine/utils/system_info_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct GpuInfo {
121121
std::optional<std::string> cuda_driver_version;
122122
std::optional<std::string> compute_cap;
123123
std::string uuid;
124+
std::string vendor;
124125
};
125126

126127
std::vector<GpuInfo> GetGpuInfoListVulkan();

0 commit comments

Comments
 (0)