Linux

As we've discussed, once CUDA is set up nicely, running your Gorgonia code on your GPU is as simple as adding -tags=cuda when building it. But how do we get to a point where that is possible? Let's find out.

This guide requires you to install standard Ubuntu 18.04. NVIDIA provides distribution-independent instructions (and troubleshooting steps) at: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html.

At a high level, you need to install the following packages:

  • NVIDIA driver
  • CUDA
  • cuDNN
  • libcupti-dev

First, you need to ensure you have NVIDIA's proprietary (not the open source default) driver installed. A quick way to check whether you are running it is to execute nvidia-smi. You should see output similar to the following, which indicates the driver version number and other details about your GPU:

If you get command not found, you have a couple of options, depending on the distribution of Linux you are running. The latest Ubuntu distribution allows you to install most of CUDA's dependencies (including the proprietary NVIDIA driver) from the default repositories. This can be done by executing the following:

sudo apt install nvidia-390 nvidia-cuda-toolkit libcupti-dev

Alternatively, you can follow the steps in the official NVIDIA guide (linked previously) to manually install the various dependencies.

Once the installation has completed and you have rebooted your system, confirm that the drivers are installed by running nvidia-smi again. You also need to verify that the CUDA C compiler (part of the nvidia-cuda-toolkit package) is installed by executing nvcc --version. The output should look similar to the following:

Once CUDA itself is installed, there are some additional steps you need to perform to ensure that Gorgonia has the necessary CUDA libraries compiled and available for use:

  1. Ensure that the target directory for the modules you are building exists. If not, create it with the following command:
mkdir $GOPATH/src/gorgonia.org/gorgonia/cuda modules/target
  1. Run cudagen to build the modules as follows:
cd $GOPATH/src/gorgonia.org/gorgonia/cmd/cudagen
go run main.go
  1. After the program executes, verify that the /target directory is populated with files representing CUDA-fied operations that we will use when building our networks, as shown in the following screenshot:

  1. Now that the preliminaries are out of the way, let's test that everything is working using the following commands:
go install gorgonia.org/cu/cmd/cudatest cudatest
cd $GOPATH/src/gorgonia.org/cu/cmd/cudatest
go run main.go

You should see output similar to the following:

You're now ready to take advantage of all the computing capacity provided by your GPU!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset