mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-07 20:10:08 +00:00
init
This commit is contained in:
22
pilot/utils.py
Normal file
22
pilot/utils.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import torch
|
||||
|
||||
def get_gpu_memory(max_gpus=None):
|
||||
gpu_memory = []
|
||||
num_gpus = (
|
||||
torch.cuda.device_count()
|
||||
if max_gpus is None
|
||||
else min(max_gpus, torch.cuda.device_count())
|
||||
)
|
||||
|
||||
for gpu_id in range(num_gpus):
|
||||
with torch.cuda.device(gpu_id):
|
||||
device = torch.cuda.current_device()
|
||||
gpu_properties = torch.cuda.get_device_properties(device)
|
||||
total_memory = gpu_properties.total_memory / (1024 ** 3)
|
||||
allocated_memory = torch.cuda.memory_allocated() / (1024 ** 3)
|
||||
available_memory = total_memory - allocated_memory
|
||||
gpu_memory.append(available_memory)
|
||||
return gpu_memory
|
Reference in New Issue
Block a user