Install CUDA 10.2 and MXNet on Ubuntu 18.04

This is a record of my experience of installing CUDA, cuDNN and MXNet on Ubuntu 18.04. As a new fish, these applications cost me over 10 hours to perfectly install, which makes me feel really important to write down some details for your reference.

Select Platform and Version

Obviously, we prefer to install and run programs on Windows. But though I smoothly installed CUDA and cuDNN on Win10, I cannot install MXNet through pip. Because there is NO such module suitable for Win10. You can check it on Pypi.org

So I turned to try it on Ubuntu. I didn’t know GPU cannot be virtualized so It took me really lots of time. BTW, the Windows subsystem for Linux seems also not capable to install CUDA.

Thus, there is only one way left: dual system

Install Ubuntu

First, you need to use Rufus to make a bootable USB to install Ubuntu. It’s quite easy. Please search on Google if you need further references.

Since the Ubuntu system have the access to the whole disk even if the space you allocated to it is limited. So the Ubuntu system may only need 20 to 40 GB disk space.

Ubuntu 18.04 is recommended.

  • Ubuntu 16 is also OK but I don’t like just because it does not support editing terminal shortcut
  • Ubuntu 20 is not recommended because CUDA 9.2 and CUDA 10.2 does not officially support Ubuntu 20. Although they seem capable to install on Ubuntu 20

Install CUDA

If you want to use MXNet, please don’t install CUDA 11 because MXNet does not support CUDA 11 for now (Sep 2020). CUDA 10.2 is recommended.

A simple way to install CUDA 10.2 is to download the runfile: developer.nvidia.com

Before running the command sudo sh cuda_10.2.89_440.33.01_linux.run, you REALLY SHOULD check the instructions in official document.

Gcc version

CUDA requires some certain versions of gcc and g++. For the combination in this article, version should not be a problem. But if you want to install CUDA on Ubuntu 16 or other releases, you need to take care of this problem. For example, CUDA 10.2 needs gcc-7 to install on Ubuntu 18. reference

Disable nouveau

How to: reference

This is the tricky part tortured me for hours.

If you skip this part and run the sh command above, you will fail to install and get an exit code 256 which means fucking nothing. Please follow the official document above to disable nouveau. Note: you will need to reboot.

You can confirm nouveau is disabled by command lsmod | grep nouveau. If successful, it will output nothing.

But even if you disabled the nouveau, and rebooted, you probably still cannot install CUDA perfectly. And even if you successfully installed CUDA, your display resolution may have severe trouble. I am not sure why and tried a lot of times.

I guess this is related to displaying desktop GUI, so I tried init 3 to disable displaying desktop. And that was amazing, I finally installed CUDA perfectly. You can use init 5 to switch to desktop but it’s better to reboot.

You can check your CUDA version by command /usr/local/cuda/bin/nvcc -V.

You can create a soft link for convenience: ln -s /usr/local/cuda/bin/nvcc /usr/bin/nvcc.

And now you can simply use nvcc -V to check CUDA version.

reinstall Nvidia driver

If the disable nouveau step cannot fix your problem, you might need to reinstall Nvidia driver.

Install DKMS

What is

Install command: sudo apt install dkms

Before install, you need to know what is your current version of Nvidia driver: whereis nvidia

Replace the command with your driver version(showed in the output above): sudo dkms install -m nvidia -v YOUR-VERSION

Reboot your system.

Install cuDNN

Another easy process. You only need to login to developer.nvidia.com and download corresponding version of cuDNN (cuDNN Library for Linux (x86)).

Then, finish installing by copy files under cuDNN sub-directory to corresponding sub-directory under /usr/local/cuda.

Install MXNet

Pip is a easy way to install MXNet: pip install mxnet-cu102. reference

End

Fine. This is it. Though seems easy after success, it was really hard at the first stage. Hope this article helps you.

Comments