繁体   English   中英

有没有办法在 Windows 上使用 python 获取 Intel 的集成 gpu 用法?

[英]Is there a way to get Intel's integrated gpu usage using python on Windows?

我需要在 Windows 上使用 python 从英特尔的集成 gpu 获得 gpu 的使用,有没有办法解决这个问题?我不介意必须使用模块。

正如第三条评论中所建议的,您可以使用子流程python package 从Windows Power Shell中提取信息。

import subprocess as sp

# raw strings avoid unicode encoding errors
gpu_mem_cmd = r'(((Get-Counter "\GPU Process Memory(*)\Local Usage").CounterSamples | where CookedValue).CookedValue | measure -sum).sum'
gpu_usage_cmd = r'(((Get-Counter "\GPU Engine(*engtype_3D)\Utilization Percentage").CounterSamples | where CookedValue).CookedValue | measure -sum).sum'

def run_command(command):
    val = sp.run(['powershell', '-Command', command], capture_output=True).stdout.decode("ascii")

    return float(val.strip().replace(',', '.'))

print()
print(" GPU Info ".center(80, '='))
print(f"GPU Memory Usage: {round(run_command(gpu_mem_cmd)/1e6,1):<6} MB")
print(f"GPU Load :        {round(run_command(gpu_usage_cmd),2):<6} %")

output 应该是:

=================================== GPU Info ===================================
GPU Memory Usage: 520.1  MB
GPU Load :        2.0 %

每条命令都比较慢,每GPU条信息要取回大约需要1.5s

希望这对你有帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM