Every line of 'cuda_visible_devices python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
69 def device_cuda(): 70 71 """ Displays the CUDA GPU device details. 72 73 Parameters 74 ---------- 75 None 76 77 Returns 78 ------- 79 None 80 81 Examples 82 -------- 83 >>> device_cuda() 84 Device: GeForce GTX 1060 6GB 85 Compute Capability: 6.1 86 Total Memory: 6291 MB 87 CLOCK_RATE: 1746500 88 ... 89 MAX_BLOCK_DIM_X: 1024 90 MAX_BLOCK_DIM_Y: 1024 91 MAX_BLOCK_DIM_Z: 64 92 ...etc 93 94 """ 95 96 pycuda.driver.init() 97 dev = pycuda.driver.Device(0) 98 print('Device: ' + dev.name()) 99 print('Compute Capability: %d.%d' % dev.compute_capability()) 100 print('Total Memory: %s MB' % (dev.total_memory() // (1024000))) 101 atts = [(str(att), value) for att, value in dev.get_attributes().items()] 102 atts.sort() 103 for att, value in atts: 104 print('%s: %s' % (att, value))
473 def _get_cuda_gpus(): 474 """ 475 Returns a list of dictionaries, with the following keys: 476 - index (integer, device index of the GPU) 477 - name (str, GPU name) 478 - memory_free (float, free memory in MiB) 479 - memory_total (float, total memory in MiB) 480 """ 481 import subprocess 482 try: 483 output = subprocess.check_output(['nvidia-smi', 484 '--query-gpu=index,gpu_name,memory.free,memory.total', 485 '--format=csv,noheader,nounits'], 486 universal_newlines=True) 487 except OSError: 488 return [] 489 except subprocess.CalledProcessError: 490 return [] 491 492 gpus = [] 493 for gpu_line in output.split('\n'): 494 if gpu_line: 495 index, gpu_name, memory_free, memory_total = gpu_line.split(', ') 496 index = int(index) 497 memory_free = float(memory_free) 498 memory_total = float(memory_total) 499 gpus.append({ 500 'index': index, 501 'name': gpu_name, 502 'memory_free': memory_free, 503 'memory_total': memory_total, 504 }) 505 return gpus