Repository navigation
Description
Summary
A kernel that calls core::hint::black_box(x) fails device codegen with a raw internal message, and the two things black_box
is most often used for on the device — keeping a load/store from being moved, and keeping an arithmetic pair from being
fused — have no per-function equivalent.
Repro (5 lines)
#[kernel]
pub fn bb_probe(x: &[f32], y: &mut [f32]) {
let t = thread::index_1d().get();
if t < x.len() && t < y.len() {
y[t] = core::hint::black_box(x[t]);
}
}error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed: Translation failed: bb_probe:
[".../lib/rustlib/src/rust/library/core/src/hint.rs": line: 491, column: 5]
Compilation error: invalid input program.
Unsupported construct: rustc intrinsic `std::intrinsics::black_box` is not yet supported on the device
Environment
348895e4, CUDA toolkit 13.4 (V13.4.92), driver 615.78.08, NVIDIA RTX PRO 4500 Blackwell (compute capability 12.0, sm_120),
Rust 1.99.1. Reproduced with cargo oxide build -- --release --bin <bin> --features "cuda simt".
What exists instead, and what does not
To be precise about "no alternative", since this issue was first filed:
- Build-wide contraction control exists and works:
CUDA_OXIDE_NO_FMA=1(orcargo oxide build --no-fmad) produces
contraction-free PTX at this revision. Measured behaviourally — the same bit-exactness case that fails when the rounding
helpers are inlined passes under the flag (3 of 32 values differ without it, 0 of 32 with it). It is also documented
(gpu-programming/error-handling-and-debugging.md). - There is no per-function/per-kernel equivalent, so a crate that needs exact rounding in one kernel pays for the flag
everywhere else. The workaround is non-generic#[inline(never)]helpers around the multiply and the add, which the book
confirms lower tonoinline/call.uni; it costs a call per operation and silently stops working if the helper gains a type
or const parameter.
Ask
- lower
black_boxto an optimisation barrier on the device (it needs no code — only "do not move or fuse across this"), or - if it stays unsupported, document the rejection and name the supported way to get the same effect.
Context
Found in a downstream engine (Craton) while making a float kernel bit-identical to its host reference: the device contracts
residual += b * w into one rounding while the host performs two, which moved a stage sum in its 7th digit. black_box was the
first thing reached for.
Activity
[-]device codegen rejects `core::hint::black_box` with no documented alternative (e.g. for blocking fp contraction)[/-][+]device codegen rejects `core::hint::black_box`; no per-function equivalent for an optimisation barrier[/+]