簡體   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