测试TensorFlow的GPU版本安装成功方法

程序如下:

import tensorflow as tf

print('GPU',tf.test.is_gpu_available())

a = tf.constant(2.)
b = tf.constant(4.)

print(a * b)

运行结果:

D:\python\python.exe E:/pycharm_project2019/forward/test_gpu.py
2019-09-21 18:03:09.167168: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2019-09-21 18:03:12.435151: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-09-21 18:03:12.439660: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2019-09-21 18:03:12.809533: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 0.98
pciBusID: 0000:04:00.0
2019-09-21 18:03:12.809793: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-09-21 18:03:12.814170: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-09-21 18:03:24.691808: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-09-21 18:03:24.692136: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2019-09-21 18:03:24.692327: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
2019-09-21 18:03:24.785375: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 514 MB memory) -> physical GPU (device: 0, name: GeForce 940M, pci bus id: 0000:04:00.0, compute capability: 5.0)
GPU True
2019-09-21 18:03:24.909917: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 0.98
pciBusID: 0000:04:00.0
2019-09-21 18:03:24.910666: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-09-21 18:03:24.927035: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-09-21 18:03:24.963911: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 0.98
pciBusID: 0000:04:00.0
2019-09-21 18:03:24.964226: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-09-21 18:03:24.968809: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2019-09-21 18:03:24.969307: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-09-21 18:03:24.969515: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2019-09-21 18:03:24.969647: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
2019-09-21 18:03:24.974380: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 514 MB memory) -> physical GPU (device: 0, name: GeForce 940M, pci bus id: 0000:04:00.0, compute capability: 5.0)
tf.Tensor(8.0, shape=(), dtype=float32)

Process finished with exit code 0

显示“GPU True”,即代表GPU版本安装成功!

  • 9
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值