"unable to allocate CUDA0 buffer" after Updating Ubuntu Packages

This guide provides step-by-step instructions to apply the kernel fix for addressing the CUDA buffer issue on a native Jetson Orin Nano setup.

Download source

  1. public_sources.tbz2
    https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v4.4/sources/public_sources.tbz2

  2. toolchain
    https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v3.0/toolchain/aarch64–glibc–stable-2022.08-1.tar.bz2

  3. Changes: (please unzip the files to *.diff files)
    7959247.diff.zip (1.7 KB)
    a94ca4c.diff.zip (1.2 KB)
    b27a1a7.diff.zip (1.5 KB)
    cfe6242.diff.zip (3.3 KB)
    e488812.diff.zip (2.0 KB)

Step 1: Verify Jetson Linux Version
head -n1 /etc/nv_tegra_release

Must show:

R36 (release), REVISION: 4.x

This procedure is only for r36.4.x.

Step 2: Check Disk, RAM & Swap (IMPORTANT)
Disk
df -h /

Ensure ≥ 30 GB free

RAM & Swap
free -h

If swap < 8 GB, create 16 GB swap:

sudo swapoff -a
sudo rm -f /swapfile
sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab

Step 3: Install Required Build Dependencies
sudo apt update
sudo apt install -y
build-essential
bc
flex
bison
libssl-dev
libncurses-dev
libelf-dev
git
rsync

Step 4: Download & Extract Kernel Sources

mkdir -p ~/jetson-kernel-fix
cd ~/jetson-kernel-fix

Download public_sources.tbz2 matching your exact r36.4.x release.

Extract:

tar xf public_sources.tbz2
tar xf aarch64–glibc–stable-2022.08-1.tar.bz2
cd Linux_for_Tegra/source
tar xf kernel_src.tbz2
tar xf kernel_oot_modules_src.tbz2
tar xf nvidia_kernel_display_driver_source.tbz2

Apply patches
Kernel patch:

cd ~/jetson-kernel-fix/Linux_for_Tegra/source/kernel/kernel-jammy-src
patch -p1 < ~/jetson-kernel-fix/a94ca4c.diff

NVIDIA OOT module patches (order matters):

cd ~/jetson-kernel-fix/Linux_for_Tegra/source/nvidia-oot

patch -p1 < ~/jetson-kernel-fix/cfe6242.diff
patch -p1 < ~/jetson-kernel-fix/e488812.diff
patch -p1 < ~/jetson-kernel-fix/b27a1a7.diff
patch -p1 < ~/jetson-kernel-fix/7959247.diff

Before you run: make sure the .diff files exist

If you only have *.diff.zip, unzip them like this:

cd ~/jetson-kernel-fix
for f in *.diff.zip; do unzip -o “$f”; done

Then run:

ls -lh ~/jetson-kernel-fix/*.diff

if you re run accidentally you can see below msg:

Reversed (or previously applied) patch detected!
Assume -R? [n]

This means the changes from a94ca4c.diff are ALREADY PRESENT in your kernel source.

Correct response

When prompted:

Assume -R? [n]

Press Enter (keep n)

This safely skips it.

4.1 Build kernel

cd ~/jetson-kernel-fix/Linux_for_Tegra/source
make -C kernel -j$(nproc)

4.2 Install modules + kernel image (keep a backup)
Backup your current kernel image first:

sudo cp /boot/Image /boot/Image.backup.$(date +%F)

Install modules + copy Image:

sudo make install -C kernel
sudo cp kernel/kernel-jammy-src/arch/arm64/boot/Image /boot/Image

Step 5: Build & install NVIDIA OOT modules

cd ~/jetson-kernel-fix/Linux_for_Tegra/source
export KERNEL_HEADERS=$PWD/kernel/kernel-jammy-src

make modules -j$(nproc)
sudo make modules_install

Step 6: Update initramfs + reboot

sudo update-initramfs -u
sudo reboot

Step 7: After reboot: verify CUDA stability
uname -r

verify:
ashwin-saravanan@ashwin-saravanan:~$ uname -r
5.15.148-tegra

now run ollama without any error:
ollama run phi3:mini

Step 8: Finally hold the update untill official release comes:

sudo apt-mark hold nvidia-l4t-display-kernel nvidia-l4t-kernel nvidia-l4t-kernel-dtbs nvidia-l4t-kernel-headers nvidia-l4t-kernel-oot-headers nvidia-l4t-kernel-oot-modules

10 Likes