CodeTheRobot

Ubuntu Linux for Robotics · Lesson 31 of 96

GPU support on Jetson and desktop GPUs

NVIDIA drivers, JetPack, checking the GPU, and CUDA in containers.

Estimated time · 60–90 min

Learning goals

What you will understand

  • Explain gpu support on jetson and desktop gpus in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

Perception (neural-network detection, depth processing) is much faster on a GPU. On a desktop or laptop install the NVIDIA driver with sudo ubuntu-drivers install and check it with nvidia-smi. On an NVIDIA Jetson the operating system comes from JetPack (Ubuntu plus the drivers, CUDA and TensorRT), installed with the vendor's flashing tool, and tegrastats shows GPU use.

For containers use the NVIDIA Container Toolkit so --gpus all works, and pick images built for your architecture (arm64 on Jetson). Watch power mode and temperature: a Jetson throttles when it gets hot. Only use a Jetson feature if your JetPack version supports your Ubuntu and ROS 2 release.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the gpu support on jetson and desktop gpus commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

ubuntu-drivers devices
# Show the recommended NVIDIA driver for your GPU.
sudo ubuntu-drivers install
# Install the recommended driver (reboot afterwards).
nvidia-smi
# Show the GPU, driver version, memory use and temperature.
sudo tegrastats
# On a Jetson: live CPU, GPU, memory and temperature.
sudo nvpmodel -q
# On a Jetson: show the current power mode.
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smi
# Prove that a container can see the GPU.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

Watch it run · The robot's computer

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

robot computercpumemdiskdriverstoppedplannerstoppedloggerstoppedsafetystoppedTHE ROBOT'S COMPUTER

Demo for GPU support on Jetson and desktop GPUs. Expected result: A table with the GPU name, driver version and memory usage

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

# TODO: print the state of the NVIDIA GPU

Expected output

A table with the GPU name, driver version and memory usage
Stuck? Show the full solution (try it yourself first)
nvidia-smi

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Check that your GPU is visible with nvidia-smi (or tegrastats on a Jetson), run a container with --gpus all, and record temperature and utilization while running an object detector.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.