Skip to content

docs(cuda-macros): the README omits #[constant], and its only derive - #1057

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:docs/cuda-macros-constant-devicecopy
Aug 20, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:docs/cuda-macros-constant-devicecopy

Conversation

@vyncint

@vyncint vyncint commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

cuda-macros exports sixteen macros. Its 500-line README documents fourteen. The two it never mentions are #[constant] and #[derive(DeviceCopy)] — and the second is the crate's only derive macro.

The omissions are connected

The "Source Layout" tree lists three files under src/:

├── lib.rs       # All proc-macro definitions (kernel, device, launch, etc.)
├── printf.rs    # gpu_printf! implementation
└── ptx_asm.rs   # ptx_asm! implementation

There are four. device_copy.rs — the derive's whole implementation — is not in the tree either, so nothing in the README points at the macro or at the file that defines it.

What each section says

#[constant] gets the three restrictions that decide whether it works, from its own rustdoc: the initializer must be ConstantMemory::UNINIT (non-zero initializers are not honored yet), it must appear inside a #[cuda_module] — elsewhere it silently produces an unreachable symbol with no setter, which is the failure mode worth warning about — and the identifier must not start with the reserved prefix. Both generated setters are named, with the stream-ordered one marked as the one to prefer.

#[derive(DeviceCopy)] gets what makes it more than Copy: the trait is unsafe and promises every bit pattern is valid, which DeviceBuffer relies on when it turns raw device bytes back into values. It also records that structs and unions are accepted and enums are rejected with a diagnostic, since that is the first thing someone tries.

Verification

Against the tree:

  • The sixteen exported macros — eleven #[proc_macro_attribute], four #[proc_macro], one #[proc_macro_derive] — are now all named in the README, and the four files under src/ are all in the tree.
  • The #[constant] snippet is the shape examples/constant_memory_coeffs/src/main.rs already uses, line for line.
  • DeviceCopy's Copy bound, its bool/char/NonZeroU32 rationale and its enum rejection come from cuda-core/src/device_buffer.rs and cuda-macros/src/device_copy.rs; the derive example matches the #[derive(Copy, Clone, DeviceCopy)] form in cuda-core's trybuild fixtures.

Documentation only — no source file changes, so #[constant]'s and the derive's behaviour is untouched.

vyncint and others added 2 commits August 20, 2026 06:33
`cuda-macros` exports sixteen macros. Its 500-line README documents fourteen.
The two it never mentions are `#[constant]` and `#[derive(DeviceCopy)]`, and
the second is the crate's only derive macro.

The omissions are connected. The "Source Layout" tree lists three files under
`src/`:

    ├── lib.rs       # All proc-macro definitions (kernel, device, launch, etc.)
    ├── printf.rs    # gpu_printf! implementation
    └── ptx_asm.rs   # ptx_asm! implementation

There are four. `device_copy.rs` -- the derive's whole implementation -- is not
in the tree either, so nothing in the README points at the macro or at the file
that defines it.

Add a section for each, and the fourth file to the tree.

`#[constant]` gets the three restrictions that decide whether it works, taken
from its own rustdoc: the initializer must be `ConstantMemory::UNINIT` because
non-zero initializers are not honored yet, it must appear inside a
`#[cuda_module]` (elsewhere it silently produces an unreachable symbol with no
setter, which is the failure mode worth warning about), and the identifier must
not start with the reserved prefix. Both generated setters are named, with the
stream-ordered one marked as the one to prefer.

`#[derive(DeviceCopy)]` gets what makes it more than `Copy`: the trait is
`unsafe` and promises every bit pattern is valid, which `DeviceBuffer` relies on
when it turns raw device bytes back into values. The example is the real
`#[derive(Copy, Clone, DeviceCopy)]` form used in `cuda-core`'s trybuild
fixtures. It also records that structs and unions are accepted and enums are
rejected with a diagnostic, since that is the first thing someone tries.

Verified against the tree: the sixteen exported macros (eleven
`#[proc_macro_attribute]`, four `#[proc_macro]`, one `#[proc_macro_derive]`) are
now all named in the README, and the four files under `src/` are all in the
tree. The `#[constant]` snippet is the shape
`examples/constant_memory_coeffs/src/main.rs` already uses; `DeviceCopy`'s
`Copy` bound, its `bool`/`char`/`NonZeroU32` rationale and its enum rejection
all come from `cuda-core/src/device_buffer.rs` and
`cuda-macros/src/device_copy.rs`.

Signed-off-by: Vyncint Ng <[email protected]>
@nihalpasham nihalpasham added documentation Improvements or additions to documentation host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) labels Aug 20, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator
  • Verified the new sections against the macro's impl: the two setters, the #[cuda_module] requirement, the prefix check, and the enum rejection are all as documented.
  • One commit layered on: the three restrictions are a bullet list instead of one 60-word sentence, and the first now matches lib.rs (any all-zeros initializer works, not UNINIT alone); the "product type / discriminated union" rationale is in plain language; "byte pattern" and "bit pattern" are one term; the serde lead-in reads directly.

@nihalpasham
nihalpasham merged commit 2537c02 into NVIDIA:main Aug 20, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants