Every line of 'torch is cuda available' 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.
124 def to_cuda(list_modules): 125 for m in list_modules: 126 m.cuda()
36 def check_cuda_support(): 37 """ Check if tensorflow was build with CUDA """ 38 return tf.test.is_built_with_cuda()
221 def cuda(xs, gpu_id): 222 if torch.cuda.is_available(): 223 if not isinstance(xs, (list, tuple)): 224 return xs.cuda(int(gpu_id[0])) 225 else: 226 return [x.cuda(int(gpu_id[0])) for x in xs] 227 return xs
95 @staticmethod 96 def check_device(cuda: Union[bool, str, torch.device]) -> torch.device: 97 if isinstance(cuda, bool): 98 if cuda: 99 if torch.cuda.is_available(): 100 return torch.device('cuda') 101 else: 102 raise RuntimeError('could not use CUDA on this machine') 103 else: 104 return torch.device('cpu') 105 106 if isinstance(cuda, str): 107 if 'cuda' in cuda: 108 if torch.cuda.is_available(): 109 return torch.device(cuda) 110 else: 111 raise RuntimeError('could not use CUDA on this machine') 112 elif 'cpu' in cuda: 113 return torch.device('cpu') 114 else: 115 raise RuntimeError( 116 'wrong device identifier' 117 'see also: https://pytorch.org/docs/stable/tensor_attributes.html#torch.torch.device' 118 ) 119 120 if isinstance(cuda, torch.device): 121 return cuda
29 def linux_with_gpu(): 30 """Returns if machine is running an Linux OS and has a GPU""" 31 has_gpu = is_available() 32 return is_linux() and has_gpu