PIP を使用した NNabla CUDA 拡張機能パッケージのインストール

注 : OS 固有の依存関係の設定については、 OS 別ワークフロー を参照してください。

In addition to NNabla's requirements, CUDA extension requires CUDA setup has done on your system. If you don't have CUDA on your system, follow the procedure described below.

Download and install CUDA toolkit and cuDNN library(Registration required) (both runtime library and development library). Please follow the instruction in the document provided by NVIDIA. Do NOT see any instruction provided by any third party. They are often incorrect or based on old instructions, that could destroy your system.

NNabla CUDA 拡張機能パッケージである nnabla-ext-cuda をインストールすることで、 NVIDIA CUDA GPU による計算の高速化が可能です( CUDA を環境に合わせて設定する必要があります ) 。

各 CUDA バージョンとそれに対応する cuDNN バージョンに対して NNabla CUDA 拡張機能の pip パッケージが次のようにいくつか提供されています。

CUDA vs cuDNN 互換性

パッケージ名

CUDA バージョン

cuDNN バージョン

nnabla-ext-cuda110

11.0.3

8.0(Linux & Win)

nnabla-ext-cuda116

11.6.2

8.4(Linux & Win)

お使いの GPU が対応可能であれば、常に最新の CUDA バージョンを使用することを推奨します。

Currently, for each NNabla CUDA extension package, it may be not compatible with some specific GPUs.

After nnabla-ext-cuda package is installed, you can manually check whether your GPU is usable. For example, you can check GPU with device_id 0 by:

import nnabla_ext.cudnn
device_id = '0'
nnabla_ext.cudnn.check_gpu(device_id)

Above code will run successfully if your GPU is usable, otherwise, an error will be reported.

nnabla-ext-cuda package will also try to check the compatibility of your GPUs automatically when you use 'cuda' or 'cudnn' extension. By default, it will list and check all gpus in your machine. Error will be reported if there is incompatible card.

You can set environment variable 'AVAILABLE_GPU_NAMES' to tell it which GPU is usable, 'AVAILABLE_GPU_NAMES' is a white list, GPU in 'AVAILABLE_GPU_NAMES' will not cause error. For example, if you think GeForce RTX 3070 and GeForce RTX 3090 are usable, you can set environment variable as following:

export AVAILABLE_GPU_NAMES="GeForce RTX 3070,GeForce RTX 3090"

インストール

The following is an example of installing the extension for CUDA 11.0.3

pip install nnabla-ext-cuda110

次に、すべて機能するか確認します。

python -c "import nnabla_ext.cuda, nnabla_ext.cudnn"
2018-06-26 15:20:36,085 [nnabla][INFO]: Initializing CPU extension...
2018-06-26 15:20:36,257 [nnabla][INFO]: Initializing CUDA extension...
2018-06-26 15:20:36,257 [nnabla][INFO]: Initializing cuDNN extension...

Note: If you want to make sure the latest version will be installed, try to uninstall previously installed one with pip uninstall -y nnabla nnabla-ext-cuda110 beforehand.

Multi-GPU サポートのインストール

Multi-GPU wheel package is only available on python3.8+.

CUDA vs cuDNN 互換性

パッケージ名

CUDA バージョン

cuDNN バージョン

nnabla-ext-cuda110

11.0.3

8.0

nnabla-ext-cuda116

11.6.2

8.4

以下のようにインストールできます。

pip install nnabla
pip install nnabla-ext-cuda110

すでに NNabla をインストールしている場合は、すべてアンインストールするか、Anaconda 、venv を使って作成したクリーンな環境から始めてください。

You should also install OpenMPI and NCCL in addition to CUDA and CuDNN.

If you are using Ubuntu 20.04 and choose mpi4.0.3, you can install mpi with following command.

sudo apt install -y --no-install-recommends openmpi-bin libopenmpi-dev

Otherwise, you must install a version openmpi by supported on ubuntu 20.04. (e.g. 3.1.6 or 4.1.3). In theory, all versions of openmpi are supported.

MPIVER=3.1.6
curl -O https://download.open-mpi.org/release/open-mpi/v${MPIVER%.*}/openmpi-${MPIVER}.tar.bz2
tar xvf openmpi-${MPIVER}.tar.bz2
cd openmpi-${MPIVER}
./configure --with-sge
make
sudo make install

FAQ

Q. どの様に CUDA をインストールしますか?

NNabla CUDA 拡張機能は、 CUDA ツールキットと cuDNN ライブラリーの両方が必要です。 CUDA デバイスの機能に応じて、適切な CUDA バージョンを選択する必要があります。 公式のインストールガイド をご覧ください。 NNabla は CUDA バージョン 8.0 以降をサポートしています。特定の CUDA バージョンとのcuDNN の互換性については、 上記の表 をご覧ください。

Q. どの様に NCCL をインストールしますか?

NCCL にアクセスして、指示に従ってください。

Q. どの様に cuDNN の適切なバージョンを確認しますか?

以下のコマンドを入力。

python -c "import nnabla_ext.cuda, nnabla_ext.cudnn"

お使いのマシン上でバージョンの不一致が発生した場合は、エラーメッセージに適切なバージョンが表示されます。以下は、エラーメッセージの例です。

[nnabla][INFO]: Initializing CPU extension...
Please install CUDA version 11.0.3.
  and cuDNN version 8.0
  Or install correct nnabla-ext-cuda for installed version of CUDA/cuDNN.