Skip to content

Commit 82b8d40

Browse files
committed
feat(examples): reach the driver through the index rather than an env var
The example previously needed LD_LIBRARY_PATH pointing at the xim sentinel, because nothing declared a runtime search directory for the driver's userspace library. compat.cuda-runtime now does, so the dependency is an ordinary one and mcpp run works unaided. The two packages divide the question by layer. libcuda-host-link in xim owns where the host's copy is, so no consumer reimplements an ldconfig probe. compat.cuda-runtime in mcpp-index owns how a built artifact reaches it, which needs a directory on the runtime search path and is therefore something only an mcpp package can declare. Verified end to end on an RTX 4080: mcpp run prints 12 24 36 48 with no environment variables set.
1 parent 069a3db commit 82b8d40

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

examples/09-cuda-kernel/README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,34 @@ $ mcpp run
6868

6969
which is `2.0 * [1,2,3,4] + [10,20,30,40]` computed on the device.
7070

71-
## The one thing that is not closed yet
71+
## Where the driver comes from
7272

7373
The CUDA runtime is linked statically, so the artifact carries every
7474
redistributable component. That leaves exactly one host dependency,
7575
`libcuda.so.1` — the driver's userspace library, which NVIDIA's licence forbids
7676
redistributing and which is in ABI lockstep with the kernel module.
7777

78-
xim already has the right shape for this: `libcuda-host-link` is a sentinel
79-
package that installs a symlink to whatever the host has, so every GPU consumer
80-
reads one path instead of reimplementing an `ldconfig` probe. This example
81-
declares it under `[xlings] deps`.
78+
Reaching it takes two packages, one per layer.
8279

83-
What is missing is the last hop. `[xlings] deps` provisions the payload and
84-
puts its `bin/` on `PATH`, which is what a payload providing a *program* needs.
85-
A payload providing a *library* also needs its `lib/` on the artifact's runtime
86-
search path, and mcpp's private loader does not consult `/usr/lib`, so without
87-
that hop the statically linked CUDA runtime cannot `dlopen` the driver and
88-
reports it as "driver version is insufficient". Until an mcpp-index package
89-
declares that directory, the run needs it supplied:
80+
`libcuda-host-link` in xim owns the question of *where* the host's copy is. It
81+
installs a symlink to whatever the machine has, so every GPU consumer reads one
82+
path instead of reimplementing an `ldconfig` probe.
83+
84+
`compat.cuda-runtime` in mcpp-index owns the mcpp-side question of how a
85+
**built artifact** reaches it. mcpp's private loader does not consult
86+
`/usr/lib`, so a bare-soname `dlopen` from inside a built program finds nothing;
87+
the package declares a directory on the artifact's runtime search path and links
88+
through the sentinel. It is declared here as an ordinary dependency:
89+
90+
```toml
91+
[dependencies.compat]
92+
cuda-runtime = "2026.09.05"
93+
```
94+
95+
Without it the program builds and links, then reports
9096

9197
```
92-
$ LD_LIBRARY_PATH=$(xlings pkginfo libcuda-host-link)/lib mcpp run
98+
cudaMalloc: CUDA driver version is insufficient for CUDA runtime version
9399
```
94100

95-
This is an ecosystem gap, not a defect in the design: the durable fix is a
96-
`compat.cuda-driver` package in mcpp-index that wraps the sentinel and declares
97-
its library directory, which is the same shape every other runtime provider in
98-
that index already has.
101+
which is what the runtime says when it cannot open the driver at all.

examples/09-cuda-kernel/app/mcpp.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import_std = true
1313
[dependencies]
1414
rules-cuda = { path = "../rules-cuda", host-module = true }
1515

16+
# The driver's userspace library, reached through an index package that owns
17+
# the one hop mcpp needs: a directory on the artifact's runtime search path.
18+
# mcpp's private loader does not consult /usr/lib, so without it the statically
19+
# linked CUDA runtime cannot dlopen the driver.
20+
[dependencies.compat]
21+
cuda-runtime = "2026.09.05"
22+
1623
# The driver's userspace library, reached through the sentinel package.
1724
#
1825
# It is the one CUDA component that cannot be an ordinary payload: NVIDIA's

0 commit comments

Comments
 (0)