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.
As suggested in the third comment, you can extract information from Windows Power Shell with the subprocess python package.
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:
=================================== 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 .
Hope this can be helpful for you:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.