def parse_smi_output(output): gpu_stat = GPUStatus() gpu_stat.product_name = _find_val(output, 'Product Name') gpu_stat.pci_device_id = _find_val(output, 'PCI Device/Vendor ID') gpu_stat.pci_location = _find_val(output, 'PCI Location ID') gpu_stat.display = _find_val(output, 'Display') gpu_stat.driver_version = _find_val(output, 'Driver Version') temp_str = _find_val(output, 'Temperature') if temp_str: temp, units = temp_str.split() gpu_stat.temperature = int(temp) fan_str = _find_val(output, 'Fan Speed') if fan_str: # Fan speed in RPM fan_spd = float(fan_str.strip('\%').strip()) * 0.01 * MAX_FAN_RPM # Convert fan speed to Hz gpu_stat.fan_speed = _rpm_to_rads(fan_spd) usage_str = _find_val(output, 'GPU') if usage_str: usage = usage_str.strip('\%').strip() gpu_stat.gpu_usage = int(usage) mem_str = _find_val(output, 'Memory') if mem_str: mem = mem_str.strip('\%').strip() gpu_stat.memory_usage = int(mem) return gpu_stat
def parse_smi_xml_output(output): gpu_stat = GPUStatus() parser = etree.XMLParser(remove_blank_text=True) tree = etree.parse(StringIO(output), parser) root = tree.getroot() gpu = root.find('gpu') gpu_stat.driver_version = root.findtext('driver_version') gpu_stat.display = "N/A" gpu_stat.product_name = gpu.findtext('product_name') gpu_stat.pci_device_id = gpu.findtext('pci/pci_device_id') gpu_stat.pci_location = gpu.findtext('pci/pci_bus_id') temp_str = gpu.findtext('temperature/gpu_temp') if temp_str: temp, units = temp_str.split() gpu_stat.temperature = int(temp) fan_str = gpu.findtext('fan_speed') if fan_str: # Fan speed in RPM fan_spd = float(fan_str.strip('\%').strip()) * 0.01 * MAX_FAN_RPM # Convert fan speed to Hz gpu_stat.fan_speed = _rpm_to_rads(fan_spd) usage_str = gpu.findtext('utilization/gpu_util') if usage_str: if usage_str != 'N/A': usage = usage_str.strip('\%').strip() gpu_stat.gpu_usage = int(usage) else: gpu_stat.gpu_usage = 0 mem_str = gpu.findtext('utilization/memory_util') if mem_str: if mem_str != 'N/A': mem = mem_str.strip('\%').strip() gpu_stat.memory_usage = int(mem) else: total_mem = gpu.findtext('memory_usage/total') used_mem = gpu.findtext('memory_usage/used') if total_mem != 'N/A' and used_mem != 'N/A': total, units = total_mem.split() used, units = used_mem.split() gpu_stat.memory_usage = math.ceil(float(used)/float(total) * 100) return gpu_stat
def parse_smi_output(output): gpu_stat = GPUStatus() gpu_stat.product_name = _find_val(output, 'Product Name') gpu_stat.pci_device_id = _find_val(output, 'PCI Device/Vendor ID') gpu_stat.pci_location = _find_val(output, 'PCI Location ID') gpu_stat.display = _find_val(output, 'Display') gpu_stat.driver_version = _find_val(output, 'Driver Version') temp_str = _find_val(output, 'GPU Current Temp') if temp_str and not "N/A" in temp_str: temp, units = temp_str.split() gpu_stat.temperature = int(temp) fan_str = _find_val(output, 'Fan Speed') if fan_str and not "N/A" in fan_str: # Fan speed in RPM fan_spd = float(fan_str.strip('\%').strip()) * 0.01 * MAX_FAN_RPM # Convert fan speed to Hz gpu_stat.fan_speed = _rpm_to_rads(fan_spd) else: gpu_stat.fan_speed = 0 usage_str = _find_val(output, 'GPU') if usage_str and not "N/A" in usage_str: usage = usage_str.strip('\%').strip() gpu_stat.gpu_usage = int(usage) else: gpu_stat.gpu_usage = -1 memUsed = 0 mem_str = _find_val(output, 'Used') if mem_str and not "N/A" in mem_str: mem = mem_str.strip(' MiB').strip() memUsed = int(mem) memTotal = 0 mem_str = _find_val(output, 'Total') if mem_str and not "N/A" in mem_str: mem = mem_str.strip(' MiB').strip() memTotal = int(mem) gpu_stat.memory_usage = int(100.0 * memUsed / memTotal) return gpu_stat