Skip to content

Commit

Permalink
Fix for get_available_gpus
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyKozhevin committed Jan 18, 2024
1 parent 0d1ccac commit bdd9592
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions batchflow/utils_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,14 @@ def get_available_gpus(n=1, min_free_memory=1, max_processes=None, verbose=False
return {} if return_memory else None
n_devices = nvidia_smi.nvmlDeviceGetCount()

cuda_visible_devices = os.environ.get('CUDA_VISIBLE_DEVICES')
if cuda_visible_devices is not None:
cuda_visible_devices = [int(i) for i in cuda_visible_devices.split(',')]

available_devices, memory_free, memory_total = [], [], []
for i in range(n_devices):
if cuda_visible_devices is not None and i not in cuda_visible_devices:
continue
handle = nvidia_smi.nvmlDeviceGetHandleByIndex(i)
info = nvidia_smi.nvmlDeviceGetMemoryInfo(handle)

Expand All @@ -274,6 +280,8 @@ def get_available_gpus(n=1, min_free_memory=1, max_processes=None, verbose=False
print(f'Device {i} | Free memory: {info.free:4.2f} | '
f'Number of running processes: {num_processes:>2} | Free: {consider_available}')

nvidia_smi.nvmlShutdown()

if isinstance(n, str) and n.startswith('max'):
n = len(available_devices)

Expand Down

0 comments on commit bdd9592

Please sign in to comment.