Skip to content

modernize-use-auto#8459

Closed
Jacobfaib wants to merge 2 commits intoNVIDIA:mainfrom
Jacobfaib:jacobf/2026-04-15/modernize-use-auto
Closed

modernize-use-auto#8459
Jacobfaib wants to merge 2 commits intoNVIDIA:mainfrom
Jacobfaib:jacobf/2026-04-15/modernize-use-auto

Conversation

@Jacobfaib
Copy link
Copy Markdown
Contributor

Description

closes

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@Jacobfaib Jacobfaib self-assigned this Apr 15, 2026
@Jacobfaib Jacobfaib requested review from a team as code owners April 15, 2026 16:06
@Jacobfaib Jacobfaib requested a review from alliepiper April 15, 2026 16:06
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Apr 15, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Apr 15, 2026
Copy link
Copy Markdown
Contributor

@fbusato fbusato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally in favor of that, but my feeling is that @gevtushenko and @miscco could have a different opinion

@Jacobfaib
Copy link
Copy Markdown
Contributor Author

I'm generally in favor of that, but my feeling is that @gevtushenko and @miscco could have a different opinion

To perhaps allay some fears here, clang-tidy will only suggest using auto when the type is already named on the same line:

  • Casts: Foo f = static_cast<Foo>(x) -> auto f = static_cast<Foo>(x)
  • Construction: Foo f = Foo{...}; -> auto f = Foo{...};
  • New expressions: Foo *f = new Foo{...}; -> auto *f = new Foo{...};

Or specifically for standard library iterators:

std::vector<int>::iterator it = v.begin();
// becomes
auto it = v.begin();

Copy link
Copy Markdown
Contributor

@bernhardmgruber bernhardmgruber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is like 95% fine and I prefer the refactoring. I looked through a third or so.

DecomposerT decomposer = {})
{
bit_ordered_type(&unsigned_keys)[ItemsPerThread] = reinterpret_cast<bit_ordered_type(&)[ItemsPerThread]>(keys);
auto(&unsigned_keys)[ItemsPerThread] = reinterpret_cast<bit_ordered_type(&)[ItemsPerThread]>(keys);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: haven't seen a reinterpretation as a reference to an array in a long time

Comment on lines +560 to 561
auto max_num_blocks = ::cuda::ceil_div(
static_cast<int>(::cuda::std::min(num_items, static_cast<OffsetT>(PORTION_SIZE))), ONESWEEP_TILE_ITEMS);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit like clang-tidy knows that PortionOffsetT is int. Can we reflect this in the cast?

Suggested change
auto max_num_blocks = ::cuda::ceil_div(
static_cast<int>(::cuda::std::min(num_items, static_cast<OffsetT>(PORTION_SIZE))), ONESWEEP_TILE_ITEMS);
auto max_num_blocks = ::cuda::ceil_div(
static_cast<PortionOffsetT>(::cuda::std::min(num_items, static_cast<OffsetT>(PORTION_SIZE))), ONESWEEP_TILE_ITEMS);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I am confused, the int cast already existed before, you want to change that to PortionOffsetT as well?

Comment thread cub/examples/block/example_block_radix_sort.cu Outdated
Comment thread cub/examples/device/example_device_partition_flagged.cu Outdated
@Jacobfaib Jacobfaib force-pushed the jacobf/2026-04-15/modernize-use-auto branch from 3db78af to c93fefb Compare April 15, 2026 19:47
@github-actions
Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 3h 17m: Pass: 99%/379 | Total: 9d 08h | Max: 2h 07m | Hits: 89%/528882

See results here.

Copy link
Copy Markdown
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am really not sure about this. Auto is often usefull if we have a static_cast on the other side of an assignment

But in many cases this creates visual noise, when we have multiple variables and one of them suddenly becomes auto

Often its also not easy to keep the type in min for more complex code, so I am not sure whether its a win


const SampleT lower_level_r = 0;
const SampleT upper_level_r = get_upper_level<SampleT>(num_bins, elements);
const auto upper_level_r = get_upper_level<SampleT>(num_bins, elements);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am against this one, it breaks alignnment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I made them all auto? And

const SampleT lower_level_r = 0;
// to
const auto lower_level_r = SamepleT{0};

I can silence them with // NOLINT but I'd rather avoid that if there are other code changes we can make to satisfy the linter.

Copy link
Copy Markdown
Contributor

@fbusato fbusato Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const SampleT lower_level = 0;
const SampleT upper_level = get_upper_level<SampleT>(num_bins, elements);
const auto upper_level = get_upper_level<SampleT>(num_bins, elements);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those also break alignment


cuda::std::bool_constant<sizeof(SampleT) == 1> is_byte_sample;
OffsetT num_row_pixels = static_cast<OffsetT>(elements);
auto num_row_pixels = static_cast<OffsetT>(elements);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto breaks alignment

@Jacobfaib
Copy link
Copy Markdown
Contributor Author

Since there seems to be no concerted votes for this feature, I will go ahead and close this PR and leave the check disabled.

@Jacobfaib Jacobfaib closed this Apr 21, 2026
@Jacobfaib Jacobfaib deleted the jacobf/2026-04-15/modernize-use-auto branch April 21, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants