Skip to content

Commit e0fa1d2

Browse files
committed
Add a 'vram usage' function that works across GPUs on Windows; It is slow, so is only useful for non critical paths
1 parent 5f58175 commit e0fa1d2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

sdkit/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .memory_utils import (
3131
gc,
3232
get_device_usage,
33+
get_vram_usage_slow,
3334
get_object_id,
3435
get_tensors_in_memory,
3536
print_largest_tensors_in_memory,

sdkit/utils/memory_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def get_device_usage(device, log_info=False, process_usage_only=True, log_prefix
5757
return cpu_used, ram_used, ram_total, vram_used, vram_total, vram_peak
5858

5959

60+
def get_vram_usage_slow():
61+
import subprocess
62+
import platform
63+
64+
if platform.system() == "Windows":
65+
ps_cmd = "(Get-Counter -Counter '\GPU Adapter Memory(*)\Dedicated Usage').CounterSamples[0].CookedValue"
66+
x = subprocess.check_output(["powershell", "-Command", ps_cmd], encoding="utf-8")
67+
return int(x)
68+
69+
return 0
70+
71+
6072
def get_object_id(o):
6173
"""
6274
Returns a more-readable object id, than the long number returned by the inbuilt `id()` function.

0 commit comments

Comments
 (0)