ChainerはTensorFlowと違ってpythonをよく分かっている人が書いている感じがあるところが好きです。しかし公式サポートがUbuntuとCentOSだけなのです。最新はchainer 4系ですが、3系がwindows上で必要になったので試行錯誤の結果動作するようになった手順をまとめます。
この記事を読むと分かること
- windows10でchainer3系+CUDA+cuDNNを入れる手順
- 動作が確認されたchainer3系依存パッケージのバージョン
Contents
使用するライブラリのバージョン
- Chainer: 3.4.0
- CUDA: 8.0
- cuDNN: 7.1
- cupy: 2.4.0
使用したwindows10のバージョンは、windows 1709 OS Build 16299.431です。
CUDAとかをインストール
https://developer.nvidia.com/cuda-80-ga2-download-archive
上記リンクよりwindows10用のCUDA toolkitをダウンロード&インストールします。
cuDNNはNVIDIA developperに登録の上、下記リンクから「cuDNN v7.1.3 Library for Windows 10」をダウンロードします。
https://developer.nvidia.com/rdp/cudnn-download
ダウンロードファイルを解凍したら、CUDAのインストールフォルダ(C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0)以下にコピーします。これによりインストール完了です。
念のためwindowsを再起動しておきましょう。
Chainerのインストール
chainerは以下のコマンドで簡単にインストールできます。
pip install chainer==3.4.0 --no-cache-dir
次に、gpuを有効にするためにcupyをインストールしたいのですが、公式で推奨されているパッケージ(cupy-cuda80) はwindows用に提供されていないのでビルドする必要があります。
まずは必要なものたちを環境変数に追加しましょう。
システム環境変数INCLUDE
- C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
- C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt
システム環境変数Path
- C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
もしVC++14がインストールされていなかったら、Visual Studio 2017 Community Edition(無料)をインストールし、インストーラーのメニューで「Desktop development with C++」及び「VC++ 2015.3 v14.00(v140) toolset for desktop」にチェックを入れてインストールしてください。
これでcupyのビルド&インストールができるようになります。
pip install cupy==2.4.0 --no-cache-dir
インストールが完了したら、pythonコンソールから
>>> import chainer
>>> import cupy as cp
cp.array([0,0,0],dtype=cp.int32)
等のコマンドが動作することを確認してください。
windowsサポートほしいなあ。。。
(2018-05-29 追記)
知らないうちにcupyをinportするとエラーが表示されるようになっていたのでcupyの再インストールをしたところ、次のエラーが出た:
C:\WINDOWS\system32>pip install cupy==2.4.0
Collecting cupy==2.4.0
Downloading https://files.pythonhosted.org/packages/71/bc/ab7d033eeca10516e203c456fd6c048c0b4d52bd50dae9914233ac0db2f5/cupy-2.4.0.tar.gz (1.7MB)
100% |################################| 1.7MB 7.3MB/s
Complete output from command python setup.py egg_info:
a.cpp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include\cuda_runtime.h: warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss
c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\cuda_runtime_api.h(1946): warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss
c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\cuda_runtime_api.h(1946): warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include\cuda_runtime.h: warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss
Generating code
Finished generating code
a.cpp
Generating code
Finished generating code
a.cpp
Generating code
Finished generating code
LINK : fatal error LNK1158: cannot run 'rc.exe'
**************************************************
*** WARNING: Cannot find nvToolsExt. nvtx was disabled.
**************************************************
Options: {'annotate': False, 'no_cuda': False, 'linetrace': False, 'profile': False}
Include directories: ['C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\include', 'C:\\Program Files\\NVIDIA Corporation\\NvToolsExt\\include']
Library directories: ['C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\bin', 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\x64', 'C:\\Program Files\\NVIDIA Corporation\\NvToolsExt\\lib\\x64']
**************************************************
*** WARNING: Cannot check CUDA version
*** WARNING: Cannot build a stub file.
Original error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1158
**************************************************
Exception: Your CUDA environment is invalid. Please check above error log.
たぶんnumpyとかのバージョンをいじったのが良くなかった。
rc.exeが無いのが問題らしいので
- C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64をシステム環境変数Pathに追加
- conda update conda からのconda update –all でモジュール群をアップデート
- conda create chainer34 python=3.5 anaconda で新たにpython環境を作り直し、chainerとcupyをインストール
したところ、問題なくインストールできた。
Deep Learningフレームワークごとに依存が違うのでvurtualenv必須ぽい。
コメント