[英]Is there a way to get Intel's integrated gpu usage using python on Windows?
I need to get gpu usage from intel's integrated gpu using python on Windows is there a way to pull this off?, i don't mind having to use modules.我需要在 Windows 上使用 python 从英特尔的集成 gpu 获得 gpu 的使用,有没有办法解决这个问题?我不介意必须使用模块。
As suggested in the third comment, you can extract information from Windows Power Shell with the subprocess python package.正如第三条评论中所建议的,您可以使用子流程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} %")
The output should be: output 应该是:
=================================== GPU Info ===================================
GPU Memory Usage: 520.1 MB
GPU Load : 2.0 %
Each command is quite slow, every GPU information that you want to retrieve takes approximately 1.5s .每条命令都比较慢,每GPU条信息要取回大约需要1.5s 。
Hope this can be helpful for you:)希望这对你有帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.