Skip to content
/ airelien.dev
Go back
Aurélien AMSELLEM

Lucebox on Olares One — Episode 2: 2h of CUDA compile for 11 undefined references

First Docker build. 2h13 of CUDA compile for sm_120, and at link time, ld dumps 11 undefined references to cuMemCreate, cuMemMap, cuMemAddressReserve. Why? Because libcuda.so.1 isn't where it should be.

If you missed episode 1, quick recap: I’m trying to package Lucebox DFlash, a llama.cpp fork that speeds up generation with speculative decoding, as a Docker image for the Olares One (RTX 5090 Mobile, sm_120 consumer Blackwell). Nobody has done it yet. We kick off the first docker buildx build, and we trip as soon as we reach the link step.

The naive Dockerfile

Three simple steps in the builder: install the tools, clone the repo, then configure and compile with CMake (the tool that generates the project’s build commands).

FROM nvidia/cuda:13.0.0-devel-ubuntu22.04 AS builder

RUN apt-get update && apt-get install -y --no-install-recommends \
    git build-essential cmake ninja-build pkg-config \
    libcurl4-openssl-dev ca-certificates python3-pip python3-dev

WORKDIR /src
RUN git clone --depth 1 --recurse-submodules \
    https://github.com/Luce-Org/lucebox-hub /src/lucebox

WORKDIR /src/lucebox/dflash
RUN cmake -B build -S . \
    -DCMAKE_BUILD_TYPE=Release \
    -DGGML_CUDA=ON \
    -DCMAKE_CUDA_ARCHITECTURES="86;89;120" \
    && cmake --build build --target test_dflash -j $(nproc)

I’m targeting three CUDA architectures: Ampere (86, RTX 3090), Ada (89, RTX 4090) and consumer Blackwell (120, RTX 5090). Each extra architecture means one more full set of kernels to compile. Lucebox auto-detects sm_120 and rewrites it to 120a at config time, which I take as a good sign.

I run the build: docker buildx build --platform linux/amd64 -t aamsellem/lucebox-qwen36-blackwell:1.0.0 .

And I wait.

2h13 later

Compiling CUDA for 3 architectures on 16 vCPU inside an OrbStack VM takes a long, long time. The fattn-mma-f16-instance-*.cu.o files (Flash Attention multi-head template instances) take 30 to 90 seconds each, and there are dozens of them. On top of that come the mmq-instance-* (quantized matrix multiplications), the template-instances/fattn-vec-instance-*, and more.

At 7208 seconds (2h00), I’m at [90%]. At 8126s, [98%] Linking CXX static library libdflash27b.a. At 8202s, [100%] Linking CXX executable test_dflash. Yes!

Then boom:

/usr/bin/ld: warning: libcuda.so.1, needed by deps/llama.cpp/ggml/src/ggml-cuda/libggml-cuda.so.0.9.11, not found (try using -rpath or -rpath-link)
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemCreate'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemAddressReserve'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemUnmap'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemSetAccess'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuDeviceGet'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemAddressFree'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuGetErrorString'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuDeviceGetAttribute'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemMap'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemRelease'
/usr/bin/ld: libggml-cuda.so.0.9.11: undefined reference to `cuMemGetAllocationGranularity'
collect2: error: ld returned 1 exit status

To read this, you need to know that a C++ build happens in two steps. Compilation turns each source file into machine code, one file at a time. Then the linker (here ld) assembles all those pieces into an executable and checks that every function being called is defined somewhere. An “undefined reference” is a called function whose definition the linker couldn’t find anywhere.

The first line sums up the problem: libggml-cuda.so needs libcuda.so.1, and ld can’t find it. A .so file (shared object) is a shared library, code compiled separately that programs load at startup instead of carrying it inside them.

Then come eleven undefined references, all to CUDA Driver API functions, most of them from VMM (Virtual Memory Management, the GPU’s virtual memory handling). Compilation worked; it’s the link that failed. Ouch.

Why

On a regular NVIDIA machine, libcuda.so.1 ships with the driver, not with the CUDA toolkit (the development kit: compiler, headers, libraries). It lives at /usr/lib/x86_64-linux-gnu/libcuda.so.1, and it’s the NVIDIA driver install that puts it there, not the CUDA packages.

In a Docker container, the driver comes from the host machine, via the NVIDIA Container Toolkit, and only at runtime. At build time, inside an nvidia/cuda:13.0.0-devel image, there’s no driver.

NVIDIA planned for this by shipping a stub at /usr/local/cuda/lib64/stubs/libcuda.so. A stub is a dummy library: it exports every CUDA Driver API symbol (the function names) with no logic behind them. Its only job is to satisfy the linker. At build time, ld resolves symbols against the stub; at runtime, the host’s real libcuda.so.1 is used.

Except the stub is named libcuda.so, not libcuda.so.1. A library records the exact name of each library it depends on, version included, and libggml-cuda.so asks for the .1. So ld doesn’t find it and dumps the undefined references.

The fix that looked obvious

Two lines in the Dockerfile:

ENV LIBRARY_PATH="/usr/local/cuda/lib64/stubs:${LIBRARY_PATH}"
RUN ln -sf /usr/local/cuda/lib64/stubs/libcuda.so \
           /usr/local/cuda/lib64/stubs/libcuda.so.1

A libcuda.so.1 symlink pointing to the stub, and the stubs folder added to LIBRARY_PATH, the environment variable where the compiler looks for libraries at link time. Seems logical. I rerun.

2 hours of compile later…

Continued in episode 3, because LIBRARY_PATH doesn’t do what I thought it did.

See you next time!


Disclosure — All the benchmarks in this post run on my own Olares One. If the content was useful and you’re considering one, ordering through this referral link gets you $300 off ($4,699 instead of $4,999), stackable with the $300 Black Friday discount starting November 17: $600 off in total ($4,399). I’m mentioning this out of transparency — and yes, incidentally, it helps keep the blog alive (hosting, domain, and the time I spend writing here).

Share this post on:

Comments