1
2

More than 3 years have passed since last update.

[Linux] Anaconda環境下でTensorflowにGPUを認識させる

Last updated at Posted at 2020-12-02

はじめに

Anaconda環境下において
TensorflowにGPUを認識させる場合に下記のようなエラーが発生。
その解決手順を記載。

# check device using tensorflow.
from tensorflow.python.client import device_lib
device_lib.list_local_devices()

>> InternalError: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version

解決概要

CUDAのデバイスドライバーのバージョンとTensorflow-gpuバージョンが一致していないことが原因である場合が多いと思われる。

初めに、nvidia-smiコマンドを利用しCUDAのデバイスドライバーのバージョン、及び、CUDAのバージョンを確認
image.png

nvidia-smiが動かない場合は下記を参照
公式 https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#abstract
Qiita https://qiita.com/protocol1964/items/19de3d1e27306f80d06d

上図ではCUDA Version: 10.0であることが分かる。

次に下記から対応するTensorflow-gpuバージョンを確認
https://www.tensorflow.org/install/source?hl=ja
image.png

CUDA 10.0に対応するTensorflowバージョンは
1.13.1以上だとわかる。

Tensorflowバージョンが分かれば、インストールし直すだけだが、まず、既にインストールしてしまっているTensorflow関連のライブラリを削除する。

conda remove cudnn tensorflow tensorflow-base tensorflow-estimator tensorflow-gpu

次にtensorflow gpuをインストールし直す。

conda install -c anaconda tensorflow-gpu=2.0.0

最後に下記コードでGPUが認識されていれば完了

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

image.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2