Repository navigation
fix(llvm-export): refuse a kernel parameter pointing into shared or local memory - #772
Merged
nihalpasham merged 2 commits intoAug 10, 2026
Conversation
…ocal memory A kernel receives its parameters in .param space, filled by the host at launch. Shared memory is allocated per block and local memory per thread, both by the device, so the host holds no address in either to pass. The address space nonetheless reached the entry signature as `.ptr .shared`, ptxas assembled it, and the driver then refused the module, taking every other kernel in it down. generated_intrinsics_blackwell had such a kernel, so the module that example builds could not be loaded on the sm_120a it pins. Nothing caught it: the example is compile-only, and no CI runner has the device. Global and constant are left alone. The host allocates there, so a pointer parameter in those spaces is one it can supply, and the libdevice linking tests depend on it. Refusing every non-generic space broke three of them, which is how the rule was narrowed. A device function may carry any state space on its parameters, so this is checked for kernels alone. compile_tma_compatibility now declares its barrier as a shared static mut, the way examples/barrier already does, rather than taking one as a parameter it could never have been given. With the module loading, the example checks what it had only been compiling: the packed-FP8 and TF32 kernels are launched and all 42 results compared against the two formats, both being bit-exact. Every expected value derives from the format rather than from a previous run, and the relu cases pin the documented argument order, the first argument landing in the low byte. The example stays compile-only in CI, which has no Blackwell device to run it on.
The refusal landed without an automated test. Pin it at both layers. error_kernel_shared_param is a new error-category example: a #[kernel] taking *mut Barrier, which lowers to an addrspace(3) parameter. Its smoketest verdict greps for 'is a pointer into shared memory', so an unrelated compile failure cannot satisfy the fixture. The kernel body deliberately does nothing but keep the parameter, so the signature refusal is the only error it can produce. Wired into ERROR_EXAMPLES and STATUS.md; check-error-example-status.sh and check-example-smoketest-contract.sh both pass. export_test.rs pins the exporter check directly: an addrspace(3) and an addrspace(5) kernel parameter are refused by index and space name, generic/global/constant kernel parameters stay accepted, and a device (non-kernel) function keeps a shared parameter. Also spell out the deliberate scope at the check itself: addrspace(4) constant parameters stay allowed by design, and addrspace(7) (shared::cluster) is not user-reachable as a parameter type today; it would need a new arm if a frontend type ever surfaces one at a kernel boundary.
Collaborator
|
Verified end-to-end on sm_120:
Pushed one fixup:
Full workspace tests and the 192-example compile-only smoketest pass. |
nihalpasham
approved these changes
Aug 10, 2026
alejandro-soto-franco
deleted the
feat/blackwell-conversions-verified
branch
September 9, 2026 17:07
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 #771.
A kernel parameter pointing into shared memory reached the entry signature as
.ptr .shared. ptxas assembles that, and the driver then refuses the module, so every kernel in it becomes unreachable.generated_intrinsics_blackwellcontains such a kernel, which is why the module that example builds cannot be loaded on the architecture it pins.Summary
Refuses a kernel parameter in a state space the host cannot supply, repairs the kernel that had one, and checks the conversions on the device rather than only compiling them.
Changes
crates/llvm-export/src/export/function.rs: a kernel parameter that is a pointer into shared or local memory is refused, naming the kernel, the parameter index and the space.crates/rustc-codegen-cuda/examples/generated_intrinsics_blackwell/src/main.rs:compile_tma_compatibilitydeclares its barrier as a sharedstatic mutrather than taking one as a parameter, and the example launches the packed-FP8 and TF32 kernels and checks all 42 results against the two formats.Rationale
Shared memory is allocated per block and local memory per thread, both by the device at launch, so the host holds no address in either to put in a parameter. Global and constant are left alone: the host allocates there, a pointer parameter in those spaces is something it can pass, and the libdevice linking tests in
cuda-oxide-codegenrely on exactly that. A device function may carry any state space on its parameters, so the check is for kernels alone.The example's kernel could never have been launched. Removing the parameter costs nothing, since a barrier has to live in shared memory anyway, and
examples/barrieralready declares one as astatic mutinside the kernel.Removing that kernel is what makes the module load. With it repaired, the conversion kernels run, which is what the rest of this change uses. Their results are bit-exact, so there is no tolerance to pick, and every expected value derives from the format:
TF32 keeps the f32 exponent and truncates the mantissa to 10 bits, so each input chosen is already representable and all ten rounding forms agree, except the four relu forms on a negative input. The relu cases pin the argument order too:
cvt_rn_satfinite_relu_e4m3x2_f32(-1.0, 448.0)gives0x7e00, which is the low lane zeroed and the high lane kept, matching the documented "first argument in the low byte".The example stays compile-only in CI, since it pins
sm_120aand no runner has that device. On one that does, the conversions are now verified rather than assumed.Validation
RTX 5060 Laptop GPU, compute capability 12.0, CUDA 13.3, driver 610.43.03, target
sm_120a.Before this change, on that device:
After it, the example reports what the device computed:
42 checks, all passing. Changing one expected constant reports
MISMATCHand exits 1, so a wrong result is caught.The refusal was narrowed by the test suite rather than by reading: refusing every non-generic space broke three
libdevice_linkingtests whose kernels take a global pointer, which is legitimate.The reproducer from #771 now fails to compile with: