mirror of
https://github.com/ultralytics/yolov5.git
synced 2025-06-03 14:49:29 +08:00
Display correct CUDA devices (#1776)
* Display correct CUDA devices * cleanup
This commit is contained in:
parent
8a81839cad
commit
c0ffcdf998
@ -48,20 +48,20 @@ def select_device(device='', batch_size=None):
|
||||
cpu_request = device.lower() == 'cpu'
|
||||
if device and not cpu_request: # if device requested other than 'cpu'
|
||||
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable
|
||||
assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity
|
||||
assert torch.cuda.is_available(), f'CUDA unavailable, invalid device {device} requested' # check availablity
|
||||
|
||||
cuda = False if cpu_request else torch.cuda.is_available()
|
||||
if cuda:
|
||||
c = 1024 ** 2 # bytes to MB
|
||||
ng = torch.cuda.device_count()
|
||||
if ng > 1 and batch_size: # check that batch_size is compatible with device_count
|
||||
assert batch_size % ng == 0, 'batch-size %g not multiple of GPU count %g' % (batch_size, ng)
|
||||
assert batch_size % ng == 0, f'batch-size {batch_size} not multiple of GPU count {ng}'
|
||||
x = [torch.cuda.get_device_properties(i) for i in range(ng)]
|
||||
s = f'Using torch {torch.__version__} '
|
||||
for i in range(0, ng):
|
||||
for i, d in enumerate((device or '0').split(',')):
|
||||
if i == 1:
|
||||
s = ' ' * len(s)
|
||||
logger.info("%sCUDA:%g (%s, %dMB)" % (s, i, x[i].name, x[i].total_memory / c))
|
||||
logger.info(f"{s}CUDA:{d} ({x[i].name}, {x[i].total_memory / c}MB)")
|
||||
else:
|
||||
logger.info(f'Using torch {torch.__version__} CPU')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user