Skip to content

fix(cuda): fall back to CUBIN when the driver rejects JIT'd PTX - #10

Merged
raphaelsty merged 2 commits into
masterfrom
fix/cuda-cubin-fallback
Jun 29, 2026
Merged

raphaelsty merged 2 commits into
masterfrom
fix/cuda-cubin-fallback

Conversation

@raphaelsty

@raphaelsty raphaelsty commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The CUDA k-means kernels are JIT-compiled to PTX and assembled by the driver. When the NVRTC toolkit is newer than the installed driver (e.g. a CUDA 13.1 toolkit on a CUDA 13.0 driver), the driver rejects the PTX with CUDA_ERROR_UNSUPPORTED_PTX_VERSION and the GPU k-means path dies (caller then falls back to CPU). This forces users into manual workarounds (hand-placing a driver-matched NVRTC on LD_LIBRARY_PATH).

Fix

Try the PTX path first (unchanged); only on failure, recompile the same kernels to a device-specific CUBIN (SASS) via nvrtcGetCUBIN and load it with cuModuleLoadData, which skips the driver's PTX->SASS JIT entirely. No version match needed, no LD_LIBRARY_PATH juggling.

Safety / backward-compat

  • CUDA-only: the code lives in the CUDA-gated cuda.rs; non-CUDA builds are unaffected.
  • Strictly additive: PTX is attempted first and unchanged; CUBIN only runs when PTX load fails (cases that are broken today). A host where the GPU works now is unchanged.
  • Builds verified with --features cuda and --features cuda-13.

Validation

On an H100 with a 13.1 toolkit / 13.0 driver, k-means clustering now runs on the GPU via the CUBIN fallback with no NVRTC workaround.

Release

Version bumped to 1.0.8 in this PR. After merge, tag v1.0.8 to trigger the
crates.io publish so downstreams (next-plaid) can depend on the fix.

The CUDA k-means kernels are JIT-compiled to PTX and assembled by the driver.
When the NVRTC toolkit is newer than the installed driver (e.g. a CUDA 13.1
toolkit on a CUDA 13.0 driver), the driver rejects the PTX with
CUDA_ERROR_UNSUPPORTED_PTX_VERSION and the GPU k-means path fails.

Try the PTX path first; only on failure recompile the kernels to a
device-specific CUBIN (SASS) via nvrtcGetCUBIN and load it directly, skipping
the driver's PTX JIT. CUDA-only and strictly additive: the fallback runs only
when the PTX load fails, so hosts where the GPU already works are unchanged.
@raphaelsty
raphaelsty force-pushed the fix/cuda-cubin-fallback branch from c7399f9 to 1979ea5 Compare June 29, 2026 15:13
@raphaelsty
raphaelsty merged commit 377e30d into master Jun 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant