当前位置:网站首页>tensorflow和torch代码验证cuda是否安装成功

tensorflow和torch代码验证cuda是否安装成功

2022-07-06 11:10:00 愚昧之山绝望之谷开悟之坡

tensorflow代码验证cuda是否安装成功
tensorflow 测试 cuda 是否安装成功,测试代码环境

tensorflow

import tensorflow as tf

tf.test.is_gpu_available()

或者

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

torch

import torch
flag = torch.cuda.is_available()
print(flag)

gpunumber = 1

Decide which device we want to run on

device = torch.device("cuda:0" if (torch.cuda.is_available() and gpunumber > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())
原网站

版权声明
本文为[愚昧之山绝望之谷开悟之坡]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_15821487/article/details/125634549