Repository navigation
docs(cuda-macros): the README omits #[constant], and its only derive - #1057
Merged
nihalpasham merged 2 commits intoAug 20, 2026
Merged
Conversation
`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]>
Collaborator
|
nihalpasham
approved these changes
Aug 20, 2026
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.
cuda-macrosexports 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/: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 beConstantMemory::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 thanCopy: the trait isunsafeand promises every bit pattern is valid, whichDeviceBufferrelies 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:
#[proc_macro_attribute], four#[proc_macro], one#[proc_macro_derive]— are now all named in the README, and the four files undersrc/are all in the tree.#[constant]snippet is the shapeexamples/constant_memory_coeffs/src/main.rsalready uses, line for line.DeviceCopy'sCopybound, itsbool/char/NonZeroU32rationale and its enum rejection come fromcuda-core/src/device_buffer.rsandcuda-macros/src/device_copy.rs; the derive example matches the#[derive(Copy, Clone, DeviceCopy)]form incuda-core's trybuild fixtures.Documentation only — no source file changes, so
#[constant]'s and the derive's behaviour is untouched.