安装 keras-gpu或者tensorflow-gpu后运行程序,发现没有调用GPU加速。
运行测试程序
import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
报错:
failed call to cuInit: CUDA_ERROR_UNKNOWN
原因可能在于CUDA没有正确安装,运行CUDA Samples
cd NVIDIA_CUDA-9.2_Samples
make -j
cd ./bin/x86_64/linux/release
sudo ./deviceQuery
报错:
CUDA driver version is insufficient for CUDA runtime version
说明显卡驱动与CUDA驱动不匹配,更新显卡驱动或者降级CUDA,问题解决。