Press "Enter" to skip to content

『AI实践学』测试深度学习框架GPU版本是否正确安装方法:TensorFlow,PyTorch,MXNet,PaddlePaddle

『AI实践学』测试深度学习框架GPU版本是否正确安装方法:TensorFlow,PyTorch,MXNet,PaddlePaddle

 

 

    1. 引子

 

 

在深度学习框架 GPU 版本安装成功后,需要测试一下是否成功安装。GPU 版本不像 CPU 版本的简单, CPU 版本测试一般只需 import 一下测试是否能正确导入即可
。GPU 版本还需要测试 CUDA 或者 GPU 模块是否能正确调用起来。

 

下面将介绍笔者常用框架的测试方法,包括 TensorFlow,PyTorch,MXNet,PaddlePaddle。如果小伙伴有其他框架测试需求或者经验,欢迎在评论区指出。必要的时候,笔者会及时更新一下的。

 

 

    1. 方法

 

 

1.0:TensorFlow

 

TensorFlow1.x 与 TensorFlow2.x 测试方法是一样的,代码如下:

 

print(tf.test.is_gpu_available())

 

上述代码保存为. py 文件,使用需要测试环境即可运行,输出:上面是一下 log 信息,关键的是的最后 True
,表示测试成功

 

2020-09-28 15:43:03.197710: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-09-28 15:43:03.204525: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-09-28 15:43:03.232432: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce RTX 2070 with Max-Q Design major: 7 minor: 5 memoryClockRate(GHz): 1.125
2020-09-28 15:43:03.235352: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2020-09-28 15:43:03.242823: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll
2020-09-28 15:43:03.261932: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_100.dll
2020-09-28 15:43:03.268757: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_100.dll
2020-09-28 15:43:03.297478: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_100.dll
2020-09-28 15:43:03.315410: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_100.dll
2020-09-28 15:43:03.330562: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-09-28 15:43:03.332846: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-09-28 15:43:05.198465: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-09-28 15:43:05.200423: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0
2020-09-28 15:43:05.201540: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N
2020-09-28 15:43:05.203863: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 6306 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2070 with Max-Q Design, pci bus id: 0000:01:00.0, compute capability: 7.5)

 

上面是一下 log 信息,关键的是的最后 True
,表示测试成功。其实我们还可以发现很多 GPU 信息

 

GPU 型号:name: GeForce RTX 2070 with Max-Q Design

 

cuda 版本:Successfully opened dynamic library cudart64_100.dll(10.0)

 

cudnn 版本:Successfully opened dynamic library cudnn64_7.dll(7.x)

 

GPU 数目:Adding visible gpu devices: 0(1)

 

GPU 显存:/device:GPU:0 with 6306 MB memory(8G)

 

1.1:PyTorch

 

PyTorch 与 TensorFlow 测试方法类似,都有 GPU 测试接口。PyTorch 的 GPU 测试代码如下:

 

print(torch.cuda.is_available())

 

上述代码保存为. py 文件,使用需要测试环境即可运行,输出: True
,表示测试成功

 

True

 

可以看出 PyTorch 输出信息简洁很多。其实 TensorFlow 的 log 信息输出也是可以控制的。

 

1.2:MXNet

 

MXNet 与 PyTorch,TensorFlow 测试方法不同,由于 MXNet’没有 GPU 测试接口(或者说笔者没有找到)。所以 MXNet 的 GPU 测试代码采用 try-catch 捕捉异常的方法来测试,代码如下:

 

_ = mx.nd.array(1,ctx=mx.gpu(0))

 

上述代码保存为. py 文件,使用需要测试环境即可运行,输出: True
,表示测试成功

 

1.3:PaddlePaddle

 

PaddlePaddle 与 TensorFlow 测试方法类似,都有 GPU 测试接口。PyTorch 的 GPU 测试代码如下:

 

paddle.fluid.install_check.run_check()

 

上述代码保存为. py 文件,使用需要测试环境即可运行,输出:Your Paddle Fluid works well on MUTIPLE GPU or CPU.,表示测试成功

 

Running Verify Fluid Program ...
W0928 16:23:17.825171 10572 device_context.cc:252] Please NOTE: device: 0, CUDA Capability: 75, Driver API Version: 11.0, Runtime API Version: 10.0
W0928 16:23:17.836141 10572 device_context.cc:260] device: 0, cuDNN Version: 7.6.
Your Paddle Fluid works well on SINGLE GPU or CPU.
W0928 16:23:19.349067 10572 build_strategy.cc:170] fusion_group is not enabled for Windows/MacOS now, and only effective when running with CUDA GPU.
Your Paddle Fluid works well on MUTIPLE GPU or CPU.
Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now

 

-1. 参考

 

-1.0: www.paddlepaddle.org.cn/install/qui…

Be First to Comment

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注