Skip to content

Derive the DeviceReduce env test kernel allowlists from the dispatch kernel sources - #9726

Open
edenfunf wants to merge 4 commits into
NVIDIA:mainfrom
edenfunf:fix/9643-env-kernel-allowlist
Open

edenfunf wants to merge 4 commits into
NVIDIA:mainfrom
edenfunf:fix/9643-env-kernel-allowlist

Conversation

@edenfunf

@edenfunf edenfunf commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

Refs #9643

#11103 fixed the failure itself by hoisting the decltype()s out of the allowlist lambdas. This PR keeps the test-side refactoring that came out of investigating the same issue, so the pattern cannot come back and the allowlists cannot drift from what the dispatch launches.

Background: the env-based DeviceReduce tests used to compute their expected kernel pointers from decltype(d_in) inside the [&] allowlist lambdas. With nvcc 13.3 and MSVC as host compiler, decltype() of a variable captured by reference inside a lambda is evaluated as a reference type, so the tests referenced Kernel<..., constant_iterator&, ...> while the dispatch launched Kernel<..., constant_iterator, ...>. That is a different instantiation with its own host stub, never registered with the runtime, so the pointer check failed.

Changes:

  • Build both allowlists in one function template, expected_reduce_kernels, shared by the two requirements-parametrized tests. Iterator types are deduced at function scope, the two near-identical lambdas are gone, and with them the decltype()-of-a-capture pattern.
  • Take the kernel pointers from the same kernel source types the dispatch uses instead of re-spelling the kernel template arguments, so the expected instantiations cannot drift from the launched ones. The RFA dispatch had no kernel source, so this adds DeterministicDeviceReduceKernelSource plus a default_kernel_source_t alias to dispatch_reduce_deterministic.cuh, following the pattern of the other dispatch layers. invoke_single_tile and invoke_passes take the kernel source like DispatchReduce does. No functional change.
  • Document the pitfall next to allowed_kernels(), which moved to stream_registry_factory.h in Merge CUB launch wrapper headers #11240.

Net effect on the test file is about -150 lines.

Verified on Windows / MSVC 14.50 / CUDA 13.3 / C++17 / sm_120: reduce_env, reduce_deterministic, reduce_deferred and reduce_env_api all pass.

The decltype() misevaluation itself still looks like a compiler regression worth tracking on the nvcc side. A trivial repro does not trigger it; it seems to need the surrounding template test function and a class-type iterator.

Checklist

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

edenfunf added 2 commits July 7, 2026 16:50
The environment-based DeviceReduce tests computed their expected kernel
pointers with `decltype(d_in)` inside the `[&]` allowlist lambda. With
nvcc 13.3 and MSVC as host compiler, decltype() of a variable captured
by reference inside a lambda is misevaluated as a reference type, so the
tests referenced (and instantiated) `Kernel<..., InputIt&, ...>` instead
of the `Kernel<..., InputIt, ...>` the dispatch launches. The two are
different instantiations with different host stubs, and the referenced
one is never registered with the CUDA runtime, so the white-box
kernel-allowlist check at catch2_test_env_launch_helper.h:97 failed.

* Hoist the iterator type aliases out of the allowlist lambdas.
* Build the allowlists from the same kernel-source types the dispatch
  uses, so the expected instantiations cannot drift from the launched
  ones.
* Add DeterministicDeviceReduceKernelSource to the RFA dispatch,
  mirroring the KernelSource pattern used by the other dispatch layers,
  and pass the kernels into invoke_single_tile/invoke_passes as
  parameters.

Verified on Windows with MSVC 14.50: CUDA 13.3.1 (previously failing)
and CUDA 12.9 (regression check) both pass all 49 test cases.

Fixes NVIDIA#9643
* Factor the near-identical allowlist lambdas of the two
  requirements-parametrized tests into one expected_reduce_kernels
  function template. As a function template, the iterator types are
  deduced at test scope, which also removes the lambda that triggered
  the decltype() misevaluation entirely.
* Expose detail::rfa::default_kernel_source_t and use it both as the
  dispatch default and in the test, so the expected RFA kernel
  instantiations are derived from a single place.
* Include <thrust/type_traits/unwrap_contiguous_iterator.h> directly
  instead of relying on transitive inclusion.
* Document the decltype()-inside-lambda pitfall next to
  allowed_kernels() in the launch helper, where future allowlist tests
  will look.
* Drop the redundant reduction_op_t alias and the stale commented-out
  UNSCOPED_CAPTURE block.

Re-verified on Windows with MSVC 14.50 on both CUDA 13.3.1 and 12.9:
reduce_env (lid_0 + lid_2), reduce_deterministic, reduce_nondeterministic,
and reduce_env_api all pass.
@edenfunf
edenfunf requested a review from a team as a code owner July 7, 2026 09:40
@edenfunf
edenfunf requested a review from bernhardmgruber July 7, 2026 09:40
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 7, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 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: Repository: NVIDIA/cccl/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 449d4ad1-b3d2-4f53-8f05-e5232a1a2f66

📥 Commits

Reviewing files that changed from the base of the PR and between f09d611 and 26d18b3.

📒 Files selected for processing (4)
  • cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
  • cub/test/catch2_test_device_reduce_deferred.cu
  • cub/test/catch2_test_device_reduce_env.cu
  • cub/test/stream_registry_factory.h

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


📝 Summary

Summary by CodeRabbit

  • New Features

    • Deterministic device reduction now supports configurable kernel sources, enabling advanced integrations to customize reduction kernel selection while preserving existing defaults.
    • Existing single-pass and multi-pass reduction workflows continue to use the standard behavior unless custom configuration is provided.
  • Documentation

    • Added guidance for configuring allowed reduction kernels and avoiding compiler-specific type deduction issues in test and integration setups.
  • Tests

    • Improved coverage and validation for deterministic, nondeterministic, deferred, and fallback reduction paths.

Walkthrough

Changes

Deterministic reduce kernel source abstraction

Layer / File(s) Summary
Kernel source contracts and dispatch wiring
cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
Adds kernel source types and default aliases. dispatch accepts and forwards an optional kernel source.
Kernel getter launch implementation
cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
Single-tile, reduction, immediate second-pass, and deferred second-pass launches use kernel source getters.
Environment test allowlist alignment
cub/test/catch2_test_device_reduce_env.cu, cub/test/catch2_test_device_reduce_deferred.cu, cub/test/stream_registry_factory.h
Environment tests derive allocation sizes and allowed kernels from dispatch kernel sources. The deferred test passes the new configuration argument. Allowlist documentation describes exact kernel instantiations and compiler-specific type handling.

Assessment against linked issues

Objective Addressed Explanation
Make environment-based DeviceReduce and DeviceSum kernel allowlists match the kernels launched by deterministic and run-to-run dispatch paths [#9643]

Suggested reviewers: naderalawar

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium


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 (1)
cub/test/catch2_test_device_reduce_env.cu (1)

505-520: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: The sum variant (Lines 550-565) is byte-identical to this block, and both mirror the run_to_run branch of expected_reduce_kernels. Extract a small helper so future kernel-source changes can't drift between the two not_guaranteed tests. Optional.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 82c18609-29b3-482f-a43b-f810cba21503

📥 Commits

Reviewing files that changed from the base of the PR and between 886c291 and eb895af.

📒 Files selected for processing (3)
  • cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
  • cub/test/catch2_test_device_reduce_env.cu
  • cub/test/catch2_test_env_launch_helper.h

Adapt the kernel-source refactor to the deferred problem size support
added in NVIDIA#9740:

- DeterministicDeviceReduceKernelSource gains a KernelNumItemsT parameter
  and a DeferredSingleTileSecondKernel getter, mirroring
  DeviceReduceKernelSource.
- invoke_single_tile/invoke_passes now take the whole kernel source
  instead of individual kernel pointers, matching DispatchReduce, so the
  deferred/immediate second-pass selection stays inside invoke_passes.
- The test allowlists derive the kernel num-items type the same way the
  dispatch does, instead of respelling it.
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh (1)

443-457: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

important: Pass KernelSource{} before fixed_grid_factory_t{} at cub/test/catch2_test_device_reduce_deferred.cu:148. The factory currently binds to KernelSource, which causes compilation to fail.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: abb39f1c-b318-4ef3-816a-33078ce56858

📥 Commits

Reviewing files that changed from the base of the PR and between 4a94f9f and f09d611.

📒 Files selected for processing (4)
  • cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
  • cub/test/catch2_test_device_reduce_deferred.cu
  • cub/test/catch2_test_device_reduce_env.cu
  • cub/test/catch2_test_env_launch_helper.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • cub/test/catch2_test_device_reduce_env.cu
  • cub/test/catch2_test_env_launch_helper.h

@edenfunf

Copy link
Copy Markdown
Contributor Author

@bernhardmgruber If you have some time, could you take a look at this PR? I’d really appreciate it. Thank you!

@bernhardmgruber

Copy link
Copy Markdown
Contributor

@edenfunf I believe the issue has been resolved already by @gevtushenko in #11103. I linked the issue and PR now.

This PR also contains some refactoring of the test. If you want, you can rebase and we can try to upstream it.

main fixed NVIDIA#9643 in NVIDIA#11103 by hoisting the decltypes out of the
allowlist lambdas. This branch removes those lambdas entirely, so keep
its expected_reduce_kernels version. The launch helper was folded into
stream_registry_factory.h in NVIDIA#11240; move the allowlist note there.
@edenfunf

Copy link
Copy Markdown
Contributor Author

@bernhardmgruber Thanks for linking #11103! Merged main and kept only the test refactoring:

Net -150 lines in catch2_test_device_reduce_env.cu. reduce_env, reduce_deterministic, reduce_deferred and reduce_env_api pass on CUDA 13.3 + MSVC 14.50.

@edenfunf edenfunf changed the title Fix env-based DeviceReduce kernel-allowlist tests on MSVC + CUDA 13.3 Derive the DeviceReduce env test kernel allowlists from the dispatch kernel sources Sep 20, 2026
@bernhardmgruber

Copy link
Copy Markdown
Contributor

Thank you for trying to prevent issues like #9643 in the future! The kernel sources in your dispatch layer are artefacts of the type erasure required for CCCL.C. We are currently in the progress of getting rid of this, by using a full C++ JIT compiler for CCCL.C V2. Once we are there, we no longer need any kernel sources in the source code and would probably like to remove them.

Can you think of a way to make the current test more robust without the need to reach for implementation details in the dispatch layer, like the kernel source?

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

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants