fix(qdp-core): link cudart locally and stub FFI when toolkit is absent #1321
Open
andrewmusselman wants to merge 1 commit into
Open
fix(qdp-core): link cudart locally and stub FFI when toolkit is absent #1321andrewmusselman wants to merge 1 commit into
andrewmusselman wants to merge 1 commit into
Conversation
Member
|
Like the high-level idea:
|
ryankert01
reviewed
May 19, 2026
| /// This function: | ||
| /// * emits `cargo:rustc-link-lib=cudart` and the appropriate | ||
| /// `cargo:rustc-link-search` path when nvcc is found, and | ||
| /// * emits `cargo:rustc-cfg=qdp_no_cuda` when it is not, gating the |
Member
There was a problem hiding this comment.
output().is_ok() is true even if nvcc exits non-zero — a half-installed nvcc would set has_cuda = true and fall through to a link error. Suggest .map(|o| o.status.success()).unwrap_or(false). Same idiom in qdp-kernels/build.rs:177; fix both so they can't disagree.
| /// | ||
| /// `qdp-core` declares CUDA Runtime API extern symbols in `src/gpu/cuda_ffi.rs` | ||
| /// (cudaHostAlloc, cudaMemGetInfo, cudaEventCreateWithFlags, ...). Those symbols | ||
| /// must be resolved at link time, which requires `libcudart` from the CUDA |
Member
There was a problem hiding this comment.
Missing cargo:rerun-if-env-changed=PATH. The whole decision hinges on nvcc-on-PATH, so installing CUDA after a stub build won't re-trigger the script until cargo clean. Same gap in qdp-kernels.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1318 .
qdp-core/build.rs(extended; it already existed for protoc) now:nvccwith the same logic asqdp-kernels/build.rs,cargo:rustc-link-search=native=$CUDA_PATH/lib64andcargo:rustc-link-lib=cudartwhen found,cargo:rustc-cfg=qdp_no_cudawhen not found, with a clearcargo:warningpointing at the toolkit install,QDP_NO_CUDA=1for explicit forcing (matchingqdp-kernels).qdp-core/src/gpu/cuda_ffi.rswraps theextern "C"block in#[cfg(not(qdp_no_cuda))]and adds matching#[cfg(qdp_no_cuda)] mod no_cuda_stubs { ... }withpub(crate) unsafe fnstubs for all 14declared functions. Each stub returns
999— the same sentinelqdp-kernelsuses for its kernel-launcher stubs — so existing callererror paths (
if ret != 0 { return Err(...) }) surface a clean runtimeerror if anyone calls a CUDA function on a no-toolkit build, instead of
failing at link time. The whole stub module is wrapped in a single
#[allow(non_snake_case)]since the originals are camelCase to matchthe real CUDA Runtime API.
Cross-crate behaviour after this PR:
QDP_NO_CUDA=1Verified on Linux + CUDA 12.4:
cargo build --workspace --tests --exclude qdp-pythonsucceeds both with and withoutQDP_NO_CUDA=1;make test_rustruns full integration tests on the GPU; 12 lintwarnings introduced by the stubs are silenced.