Install Chainer/PyTorch with GPU Support

This documentation describes how to install Chainer/PyTorch with GPU suppport.


  • Nvidia GPU (ex. K80, TitanX, GTX 1080Ti).

  • Ubuntu (ex. 14.04, 16.04, 18.04).

    You can check whether your PC has a GPU by lspci | grep -i nvidia.

Version Compatibilities for 18.04

(Recommended) Use CUDA 9.1 from Official ubuntu repository (

(Experimental) Use CUDA 10.2 from Nvidia Developer’s site (

Install CUDA


# If you’d like to use CUDA8.0 on Ubuntu 14.04. wget mv cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64-deb cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb sudo apt-get update sudo apt-get install cuda


  • Add below to your ~/.bashrc:


    # setup cuda & cudnn export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH export LIBRARY_PATH=/usr/local/lib:/usr/lib:$LIBRARY_PATH export CPATH=/usr/include:$CPATH export CFLAGS=-I/usr/include export LDFLAGS=”-L/usr/local/lib -L/usr/lib” if [ -e /usr/local/cuda ]; then

    export CUDA_PATH=/usr/local/cuda export PATH=$CUDA_PATH/bin:$PATH export CPATH=$CUDA_PATH/include:$CPATH export LD_LIBRARY_PATH=$CUDA_PATH/lib64:$CUDA_PATH/lib:$LD_LIBRARY_PATH export CFLAGS=-I$CUDA_PATH/include export LDFLAGS=”-L$CUDA_PATH/lib64 -L$CUDA_PATH/lib”


# If you’d like to use CUDA9.2 on Ubuntu 16.04. # Choose the green buttons on the web page like x86_64 -> Ubuntu -> version -> deb (network). # Excute 1-3 and then, change step 4 as follows: sudo apt install cuda-9-2


  • Ubuntu 18.04 : You can use CUDA 9.1 by deafult

    ```bash sudo apt install nvidia-cuda-toolkit sudo apt install nvidia-cuda-dev

  • (Experimental) Ubuntu 18.04 : CUDA 10.2 is the latest version which supports jsk_perception. Download deb file from

    # If you'd like to use CUDA10.2 on Ubuntu 18.04.
    # goto
    # Choose the green buttons on the web page like x86_64 -> Ubuntu -> version -> deb (network).
    # Excute all steps, but change the last step as follows:
    sudo apt install cuda-10-2
    • If you install CUDA from nvidia, Make sure to uninstall CUDA tools from

      `bash sudo apt remove nvidia-cuda-toolkit sudo apt remove nvidia-cuda-dev `

    • Also set environment variables to ~/.bashrc

      ```bash # set PATH for cuda 10.0 installation if [ -d “/usr/local/cuda-10.2/bin/” ]; then

      export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} export CFLAGS=-I/usr/local/cuda-10.2/include

  • After rebooting, you can see the memory usage of your GPU by nvidia-smi

Install CUDNN

  • If you install pip install cupy-cuda91, you do not need to install CUDNN manually. (c.f. Thus, default 18.04 user can use CUDA 9.1 and cupy-cuda91==6.7.0 for chainer==6.7.0 and you can SKIP this section.

    Installing CUDNN manually only requires for experimental user who install CUDA 10.2 manually.

  • You need to login at

  • Go to cuDNN Download and choose version

  • Download deb files of cuDNN Runtime Library and cuDNN Developer Library


# If you’d like to install cuDNN for CUDA9.2 on Ubuntu 16.04 # Download cuDNN v7.3.1 Runtime Library for Ubuntu16.04 (Deb) sudo dpkg -i libcudnn7_7.3.1.20-1+cuda9.2_amd64.deb # Download cuDNN v7.3.1 Developer Library for Ubuntu16.04 (Deb) sudo dpkg -i libcudnn7-dev_7.3.1.20-1+cuda9.2_amd64.deb # Download cuDNN v7.6.5 Developer Library for Ubuntu18.04 (Deb) sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb


Install Chainer


sudo pip install chainer==6.7.0


Install Cupy

  • (Default) Chainer 6.7.0 requires CuPy 6.7.0 and if you have CUDA 9.1, you can use CuPy pre-compiled binary package.

    • Pre-compiled Install Cupy for CUDA 9.1


      sudo pip install cupy-cuda91==6.7.0 ```

  • (Experimental) If you have newer CUDA version. You need to install CuPy with source distribution. This requires CUDNN before you run pip install cupy .

    • Source Install Cupy for CUDA 10.2


      sudo pip install -vvv cupy –no-cache-dir ```

Install PyTorch


sudo pip install torch-1.1.0-cp27-cp27mu-linux_x86_64.whl sudo pip install torchvision-0.3.0-cp27-cp27mu-manylinux1_x86_64.whl


  • (Experimental) If you manually install CUDA 10.2 manually, you can use latest PyTorch.


sudo pip install torch==1.4.0


Try Chainer Samples

You can try to run samples to check if the installation succeeded:

roslaunch jsk_perception sample_fcn_object_segmentation.launch gpu:=0
roslaunch jsk_perception sample_people_pose_estimation_2d.launch GPU:=0
roslaunch jsk_perception sample_regional_feature_based_object_recognition.launch GPU:=0

Try PyTorch Samples

You can try to run samples to check if the installation succeeded:

roslaunch jsk_perception sample_hand_pose_estimation_2d.launch gpu:=0

Trouble Shooting

  • After installing CUDA and rebooting, nvidia-smi returns command not found

If your PC uses dual boot, please check BIOS setting and secure boot is disabled.

  • When installing jsk_perception, rosdep install --from-paths --ignore-src -y -r src fails due to pip version:

Please make sure you have pip >= 9.0.1. If not, please try sudo python -m pip install pip==9.0.1, for example. Please do not execute pip install -U pip. (2018.11.20)