MCPcopy Create free account
hub / github.com/aigc3d/LHM / check_single_gpu_memory

Function check_single_gpu_memory

LHM/utils/gpu_utils.py:21–45  ·  view source on GitHub ↗
(threshold_gb=24, gpu_id=0)

Source from the content-addressed store, hash-verified

19 import GPUtil
20
21def check_single_gpu_memory(threshold_gb=24, gpu_id=0):
22
23 gpus = GPUtil.getGPUs()
24
25 if not gpus:
26 print("No GPU found.")
27 return False
28
29 if gpu_id >= len(gpus):
30 print(f"GPU ID {gpu_id} is out of range. There are only {len(gpus)} GPUs.")
31 return False
32
33 gpu = gpus[gpu_id]
34 total_memory = gpu.memoryTotal
35 used_memory = gpu.memoryUsed
36
37 available_memory = total_memory - used_memory
38 available_memory_gb = available_memory / 1024
39
40 print(f"GPU ID: {gpu.id}, Total Memory: {total_memory} MB, Used Memory: {used_memory} MB, Available Memory: {available_memory_gb:.2f} GB")
41
42 if available_memory_gb < threshold_gb:
43 return False
44 else:
45 return True

Callers

nothing calls this directly

Calls 1

printFunction · 0.85

Tested by

no test coverage detected