Skip to content

[CUB] Refactor DeviceReduce::Arg{Min, Max} to always take an environment - #9403

Merged
miscco merged 1 commit into
NVIDIA:mainfrom
miscco:device_reduce_argmin_env
Jul 2, 2026
Merged

miscco merged 1 commit into
NVIDIA:mainfrom
miscco:device_reduce_argmin_env

Conversation

@miscco

@miscco miscco commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

We want to be able to pass tunings even to the APIs that currently only take a stream.

Refactor so that we can pass an arbitrary environment to those APIs that take user provided memory

Also port the PSTL algorithms to use the new API

@miscco
miscco requested review from a team as code owners June 11, 2026 12:28
@miscco
miscco requested review from griwes and srinivasyadav18 June 11, 2026 12:28
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 11, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e2227ebf-eeea-46bf-bdd4-adcc782cabba

📥 Commits

Reviewing files that changed from the base of the PR and between dbfdda1 and ef5f96f.

📒 Files selected for processing (2)
  • cub/cub/device/device_reduce.cuh
  • cub/test/catch2_test_device_reduce.cu
💤 Files with no reviewable changes (1)
  • cub/test/catch2_test_device_reduce.cu
🚧 Files skipped from review as they are similar to previous changes (1)
  • cub/cub/device/device_reduce.cuh

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Refactor

    • Updated cub::DeviceReduce::ArgMin/ArgMax to use an execution environment parameter (env) instead of a raw CUDA stream, consistently across overloads.
  • Tests

    • Enhanced DeviceReduce tests to verify user-provided temporary storage and run reductions across multiple execution environment types (including stream-bound GPU environments).
  • Integration

    • Updated CUDA PSTL min_element/max_element to pass the execution policy into DeviceReduce::ArgMin/ArgMax during storage sizing and kernel launch.

Walkthrough

DeviceReduce ArgMin and ArgMax now take execution environments by const-reference, use environment-aware dispatch internally, update PSTL CUDA backends to pass policies, and expand tests to cover multiple environment types with user-provided temporary storage.

Changes

DeviceReduce ArgMin/ArgMax Environment Migration

Layer / File(s) Summary
Argument extremum dispatch infrastructure
cub/cub/device/device_reduce.cuh
Private __arg_min accepts EnvT and const EnvT& env, and dispatches through detail::dispatch_with_env_and_tuning with a policy selector derived from the key/value-related types.
ArgMin public API migration
cub/cub/device/device_reduce.cuh
ArgMin compare-op and cuda::std::less overloads add EnvT, accept const EnvT& env = {}, forward env into internal helpers, and update the later public overloads to pass env by const-reference.
ArgMax public API migration
cub/cub/device/device_reduce.cuh
ArgMax compare-op and cuda::std::greater overloads add EnvT, accept const EnvT& env = {}, forward env into the internal implementation with detail::swap_args{compare_op}, and update the later public overloads to pass env by const-reference.
ArgMin/ArgMax tests with user-provided memory and environments
cub/test/catch2_test_device_reduce.cu
Tests add environment headers, query temporary storage size with nullptr, allocate device storage, and rerun ArgMax and ArgMin across stream, stream_ref, execution env, and gpu policy variants while checking value and index.
PSTL CUDA backend integration
libcudacxx/include/cuda/std/__pstl/cuda/max_element.h, libcudacxx/include/cuda/std/__pstl/cuda/min_element.h
max_element and min_element CUDA backends pass __policy to DeviceReduce::ArgMax and DeviceReduce::ArgMin for temporary-storage sizing and kernel launch.

Suggested reviewers: ericniebler, NaderAlAwar


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (2)
cub/test/catch2_test_device_find_env.cu (1)

186-252: ⚡ Quick win

suggestion: factor the repeated env-variant/user-memory matrix into a shared test helper. The same structure is duplicated across FindIf, LowerBound, and UpperBound, which increases drift risk when adding/removing env forms or changing sync/error assertions.

Also applies to: 288-379, 415-506

cub/test/catch2_test_device_reduce.cu (1)

233-315: ⚡ Quick win

suggestion: The ArgMax and ArgMin “user provided memory and environment” sections are nearly identical; extract a shared helper to run size-query, allocation, execution, and verification so future environment/tuning updates don’t drift between the two paths.

Also applies to: 338-420


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0ca9b054-9d82-47f1-a65e-7e5384aba088

📥 Commits

Reviewing files that changed from the base of the PR and between 19ffe4f and 51677c4.

📒 Files selected for processing (8)
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh
  • cub/cub/device/device_reduce.cuh
  • cub/test/catch2_test_device_find_env.cu
  • cub/test/catch2_test_device_reduce.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/find_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/max_element.h
  • libcudacxx/include/cuda/std/__pstl/cuda/min_element.h

@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the device_reduce_argmin_env branch 2 times, most recently from 162c1f6 to dbfdda1 Compare June 12, 2026 11:14
@github-actions

This comment has been minimized.

Comment thread cub/cub/device/device_reduce.cuh Resolved
…nment

We want to be able to pass tunings even to the APIs that currently only take a stream.

Refactor so that we can pass an arbitrary environment to those APIs that take user provided memory
@miscco
miscco force-pushed the device_reduce_argmin_env branch from dbfdda1 to ef5f96f Compare July 1, 2026 09:16
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 21m: Pass: 100%/345 | Total: 13d 12h | Max: 2h 21m | Hits: 37%/1338008

See results here.

typename IndexOutIteratorT,
typename CompareOpT,
typename EnvT = ::cuda::std::execution::env<>>
CUB_RUNTIME_FUNCTION static cudaError_t __arg_min(

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.

Important: With the new changes, __arg_min is almost identical to __arg_min_env. Please unify the two functions, I am sure this is possible.

@miscco
miscco merged commit c5318b2 into NVIDIA:main Jul 2, 2026
364 of 365 checks passed
@miscco
miscco deleted the device_reduce_argmin_env branch July 2, 2026 11:30
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jul 2, 2026
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.

2 participants