# 确定设备为GPU
num_gpus = torch.cuda.device_count()
target_gpu_id = None
for gpu_id in range(num_gpus):
gpu_props = torch.cuda.get_device_properties(gpu_id)
if gpu_props.total_memory >= 80 * 1000**3: # 实验室空闲的GPU内存没这么大
target_gpu_id = gpu_id
break
if target_gpu_id is not None:
device = torch.device(f"cuda:{target_gpu_id}")
print(f"Selected GPU {target_gpu_id}: {gpu_props.name}, Total Memory: {gpu_props.total_memory} bytes")
#运行的代码
else
print("Error: CUDA is not available even though a suitable GPU was detected.")
sys.exit(1)
07-08
07-08
07-08
07-08
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交