Install PyCUDA on Jetson Nano

3 Step Set up and get started (+ test code)

Winston Robson
Dropout Analytics
Oct 17, 2020

--

Step 1 — Install PyCUDA

Install PyCUDA with PIP;

pip install pycuda

If you don’t have pip, get pip.

Step 2 — Set nvcc Path

Nvcc comes preinstalled, but your Nano isn’t exactly told about it.. Use sudo to open your bashrc file;

sudo gedit ~/.bashrc

Add a blank, then these 2 lines (letting your Nano know where CUDA is) to the bottom of the file;

export PATH=${PATH}:/usr/local/cuda/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib64

Save, close, then (back in Terminal) source the bashrc file

source ~/.bashrc

You can now check your nvcc version with;

nvcc --version

Step 3 — Test with Code

By using PyCUDA’s SourceModule to create a function (add_them) with CUDA C code, we can simply .get_function() it into python.

From there, we make 2 arrays of random floats (a, b), and an array of 0s which will be replaced by the results of running our function (i.e. each 0 will be replaced by the result of a + b at its index).

After we run the function, printing the results (dest) minus the values added (a, b) should output a list of floating point 0s (0.).

And it does.

Fin

Thanks for reading. Please feel free to respond with any questions.

Continued Reading

--

--

Winston Robson
Dropout Analytics

Friend links: https://gumdropsteve.github.io/blog — “Energy may be likened to the bending of a crossbow, decision to the releasing of a trigger.”