Repository navigation
Description
Description
The vectorization example inspects its own generated PTX at runtime and asserts that f32x4_view_copy performs 128-bit ld.global/st.global transactions. It does not, and the example fails.
The copy is fused to 128 bits — but in the generic address space rather than global, so the example's ld.global search finds nothing. There is also a local-memory round trip in constructing the view.
Reproducer
cargo oxide run vectorization # fails the assertion
cargo oxide build vectorization --arch sm_75 # PTX alone is enough to see it
Actual behavior
Runtime report:
f32x4 float4 16 16 ld.global.v2.b64 yes
f64x4 double4 32 16 ld.global.v2.b64 yes
!! f32x4_view_copy has no 128-bit ld.global vector op
!! f32x4_view_copy has no 128-bit st.global vector op
✗ FAILED: 2 problem(s)
The emitted memory operations inside f32x4_view_copy:
cvta.global.u64 %rd58, %rd25;
st.local.v2.b32 [%rd34+8], {%r33, %r29};
ld.local.b64 %rd5, [%rd34+8];
cvta.global.u64 %rd60, %rd40;
st.local.v2.b32 [%rd48+8], {%r55, %r51};
ld.local.b64 %rd49, [%rd48+8];
ld.v2.b64 {%rd54, %rd55}, [%rd53];
st.v2.b64 [%rd56], {%rd54, %rd55};
Compare the direct f32x4 kernel in the same module, which is what the example expects:
ld.global.v2.b64 {%rd21, %rd22}, [%rd20];
st.global.v2.b64 [%rd3], {%rd21, %rd22};
So the width is right and the address space is not. The example's message is literally true but describes the wrong defect — worth fixing in the example's wording whatever the outcome here.
What I ruled out
- Not architecture-specific. Building for
sm_75andsm_90produces byte-identical output for this kernel, down to register numbers. (This also corrects an earlier version of this issue, which claimed newer hardware was needed to tell — the assertion reads generated PTX, so a compile-only build settles it with no GPU.) - Not a regression from fix(mir-lower): genericize named-space pointer values #626. I suspected the named-space genericization in
fix(mir-lower): genericize named-space pointer values, since this kernel observes a pointer's representation. Building at3f1cdaae^and at3f1cdaaegives identical PTX for this kernel, so that change is not the cause. - Not
.align 1on the parameters. Every kernel in the module declares.param .u64 .ptr .align 1, including the ones that do emitld.global.v2.b64, so parameter alignment is not the discriminator.
Likely never passed. The kernel, its 128-bit assertion, and the raw-pointer round trip all arrived together in #512 (2026-07-28). CI compiles examples without executing them, and this check runs at execution time, so it appears never to have been evaluated in CI.
Hypothesis — superseded, see the comment below
I originally suspected output.as_mut_ptr(). That is wrong: the input side never touches as_mut_ptr and is genericized too. Probes since have narrowed the trigger to vector::as_vectors itself, with a minimal reproducer that needs no quad copy at all, and have ruled out from_raw_parts, the address-exposure cast, parameter alignment, and #626. See the comment below for the reproducer and the eliminations.
Question
Should the global window survive a as_mut_ptr() / from_raw_parts round trip when the pointer provably stays in one space, or is the example's expectation simply wrong for a view built this way? The answer decides whether the fix belongs in lowering or in the example, and I would rather not guess at that boundary. Happy to implement either.
Environment
- GPU: Tesla T4 (sm_75, 15360 MiB); PTX comparison also built for sm_90
- CUDA driver version: 595.71.05
- nvcc:
Build cuda_13.2.r13.2/compiler.37434383_0 - Rust toolchain:
nightly-2026-04-03(perrust-toolchain.toml) - Source revision:
e28248c1
Found while running the full example suite on sm_75; the compute-capability gating problems that surfaced in the same run are filed separately as #656 and are unrelated.
Activity
[-]vectorization: `f32x4_view_copy` emits no 128-bit vector load/store[/-][+]vectorization: f32x4_view_copy accesses lower to generic space, not .global[/+]vyncint commentedon Aug 4, 2026
Narrowed this down with compile-only PTX probes. The trigger is
vector::as_vectorsitself, not the example's quad copy — which makes this an issue about the API rather than about one kernel.Minimal reproducer
No 16-byte copy, no
as_mut_ptr, nofrom_raw_parts_mut. Reading a single lane through anas_vectorsview is enough:This kernel carries its own control: the input is read through
as_vectors, the output is written through the ordinaryget_mutaccessor. Same kernel, same launch,--arch sm_75:The view's
(ptr, len)pair round-trips through local memory, and the pointer that comes back out has no address-space provenance left — so every subsequent access through the view is generic.What this is not
I tested each of these and they are all innocent:
.param ... .align 1on pointer parametersld.global.v2.b64. Not the discriminator.3f1cdaae^and3f1cdaaegives byte-identical PTX for the affected kernel, register numbers included. Not a regression from it.core::slice::from_raw_partsld.global.b32.slice.as_ptr() as usize(the alignment check's address exposure)ld.global.b32.sm_75andsm_90produce byte-identical PTX for this kernel.So the remaining difference between the probe that keeps
.globalandas_vectors, which does not, is narrow: the.cast::<V>()to an over-aligned element type, and/or theOption<&[V]>view not being scalarized away. I did not manage to separate those two, and did not want to guess again after four wrong suspects.Why this is worth more than the failing example
vector::as_vectorsdocuments itself as the path to full-width transactions: "Both are checked once here; every access through the returned slice is then a full-width transaction" (crates/cuda-device/src/vector.rs). If every access through such a view is generic-space and the view spills to local memory first, the API's documented benefit does not materialise, and thevectorizationexample is simply the only thing that noticed — because it is the only place that inspects the emitted PTX, and CI never executes it.The narrow question, if it helps: is the
Option<&[V]>expected to be scalarized here, and is the local round trip what destroys the address space, or is the.cast::<V>()alone enough to genericize? Happy to keep digging if you tell me which layer to look in.All PTX above is from
cargo oxide build, no GPU execution required.vyncint commentedon Aug 5, 2026
Correcting my previous comment: the
probe_as_vectors_lanereproducer in it is invalid, and this module's own documentation says so.crates/cuda-device/src/vector.rs:28-42documents, measured on sm_86:My probe read a single lane (
quads[i].as_slice()[0]), which is the third row — documented to scalarize. So it demonstrates intended behaviour, not this bug. Please disregard that reproducer. The case that matters is still the original one inf32x4_view_copy, where the quad is never decomposed:What still stands from that comment: the eliminations.
.align 1parameters, #626,core::slice::from_raw_parts, andslice.as_ptr() as usizewere each tested with probes that keepld.global, andsm_75/sm_90remain byte-identical. Those all speak to the address space, which is unaffected by the lane-decomposition caveat above.One more negative result since: adding
#[inline]toas_vectorsandas_vectors_mutchanges the emitted PTX not at all — byte-identical, register numbers included. So thest.local/ld.localpair is not a call-return spill; these generics were already being inlined. That kills the return-through-memory explanation too.The question I should have asked first
LDGandSTGin the table above are SASS. The example asserts on PTX text, searching for a 128-bitld.global:But what it emits is
ld.v2.b64— 128 bits wide, in the generic space.ptxasmay well lower that to a perfectly goodLDG.E.128, in which case the documented contract is met, the generated code is fine, and the example's assertion is simply checking the wrong thing — the.globalqualifier in PTX rather than the transaction width in SASS.I could not settle this: the AMI I have carries
ptxas,compute-sanitizer,ncuandcuda-gdb, but neithercuobjdumpnornvdisasm, so I have no way to read SASS. For anyone who has them, one command decides whether this issue is a codegen defect or an over-strict assertion:If
f32x4_view_copyshowsLDG.E.128/STG.E.128, this is an example bug and I am happy to send that patch — the message would also want rewording, since "has no 128-bit ld.global vector op" describes the wrong property either way. If it shows four scalarLDG.E, it is a real codegen issue and the generic address space is the lead worth pulling.Apologies for the noise in the previous comment.
vyncint commentedon Aug 5, 2026
Got SASS. It answers the question I left open two comments ago: this is a codegen pessimization, not an over-strict assertion — though the example's wording is wrong too.
Needed
cuda-cuobjdump-13-2andcuda-nvdisasm-13-2; the AMI I use ships neither, andcuobjdumpfails with "Could not find executable file 'nvdisasm'" if only the first is installed.Measured on sm_86
ptxas -arch=sm_86 -O3, memory operations per kernel:f32x4(direct)f32x4_view_copy(viaas_vectors)LDG.E.128×1,STG.E.128×1LD.E.128×1,ST.E.128×1LDL.64×2,STL.64×2The view path also carries 37
PRMTinstructions, 14LOP3.LUT, 10SELand 8SHF.R.U64— byte-level permutes and shifts that reassemble the quad piecewise. The direct kernel has none of that.What that means
The 128-bit width is achieved —
ld.v2.b64does becomeLD.E.128, so my worry that the transaction was being split was wrong. Two real costs remain:LD.E/ST.Erather thanLDG.E/STG.E: the access goes through the generic window instead of the global one.LDL.64/STL.64plus thePRMTchain, none of which the direct path needs — the quad is spilled and reassembled byte-wise.So the documented contract in
vector.rs:28-42("every access through the returned slice is then a full-width transaction",LDG.E.128/STG.E.128measured on sm_86) does not hold for a view taken withas_vectors, and the gap is 2 memory operations versus 6.Two separate fixes
The example's message is inaccurate and should be reworded whatever happens to the codegen. "has no 128-bit
ld.globalvector op" describes only the address space; the 128-bit op exists. Something like "performs its 128-bit access through the generic window, plus a local round trip" would describe what is actually there. I am happy to send that patch on its own — it is a strict improvement even if the codegen stays as it is.The codegen question is now narrow. Everything I ruled out earlier still holds (
.align 1parameters, #626,from_raw_partsalone,as_ptr() as usizealone,#[inline]on the constructors, and any architecture dependence —sm_75/sm_86/sm_90all agree). What remains is the.cast::<V>()to an over-aligned element type and theOption<&[V]>view that is not scalarized away, which is where the local traffic comes from.If you can say which layer should own that — keeping the global window across the cast, or scalarizing the
Optionso the slice never reaches memory — I will implement it. I would rather not pick that boundary myself; it is the same layering call that closed #636 and #638.docs(examples): frame the view-copy message as a regression diagnostic
docs(examples): vectorization misdescribes what f32x4_view_copy emits (…
perf(mir-lower): type an enum's unclaimed bytes as one integer (NVIDI…