Skip to content

Final env-passthrough 2/4 - #8979

Merged
bernhardmgruber merged 10 commits into
NVIDIA:mainfrom
gonidelis:env_passthrough_2
May 20, 2026
Merged

bernhardmgruber merged 10 commits into
NVIDIA:mainfrom
gonidelis:env_passthrough_2

Conversation

@gonidelis

Copy link
Copy Markdown
Member

Handles #8175 for

  • DeviceAdjacentDifference
  • DeviceCopy
  • DevicePartition
  • DeviceRunLengthEncode
  • DeviceFind

the most serious issues have to do with defaults in adjacentdifference and ambiguities they were created.

I chose to start introducing non-env api file tests to check that the non-env APIs work in their minimal form. That is when default args are not explicitly passed. These files will facilitate as ground for extracting the example snippets from non env overloads from doxygen to literalincludes later on.

gonidelis added 7 commits May 13, 2026 20:16
* add in docs that memory_resource can also be passed in env
* add enable_ifs to beat existing ambiguities with non-env APIs
* match 1-1 the non-env APIs to the env APIs identities (defaults, arguments order)
* its purpose is to guard against ambiguities introduced with env algorithms
* it also extends as a ground for placing the literalinclude examples as we extract them
  from the hardcoded snippets in the docs
@gonidelis
gonidelis requested a review from a team as a code owner May 14, 2026 03:21
@gonidelis
gonidelis requested a review from elstehle May 14, 2026 03:21
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 14, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 14, 2026
@coderabbitai

coderabbitai Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Refactor

    • Simplified and tightened template constraints across partition, run-length-encode, and adjacent-difference APIs to improve overload resolution and disambiguation.
  • Documentation

    • Clarified memory-resource customization for adjacent-difference.
    • Removed a determinism claim from copy docs.
    • Improved find/partition/run-length-encode docs and parameter descriptions.
  • Tests

    • Added overload-resolution tests for adjacent-difference, copy, find, partition, and run-length-encode.
    • Updated env-based tests to use direct stream references with explicit sync.

Walkthrough

important: Five device algorithm headers replace iterator-based SFINAE on environment overloads with integral NumItemsT checks or remove the SFINAE entirely, extend environment docs to mention memory-resource customization, clarify bounds/search documentation, and add/adjust tests to ensure legacy size-query overloads resolve unambiguously; env tests now pass cuda::stream_ref directly and call stream.sync().

Changes

DeviceAdjacentDifference SFINAE refactor & docs

Layer / File(s) Summary
SFINAE, docs, and includes
cub/cub/device/device_adjacent_difference.cuh
Added type-trait includes; updated Doxygen @tparam to mark iterator params as [inferred]; env overloads (SubtractLeftCopy, SubtractRightCopy) now enable when NumItemsT is integral; in-place env overloads (SubtractLeft, SubtractRight) require is_integral_v<NumItemsT> && !is_integral_v<EnvT>; env docs now mention cuda::mr::get_memory_resource.

DeviceCopy documentation adjustments

Layer / File(s) Summary
Docs: Batched/mdspan environment overloads
cub/cub/device/device_copy.cuh
Removed gpu_to_gpu determinism claim from Batched and mdspan Copy env-overload docs; reordered mdspan description to follow environment customization bullets.

DeviceFind documentation clarification

Layer / File(s) Summary
Bounds/FindIf docs rewording
cub/cub/device/device_find.cuh
LowerBound/UpperBound docs (non-env and env overloads) now explicitly state returned iterator is the first element meeting the condition; reflowed FindIf overview bullets.

DevicePartition SFINAE removal & docs

Layer / File(s) Summary
Remove env SFINAE defaults and doc notes
cub/cub/device/device_partition.cuh
Removed trailing enable_if_t template defaults from env overloads (Flagged, unary If, three-way If); added/updated @versionadded notes and three-way If docs.

DeviceRunLengthEncode SFINAE removal & param docs

Layer / File(s) Summary
Env overload signatures and docs
cub/cub/device/device_run_length_encode.cuh
Dropped SFINAE default template parameter from env overloads (Encode, NonTrivialRuns) and removed related type-trait includes; added/corrected NumItemsT and num_items docs to refer to total input item count (length of d_in).

Legacy API overload-resolution tests

Layer / File(s) Summary
AdjacentDifference legacy overload tests
cub/test/catch2_test_device_adjacent_difference_api.cu
Added four tests asserting legacy size-query calls for SubtractLeft/Right and SubtractLeftCopy/RightCopy resolve unambiguously (nullptr temp-storage + bytes + n).
DeviceCopy Batched legacy overload test
cub/test/catch2_test_device_copy_api.cu
Added test ensuring Batched legacy temp-storage size-query (iterator-of-iterators placeholders) resolves to the legacy overload.
DeviceFind legacy overload tests
cub/test/catch2_test_device_find_api.cu
Added three tests (FindIf, LowerBound, UpperBound) validating legacy size-query overload resolution without explicit stream.
DevicePartition legacy overload tests
cub/test/catch2_test_device_partition_api.cu
Added tests (Flagged, If unary, If three-way) using a device predicate ensuring legacy size-query overloads resolve unambiguously.
RunLengthEncode legacy overload tests
cub/test/catch2_test_device_run_length_encode_api.cu
Added two tests for Encode and NonTrivialRuns legacy size-query overload resolution.

Environment test call-site refactor (stream_ref)

Layer / File(s) Summary
DeviceCopy env tests
cub/test/catch2_test_device_copy_env_api.cu
Refactored Batched and mdspan Copy env tests to pass cuda::stream_ref directly and added stream.sync().
DevicePartition env tests
cub/test/catch2_test_device_partition_env_api.cu
Refactored If and Flagged env tests to pass cuda::stream_ref directly and added stream.sync() before assertions.
RunLengthEncode env tests
cub/test/catch2_test_device_run_length_encode_env_api.cu
Refactored Encode and NonTrivialRuns env tests to pass cuda::stream_ref directly and added stream.sync() before validation.

Suggested reviewers

  • gevtushenko
  • srinivasyadav18

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

@gonidelis
gonidelis requested a review from bernhardmgruber May 14, 2026 05:00
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment on lines +15 to +23
C2H_TEST("DeviceAdjacentDifference::SubtractLeftCopy legacy size-query is unambiguous", "[adjacent_difference][device]")
{
int* d_in = nullptr;
int* d_out = nullptr;
size_t bytes = 0;
int n = 0;

REQUIRE(cudaSuccess == cub::DeviceAdjacentDifference::SubtractLeftCopy(nullptr, bytes, d_in, d_out, n));
}

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: Those tests don't look like API examples. So they should go into the files cub/test/catch2_test_device_adjacent_difference_subtract_*.cu

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. doesn't have to be an example to go under the _api.cu test. It's literally what the name suggest, an API test, not an example (which the file name doesn't even suggest).

  2. it's a good starting point to have for moving old docs examples into literalincludes

please let's keep it as is

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.

  1. doesn't have to be an example to go under the _api.cu test. It's literally what the name suggest, an API test, not an example (which the file name doesn't even suggest).

This is contrary to my understanding. _api.cu contain only API examples which are referenced from the documentation. They do not contain any functional tests.

Functional tests are always in files like catch2_test_device_algorithmname.cu (with some variations). You also added tests named catch2_test_device_algorithmname_env.cu, which test whether the handling of the execution environment works correctly, with little or no focus on algorithmic correctness.

Please elaborate why we need to break the convention now, or where it has been broken before.

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.

Let's continue here: #9078

Comment on lines +17 to +27
C2H_TEST("DeviceCopy::Batched legacy size-query is unambiguous", "[copy][device]")
{
// DeviceCopy::Batched takes iterator-of-iterators for input/output ranges.
int** in = nullptr;
int** out = nullptr;
size_t* sizes = nullptr;
size_t bytes = 0;
::cuda::std::int64_t num_ranges = 0;

REQUIRE(cudaSuccess == cub::DeviceCopy::Batched(nullptr, bytes, in, out, sizes, num_ranges));
}

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.

Same here, this is not an API example test.

Applies a few more times below.

@gonidelis

gonidelis commented May 20, 2026 •

Copy link
Copy Markdown
Member Author

critical ambiguity resolved in last commit

@gonidelis
gonidelis requested a review from bernhardmgruber May 20, 2026 18:34

@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 (1)
cub/cub/device/device_partition.cuh (1)

991-992: important: This overload-resolution change touches a Device* API path; please attach pre/post SASS diff and CUB benchmark results for DevicePartition before merge to confirm no codegen or performance regressions.

As per coding guidelines **/cub/**/device*.{cu,cuh,h}: “Verify no SASS code generation changes occur for Device* algorithms in CUB by comparing generated SASS output before and after changes” and “Run benchmark tests using the CUB Benchmarks framework when modifying Device* algorithms to verify no performance regressions occur”.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d3a48de4-f621-495a-8986-a9832267e915

📥 Commits

Reviewing files that changed from the base of the PR and between 257fede and 66fee1b.

📒 Files selected for processing (2)
  • cub/cub/device/device_partition.cuh
  • cub/test/catch2_test_device_partition_api.cu

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 57m: Pass: 100%/283 | Total: 7d 11h | Max: 1h 55m | Hits: 45%/450454

See results here.

@bernhardmgruber
bernhardmgruber merged commit a5f77ab into NVIDIA:main May 20, 2026
302 of 304 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL May 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Successfully created backport PR for branch/3.4.x:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants