Repository navigation
fix(cuda-macros): obey #[inline] on generic device functions - #1472
Draft
fxeqxmulfx wants to merge 1 commit into
Draft
fxeqxmulfx wants to merge 1 commit into
fxeqxmulfx wants to merge 1 commit into
Conversation
fxeqxmulfx
force-pushed
the
fix/1471-generic-device-inline-policy
branch
from
October 11, 2026 17:51
4c12128 to
74ce9f6
Compare
`#[device]` added `#[inline(never)]` before the other attributes of a generic device function. rustc uses only the first `inline` attribute. Because of this, rustc did not use an `#[inline(always)]` or `#[inline]` attribute on the function. Add `#[inline(never)]` only if there is no `inline` attribute on the function. `#[kernel]` uses the same check for the attributes of generic kernels. rustc expands `cfg_attr` before it calls the macro. Because of this, the check also finds an `inline` attribute in `cfg_attr`. Move the expansion to `device_function_tokens`, as for generic kernels, so that unit tests can examine it. Fixes NVIDIA#1471 Signed-off-by: Mikhail Borisov <mikhail.boriso2014@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fxeqxmulfx
force-pushed
the
fix/1471-generic-device-inline-policy
branch
from
October 11, 2026 20:50
74ce9f6 to
a146283
Compare
fxeqxmulfx
marked this pull request as draft
October 12, 2026 08:53
This branch has not been deployed
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.
Summary
#[device]added#[inline(never)]before the other attributes of a generic function. rustc uses only the firstinlineattribute. Because of this, rustc did not use an#[inline(always)]or#[inline]attribute on the function. rustc also gave anunused attributewarning. Now#[device]adds#[inline(never)]only if there is noinlineattribute on the function.Fixes #1471
Before → after
maininlineattributes of{DEVICE_PREFIX}scale#[inline(never)](from#[device]),#[inline(always)]#[inline(always)]warning: unused attributefor#[inline(always)]: "it will become a hard error in a future release"optscale_allcallsscalefEB2_scalefEB2_:scale_allcontains the code ofscale.entry scale_alland.visible .func scalefEB2_.entry scale_allonlyChanges
cuda-macros/src/device.rs:#[device]adds#[inline(never)]to a generic function only if the function has noinlineattribute. The check usesattr_path_ends_with.#[kernel]uses the same function for the attributes of generic kernels. rustc expandscfg_attrbefore it calls the macro. Because of this, the check also finds aninlineattribute incfg_attr.device_function_tokens, as for generic kernels ingeneric_kernel_no_instantiation_tokens. Unit tests can examine it.generic_device_function_keeps_the_inline_attribute_of_the_user(#[inline],#[inline(always)],#[inline(never)]), and the trybuild pass testtests/pass/device_inline_policy.rswith#![deny(unused_attributes)]. Both fail when#[device]always adds#[inline(never)], as onmain.generic_device_function_is_inline_never_by_defaultandnon_generic_device_function_gets_no_inline_attribute.other_attributes_do_not_replace_the_default(#[cold],#[doc = "inline"]).standalone_device_fn: the comment about#[inline(never)]now includes "by default".Testing
just -f cuda-oxide/Justfile checkpasses (the local mirror of CI: fmt, clippy, tests, guards, docs)cargo oxide run <example>passes, orcuda-oxide/scripts/smoketest.sh -o '^<example>$'cargo oxide run standalone_device_fn --arch sm_80givesSUCCESS: 18/18 tests passed.On an RTX 3050 (sm_86), the example above gives correct results on
mainand with this change. The table shows the output of the two builds.Checklist
git commit -s)🤖 Generated with Claude Code