Skip to content

Add C2H utilities: c2h::current_device() / c2h::make_current_device_stream() - #11491

Merged
bernhardmgruber merged 1 commit into
NVIDIA:mainfrom
bernhardmgruber:cub-current-device-refactor
Sep 21, 2026
Merged

bernhardmgruber merged 1 commit into
NVIDIA:mainfrom
bernhardmgruber:cub-current-device-refactor

Conversation

@bernhardmgruber

Copy link
Copy Markdown
Contributor

Adds c2h::current_device() / c2h::make_current_device_stream() (in a new lightweight header c2h/include/c2h/device_and_stream.h) and uses them across CUB's Catch2 tests wherever a test needs a stream or device on the CUDA device currently selected via -d/--device. Several tests constructed streams via cuda::stream{cuda::devices[0]}, which silently targeted device 0 regardless of the selected device; others repeated cudaGetDevice/REQUIRE boilerplate per test that the new helper replaces with a single call.

🤖 Generated with Claude Code

@bernhardmgruber
bernhardmgruber requested review from a team as code owners September 18, 2026 14:53
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Sep 18, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Sep 18, 2026
…n CUB tests

c2h selects the device via -d/--device, so device-affine test resources
(streams, buffers) must be created against that device rather than assuming
device 0 or hand-rolling cudaGetDevice() boilerplate per test. Several tests
constructed streams via cuda::stream{cuda::devices[0]}, which silently
targeted the wrong device when run with a non-default -d/--device selection.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@bernhardmgruber
bernhardmgruber force-pushed the cub-current-device-refactor branch from d050d04 to fa034df Compare September 18, 2026 15:18
@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

@oleksandr-pavlyk for vis

@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview 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: e599fa1e-4558-4d87-b35f-a376b402c694

📥 Commits

Reviewing files that changed from the base of the PR and between 33fec85 and fa034df.

📒 Files selected for processing (26)
  • c2h/include/c2h/device_and_stream.h
  • cub/test/catch2_test_device_adjacent_difference_substract_left.cu
  • cub/test/catch2_test_device_adjacent_difference_substract_right.cu
  • cub/test/catch2_test_device_copy_batched.cu
  • cub/test/catch2_test_device_copy_mdspan.cu
  • cub/test/catch2_test_device_find_env.cu
  • cub/test/catch2_test_device_for_env.cu
  • cub/test/catch2_test_device_histogram_env.cu
  • cub/test/catch2_test_device_memcpy_env.cu
  • cub/test/catch2_test_device_merge_sort_env.cu
  • cub/test/catch2_test_device_partition_flagged.cu
  • cub/test/catch2_test_device_partition_if.cu
  • cub/test/catch2_test_device_radix_sort_env.cu
  • cub/test/catch2_test_device_reduce.cu
  • cub/test/catch2_test_device_reduce_arg_minmax_env.cu
  • cub/test/catch2_test_device_reduce_deferred.cu
  • cub/test/catch2_test_device_run_length_encode_env.cu
  • cub/test/catch2_test_device_scan_by_key_env.cu
  • cub/test/catch2_test_device_scan_iterators.cu
  • cub/test/catch2_test_device_segmented_sort_pairs_env.cu
  • cub/test/catch2_test_device_select_flagged.cu
  • cub/test/catch2_test_device_select_flagged_if.cu
  • cub/test/catch2_test_device_select_if.cu
  • cub/test/catch2_test_device_select_unique.cu
  • cub/test/catch2_test_device_select_unique_by_key_env.cu
  • cub/test/catch2_test_device_transform_env.cu

Included review availability: Your plan provides up to 12 included reviews per hour; 8 remain after this review.


📝 Summary

Summary by CodeRabbit

  • New Features

    • Added CUDA test utilities for retrieving the active device and creating streams associated with it.
  • Tests

    • Updated CUB CUDA tests to create streams for the active device through shared test utilities.
    • Standardized device selection across stream, execution-policy, sorting, scanning, reduction, selection, and transformation tests.
    • Preserved existing test behavior and expected results while improving consistency across supported test scenarios.

Walkthrough

Changes

The PR adds shared C2H helpers for retrieving the active CUDA device and creating a stream for it. CUB tests replace direct device-indexed stream construction and current-device queries with these helpers.

Current-device stream handling

Layer / File(s) Summary
Current-device helper API
c2h/include/c2h/device_and_stream.h
Adds current_device() and make_current_device_stream().
CUB stream test migration
cub/test/catch2_test_device_*.cu
Updates stream-based tests to use current-device streams and removes direct cuda/devices usage.
Current-device access in scan tests
cub/test/catch2_test_device_scan_by_key_env.cu, cub/test/catch2_test_device_scan_iterators.cu
Uses c2h::current_device() for device properties and device-buffer construction.

Suggested reviewers: jacobfaib, davebayer

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to fa034

The test migration preserves active-device stream affinity, with no concrete merge-blocking issue identified.


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

@bernhardmgruber bernhardmgruber changed the title Use current CUDA device for device-affine resources in CUB tests Add C2H utilities: c2h::current_device() / c2h::make_current_device_stream() Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 04m: Pass: 100%/182 | Total: 10d 01h | Max: 3h 01m | Hits: 27%/846760

See results here.

@bernhardmgruber
bernhardmgruber merged commit ad3ad3b into NVIDIA:main Sep 21, 2026
212 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Sep 21, 2026
@bernhardmgruber
bernhardmgruber deleted the cub-current-device-refactor branch September 21, 2026 07:27
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