simplify code - no need for helper methods at this point

This commit is contained in:
henryruhs committed 2026-05-11 16:35:12 +02:00
1 parent abeef470cc
commit 2db7ad426a
1 file changed
+15 -25
+15 -25
View File
@@ -129,10 +129,6 @@ def resolve_openvino_device_type(execution_device_id : int) -> str:
return 'GPU.' + str(execution_device_id) return 'GPU.' + str(execution_device_id)
def resolve_cuda_driver_version(cuda_driver_version : int) -> str:
return '{}.{}'.format(cuda_driver_version // 1000, (cuda_driver_version % 1000) // 10)
@lru_cache() @lru_cache()
def detect_static_execution_devices() -> List[ExecutionDevice]: def detect_static_execution_devices() -> List[ExecutionDevice]:
return detect_execution_devices() return detect_execution_devices()
@@ -147,62 +143,56 @@ def detect_execution_devices() -> List[ExecutionDevice]:
for device_id in range(device_count): for device_id in range(device_count):
handle = pynvml.nvmlDeviceGetHandleByIndex(device_id) handle = pynvml.nvmlDeviceGetHandleByIndex(device_id)
product_name = pynvml.nvmlDeviceGetName(handle)
driver_version = pynvml.nvmlSystemGetDriverVersion()
cuda_driver_version = resolve_cuda_driver_version(pynvml.nvmlSystemGetCudaDriverVersion())
memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
utilization = pynvml.nvmlDeviceGetUtilizationRates(handle)
temperature = pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU)
memory_total_mib = memory_info.total // (1024 * 1024)
memory_free_mib = memory_info.free // (1024 * 1024)
memory_used_mib = memory_info.used // (1024 * 1024)
memory_percent = memory_used_mib / memory_total_mib * 100
execution_devices.append( execution_devices.append(
{ {
'driver_version': driver_version, 'driver_version': pynvml.nvmlSystemGetDriverVersion(),
'framework': 'framework':
{ {
'name': 'CUDA', 'name': 'CUDA',
'version': cuda_driver_version 'version': pynvml.nvmlSystemGetCudaDriverVersion()
}, },
'product': 'product':
{ {
'vendor': 'NVIDIA', 'vendor': 'NVIDIA',
'name': product_name.replace('NVIDIA', '').strip() 'name': pynvml.nvmlDeviceGetName(handle)
}, },
'video_memory': 'video_memory':
{ {
'total': 'total':
{ {
'value': int(memory_total_mib), 'value': pynvml.nvmlDeviceGetMemoryInfo(handle).total // (1024 * 1024 * 1024),
'unit': 'MiB' 'unit': 'GB'
}, },
'free': 'free':
{ {
'value': int(memory_free_mib), 'value': pynvml.nvmlDeviceGetMemoryInfo(handle).free // (1024 * 1024 * 1024),
'unit': 'MiB' 'unit': 'GB'
} }
}, },
'temperature': 'temperature':
{ {
'gpu': 'gpu':
{ {
'value': int(temperature), 'value': pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU),
'unit': 'C' 'unit': 'C'
}, },
'memory': None 'memory':
{
'value': 0,
'unit': '%'
}
}, },
'utilization': 'utilization':
{ {
'gpu': 'gpu':
{ {
'value': int(utilization.gpu), 'value': pynvml.nvmlDeviceGetUtilizationRates(handle).gpu,
'unit': '%' 'unit': '%'
}, },
'memory': 'memory':
{ {
'value': int(memory_percent), 'value': pynvml.nvmlDeviceGetUtilizationRates(handle).memory,
'unit': '%' 'unit': '%'
} }
} }