我是靠谱客的博主 无私荔枝,这篇文章主要介绍paddlepaddle 、tensorflow和torch代码验证cuda是否安装成功tensorflow或者torchDecide which device we want to run onpaddlepaddle,现在分享给大家,希望可以做个参考。

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

tensorflow

复制代码
1
2
3
import tensorflow as tf tf.test.is_gpu_available()

或者

复制代码
1
2
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

torch

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
验证cuda是否可用以及版本号,发现和本地的版本不一致,会导致不可用,重新下拉镜像 import torch print(torch.__version__) print(torch.version.cuda) print(torch.backends.cudnn.version()) torch.cuda.is_available() #cuda是否可用; torch.cuda.device_count() #返回gpu数量; torch.cuda.get_device_name(0) #返回gpu名字,设备索引默认从0开始; torch.cuda.current_device() #返回当前设备索引

Decide which device we want to run on

复制代码
1
2
3
4
5
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())

paddlepaddle

查看安装软件的型号

进入python环境

复制代码
1
2
3
4
5
import paddle print(paddle.version.cuda()) import paddle print(paddle.version.cudnn())

查看硬件本身的型号

退出python环境

复制代码
1
2
nvcc -V

进入python环境

复制代码
1
2
3
4
5
import paddle print(paddle.device.get_device()) import paddle print(paddle.device.get_cudnn_version())

使用python进入python解释器,输入

复制代码
1
2
3
import paddle.fluid paddle.fluid.install_check.run_check()

如果出现Your Paddle Fluid is installed successfully!,说明您已成功安装paddle-gpu。
如果没成功,验证驱动、cuda、cdnn是否安装成功。

最后

以上就是无私荔枝最近收集整理的关于paddlepaddle 、tensorflow和torch代码验证cuda是否安装成功tensorflow或者torchDecide which device we want to run onpaddlepaddle的全部内容,更多相关paddlepaddle内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部