Skip to content

fix(cutile): retain source origins for generated code and host checks - #1602

Merged
elibol merged 2 commits into
NVIDIA:mainfrom
elibol:fix/cutile-generated-source-provenance
Oct 22, 2026
Merged

elibol merged 2 commits into
NVIDIA:mainfrom
elibol:fix/cutile-generated-source-provenance

Conversation

@elibol

@elibol elibol commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Generated const-generic arrays and reduction bodies can point at the module header, and checks relocated to the host lose the original access and inline caller locations. Preserve those origins through compilation and show every distinct protected access when a shared launch check fails.

Part of #1475:

  • Attribute const-generic array materialization to the original signature for entry kernels, inlined functions, and inlined methods.
  • Attribute generated reduction-region operations to the reduction call, retaining its inline chain.
  • Deduplicate host checks by canonical predicate while retaining all distinct source origins internally in the compiler. Render the origins into the existing LaunchCheck.cause diagnostic at export, through the same path for KernelCompiler and the runtime validator. The public shared-host API, crate versions, dependencies, and check-evaluation behavior are unchanged.
  • Add exact source-file/line/caller-chain regressions for arrays, reductions, in-place/hoisted checks, loop/user assumptions, and deduplicated host errors. Device-check placement and assumption provenance already work on main; these cases protect that behavior.

Other claimed frontend work stays with #1385 (generated-constant fallback), #1480 (entry wrappers), and #1528 (short-circuit/folded expressions). This does not close the full audit. Actual assertion SIGTRAP/coredump attribution remains a Tile IR backend issue under #1379; caller-line breakpoint resolution belongs to NVIDIA/cuda-gdb#29 / #1476.

Validation on 825de3e38:

  • Both CI-equivalent semver commands pass for the host and Tile workspaces; no version update is required. Existing two-field LaunchCheck struct literals remain valid.
  • All CPU/assembler tests pass. Two new collection tests cover distinct/repeated/unknown origins, unchanged predicates and causes, and repeatable export.
  • All six source-location regressions pass, including real assembler/disassembler checks. They cover Line and Full modes, and host diagnostics additionally cover None. The array, reduction-region, and host-error cases fail on unchanged main (e027ac324).
  • All nine debug-info tests pass, including live CUDA-GDB, actual kernel execution, and cubin inspection. The GPU launch_checks_are_enforced_at_launch regression also passes.
  • Strict Clippy for the compiler library/tests and cuTile library/new test, root/Tile formatting, SPDX, and whitespace checks pass.

The earlier full-suite run on 89a3d688d passed CPU checks, 27 examples (one capability skip), and eight benchmark smoke tests. The GPU suite encountered the existing warmup-cache ordering failure documented in #1480; all 16 warmup tests passed serially. Benchmark validation supplied --features smoke-test because the existing runner drops its bare smoke-test argument. No runner changes are included.

Backend limitation: full-debug tileiras 13.3 coalesces one adjacent reduction source-line entry despite correct frontend metadata; all four call lines survive optimized line-info assembly. This change preserves frontend provenance and does not claim complete backend stepping accuracy.

@elibol

elibol commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

CI follow-up for the v0.5.0 candidate: the CUDA 13.2/13.4 Tile lanes, shared-host tests, and other functional checks passed, but semver-checks correctly rejects the new public LaunchCheck.origins field: existing downstream struct literals no longer compile while cuda-async is still version 0.4.0.

The compatibility change is documented in the PR, but that does not satisfy the version gate. Before merging, this needs either the coordinated v0.5.0 shared-host crate version/dependency updates or an API-compatible representation. Keep the semver check enabled. Failure details: https://github.com/NVIDIA/cuda-rust/actions/runs/39655891846/job/119416778266

@elibol

elibol commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Fixed the semver failure in 825de3e. Source frames now stay private to the compiler and are rendered into the existing LaunchCheck.cause string when checks are exported. LaunchCheck and the shared runtime are back to their original public API; no version bump or semver exemption is needed.

Validation: host and Tile semver suites pass; the CPU/assembler suite, two new collection tests, all six source-location regressions, all nine debug-info tests (including live CUDA-GDB), and the GPU host-check enforcement regression pass. Strict Clippy, formatting, SPDX, and whitespace checks pass. All build/test/semver CI jobs have now passed on this commit, including CUDA 13.2/13.4 and shared-host/reactor checks. Rust CodeQL also passed (verified 2026-10-22); all applicable CI checks are green.

Self-review completed:

  • Confirmed canonical predicates and one-comparison deduplication are unchanged, while distinct inline callers remain in diagnostics. Repeated export does not append duplicate origins; missing source data preserves the original cause.
  • Confirmed both standalone compilation and normal launches export through the same method after compilation, before the compiler is dropped. Runtime predicate evaluation is unchanged.
  • Checked that source-location guards end before ordinary user code resumes and retain the outer inline chain.
  • Tightened the array and reduction tests to verify the source file and reduction caller chain explicitly. No remaining correctness findings from this review. The backend trap/coredump issue remains outside this PR.

@elibol
elibol merged commit 9718b43 into NVIDIA:main Oct 22, 2026
26 checks passed
elibol added a commit that referenced this pull request Oct 30, 2026
…py (#1516)

Closes #1506. First change under #1460; implements the `bool` decision
recorded there and in #1461 and #1503.

Safe element casts previously checked size and alignment but could turn
a byte containing `2` into a Rust `bool`. This PR rejects those casts,
supports initialized `bool` buffers, and closes the host-side
initialization, atomic-reference, kernel-argument, and pinned-alignment
holes found during review and follow-up auditing.

## Element validity

`DeviceBuffer::cast_elem`, `cast_chunks`, `can_cast_chunks`, and
`Tensor::reinterpret` require `bytemuck::AnyBitPattern` on the target.
Casting into `bool` is therefore a compile error.

The two safe buffer casts also require `T: bytemuck::NoUninit` on their
source: padding or `MaybeUninit` bytes must not become initialized
destination values. `can_cast_chunks` remains a layout query. These
bounds do not restrict `DeviceCopy` itself, and bool-to-byte casts
remain supported.

`bool` implements `DeviceCopy`: valid values can be copied between host
and device, and its all-zero representation is valid. `DeviceCopy` does
not promise that every bit pattern is valid. It remains independent of
`DType`.

The numeric `DType` newtypes implement `Pod`, and `half` enables its
bytemuck feature, preserving numeric reinterpretation targets. cuda-core
re-exports `bytemuck` for downstream marker implementations. Vector
types in cuda-device also implement `Pod`, preserving `cast_chunks`
usage.

## Owned atomic-buffer conversions

`wrap_elem` and `peel_elem` use the unsafe marker `DeviceRepr<Inner>`.
Its contract requires identical layout, valid initialized
representations in both directions, no element destruction, and no
additional ownership obligations. It has no methods and grants no
reference conversions.

The integer and floating-point atomic macros implement `DeviceRepr`, not
`TransparentWrapper`. Consequently, safe
`DeviceAtomicU32::wrap_ref(&u32)` and the reverse `peel_ref` conversion
are unavailable. Owned scalar buffers can still be wrapped for atomic
kernel access and peeled for readback, retaining their allocation,
context, and deallocation stream. Kernel accesses must obey the existing
borrowing and synchronization contracts.

The marker lives in the dependency-free, `no_std` cuda-repr crate and is
re-exported by cuda-core and cuda-device. This lets both sides share one
trait without making kernel-only crates depend on the host runtime. The
dependent lockfiles add this local package without changing registry or
git dependencies. CI path filters include the new crate.

The atomic examples use `wrap_elem`/`peel_elem`. `KernelSliceArg` is not
restricted to `DeviceCopy`, since atomic wrappers are legitimate kernel
element types that cannot implement `Copy`.

## Completed zero-initialization

`DeviceBuffer::zeroed` queues the zero-fill and synchronizes its stream
before returning. A safe readback or launch on another stream can
therefore rely on initialization having completed, including for `bool`.
Empty allocations retain their fast path.

This makes nonempty `zeroed` a blocking constructor. Asynchronous
initialization with automatically retained completion dependencies
belongs to the subsequent runtime work; callers are not asked to repair
a safe API through manual synchronization.

## Host-side argument contracts and pinned alignment

`KernelInputStored` and `KernelOutputStored` now require `unsafe impl`.
Their contracts cover truthful dtype/layout/specialization metadata,
argument ABI, addressable extent, and storage/access retention through
completion and graph replay. Previously an entirely safe custom binding
could present `Tensor<bool>` storage as `u8` output, so a normal byte
kernel could write invalid bool values. The input counterpart could
similarly mislabel arbitrary byte storage as booleans. The safe
`KernelInput`/`KernelOutput` conversion traits remain available and must
return stored bindings satisfying those contracts. Existing owned,
borrowed, view, and mapped bindings retain their behavior.

`PinnedHostBuffer` reserves alignment slack, exposes an aligned interior
pointer, and retains the original CUDA pointer for deallocation. It also
rejects allocation sizes that exceed Rust slice/pointer-arithmetic
limits. Empty and zero-sized buffers keep their aligned dangling
pointers and allocation-free behavior.

## Tensor alias accounting

Tensor aliases and lazy copy operations share a separate ownership
token. Completion leases retain the storage itself without contributing
to that token. Uniqueness therefore stays correct while a lease is being
registered or destroyed: a real alias cannot become a mutable partition,
and retiring a lease cannot spuriously reject a unique tensor. Access
exclusion and completion retention remain enforced.

The acquisition and destruction regressions fail on the previous
implementation and pass with this change. A separate test preserves
ownership held by an unsubmitted copy operation.

## Compatibility and validation

The new `AnyBitPattern` target and `NoUninit` source bounds are breaking
changes for safe casts whose element types do not implement those
traits. Numeric targets remain supported; atomics use the owned-buffer
conversions. Tuple types remain usable as buffer elements but are not
reinterpretation targets. Custom stored Tile argument implementations
must now explicitly uphold the documented unsafe contract.

Earlier validation of the underlying changes:

- Full cuda-core and cuda-device tests, including GPU buffer tests,
compile-fail tests for invalid bool casts and both atomic
shared-reference conversions, and layout checks for all 21 scoped atomic
types.
- A gated-stream regression that fails without the initialization
synchronization and passes with it. It inspects bytes, avoiding invalid
Rust bool values in the failing case.
- Owned wrapper roundtrip coverage for pointer identity, context, stream
retention, and readback.
- GPU runs of `legacy_atomic_rmw_cas`, `legacy_atomic_fadd`, and
`hashmap` on an RTX 5090; all six Tile tensor reinterpretation tests.
- Clippy for cuda-core/cuda-repr, cuda-device/cuda-host, and cutile;
host and component formatting; cuda-core/cuda-repr rustdoc with warnings
denied.
- Device-only build, example lock consistency,
dependency-license/SPDX/source-reference/test-matrix guards, and
cargo-deny for the host, SIMT, backend, device-only, and Tile
workspaces.

The Tile UI snapshot now uses the normalized external-crate path. Both
UI harness tests (all 12 compile-fail cases) pass, and the CPU CI script
now runs them. The version-only update to the planned v0.5.0 API
boundary has landed on main in #1614; host and Tile semver checks pass.
SIMT workflow branch filters now include stacked PRs targeting
`pull-request/<n>` prerequisite mirrors.

Follow-up validation for the host-side argument and pinned-buffer fixes:

- Both new compile-fail cases compiled before the fix and now fail
specifically because `unsafe impl` is required; snapshots were reviewed
and rerun without overwrite.
- The pinned alignment regression failed before the fix, without
constructing misaligned references. It now passes, alongside
over-aligned copying, empty/ZST coverage, and allocation-size boundary
tests.
- Full cuda-core suite: 105 passed, 3 ignored. Selected Tile
library/GPU/tensor/view suites: 168 passed, 2 ignored.
Submission-lifetime suite: all 9 passed, including forgotten borrowed
work and graph replay.
- cuda-core and cutile Clippy with warnings denied, host/Tile
formatting, and SPDX checks passed. cuda-core rustdoc with warnings
denied passed. Tile documentation builds, but its stricter
warnings-as-errors check reports 12 existing link warnings outside the
added trait documentation.

Earlier host-argument follow-up validation: the complete CPU runner
passes (1,408 tests, 98 intentionally ignored), including the Tile UI
suites. All 25 targeted GPU buffer and pinned-host-buffer tests pass,
including the cross-stream initialization regression. The branch
includes the #1602 debug-source fixes and the same version metadata as
#1614.

Current validation (2026-10-30): head
`117205c1277a9e6d422df20499342690b412bc16` includes main through
`76ac10216`. The new regression fixture compiled before the
source-validity fix, then all five trybuild cases passed afterward
without snapshot regeneration. The new-main `math_special` example
lockfile includes the host dependencies at the versions used by other
examples; the full example dependency-policy guard passes. Fresh CI is
running. GitHub dismissed the previous approval after the source
changes, and renewed review has been requested.


The expanded atomics example from current main uses owned
`wrap_elem`/`peel_elem` conversions, with explicit checked ownership
transfer for its standard-library atomic case. Strict example Clippy
passes, and all 24 runtime atomic cases pass on both this PR and the
combined shared-host stack on RTX 5090 / CUDA 13.3.


Merge-readiness refresh (2026-10-30): head
`c5ea583c5b5f06b424a9ab0c48174c771e99ff52` includes main through the
merged #1480 (`b025a8b31`). The only manual conflict resolution
preserved both changelog entries; source and tests from #1480 merged
unchanged. The combined release candidate has an identical source/test
tree to previously validated `c6c5a860a` (only the changelog and merge
ancestry changed). New-head CI is running. Merge #1516 into main first,
then retarget #1603 to main and merge it, then retarget #1604 to main
and merge it. Do not merge the children into the temporary
`pull-request/*` bases. Issue/release inclusion tracking: #1606.

---------

Signed-off-by: Melih Elibol <[email protected]>
Co-authored-by: Melih Elibol <[email protected]>
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