Skip to content

[CUB] Refactor DeviceSelect::UniqueByKey to always take an environment - #9387

Closed
miscco wants to merge 3 commits into
NVIDIA:device_select_unique_envfrom
miscco:device_select_unique_by_key
Closed

miscco wants to merge 3 commits into
NVIDIA:device_select_unique_envfrom
miscco:device_select_unique_by_key

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

@miscco
miscco requested review from a team as code owners June 11, 2026 07:23
@miscco
miscco requested a review from bernhardmgruber June 11, 2026 07:23
@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
@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the device_select_unique_by_key branch from f62f547 to 3c05a4a Compare June 11, 2026 11:16
@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note: CodeRabbit is enabled on this repository as a convenience for maintainers
and contributors. Use your best judgment when considering its review comments and
suggestions — a suggested change may be inadequate, unnecessary, or safe to ignore.
Contributors are not expected to address every comment. Human reviews are what
ultimately matter for merging.

Overview

This PR refactors cub::DeviceSelect algorithms to consistently accept an execution environment parameter instead of a CUDA stream, enabling passage of user-provided tunings to APIs that support temporary storage. Changes affect DeviceSelect::Flagged, If, Unique, and UniqueByKey, and update dependent PSTL backends in libcudacxx. Tests exercising environment-based dispatch and user-provided temporary storage were added or extended.

Core Changes

CUB Device Select Refactoring (cub/cub/device/device_select.cuh)

  • Environment parameter standardization: environment-based overloads now accept const EnvT& env = {} instead of EnvT by value.
  • Stream-to-environment dispatch migration: overloads that previously accepted cudaStream_t stream = nullptr were replaced by environment-parameterized overloads that route execution through detail::dispatch_with_env_and_tuning, which derives stream and policy selector from the environment and forwards them to detail::select::dispatch / detail::unique_by_key::dispatch.
  • UniqueByKey equality-operator overloads and the default-equality wrapper now accept and forward const EnvT& env.
  • Lines changed: +353/-249; estimated review effort: High.

Tests (cub/test/)

  • New/updated tests exercise DeviceSelect with user-provided temporary storage across multiple environment forms (raw cudaStream_t, cuda::stream, cuda::stream_ref, cuda::std::execution::env, cuda::execution::gpu, and cuda::execution::gpu bound to a stream):
    • catch2_test_device_select_flagged.cu (+99): Flagged test extended to exercise environments.
    • catch2_test_device_select_flagged_if.cu (+115/-1): FlaggedIf test extended.
    • catch2_test_device_select_if.cu (+97): If test extended.
    • catch2_test_device_select_unique.cu (+124): Unique test extended.
    • catch2_test_device_select_unique_by_key.cu (small include changes) — existing file updated minimally.
    • New translation unit catch2_test_device_select_unique_by_key_env.cu (+220): comprehensive UniqueByKey environment/temp-storage test (moved into a separate TU to avoid TU-level CI interactions).
  • Tests perform temp-storage-size query with temp_storage = nullptr, allocate device temp-storage, run CUB calls with provided temp-storage, validate CUDA error/sync status, and compare outputs to host references (e.g., std::unique or stable-partition logic).

libcudacxx PSTL Backend Changes (libcudacxx/include/cuda/std/__pstl/cuda/)

  • copy_if.h, remove_if.h, shift_left.h: updated to pass execution policy (__policy) instead of explicit CUDA stream and to use raw temporary-storage pointer accessors (__get_raw_ptr<0>()) where needed.
  • unique.h: refactored to use cub::DeviceSelect::Unique directly, return input iterator advanced by the selected count, removed prior SelectImpl variant and CUDA unique_copy support from this header.
  • New unique_copy.h (CUDA backend): adds CUDA-specific __pstl_dispatch specialization for __unique_copy that uses DeviceSelect::Unique, manages temporary storage, handles stream/context and allocation errors, and falls back to non-CUDA path when iterator constraints aren't met.
  • dispatch.h: added __unique_copy enum tag.
  • PSTL wrapper unique_copy.h: updated to dispatch to __unique_copy.

Known CI/Integration Issue and Rationale for TU Split

  • A nondeterministic CI failure was observed: adding environment tests in the same translation unit caused a shared iterator’s value_type to resolve unexpectedly (to unsigned int), breaking an unrelated legacy vsmem test that uses thrust::copy(). Investigation suggests a TU-level interaction (gcc12/CUDA12/libcu++/thrust) affecting type resolution. To avoid this instability, environment tests that trigger the new overloads are moved into a separate translation unit (catch2_test_device_select_unique_by_key_env.cu) in this PR.

Merge Prerequisites

  • This PR should be merged after PR #9318.

important: Walkthrough

DeviceSelect non-temp-storage overloads across Flagged, If, Unique, and UniqueByKey change their env parameter from by-value to const EnvT&. All d_temp_storage overloads replace stream-parameterized execution with environment-parameterized dispatch via dispatch_with_env_and_tuning. New CUB tests validate these changes across multiple environment types. PSTL backends for existing algorithms (copy_if, remove_if, shift_left) switch from passing CUDA streams to passing execution policies. PSTL unique is refactored to use DeviceSelect::Unique directly. A new PSTL unique_copy backend is implemented using the same environment-based DeviceSelect::Unique dispatch pattern.

important: Changes

DeviceSelect and PSTL environment-based dispatch

Layer / File(s) Summary
DeviceSelect const EnvT& parameter signatures
cub/cub/device/device_select.cuh
Non-temp-storage overloads for Flagged, If, Unique, UniqueByKey, and FlaggedIf update the env parameter from EnvT by value to const EnvT& with default env = {}.
DeviceSelect d_temp_storage environment dispatch
cub/cub/device/device_select.cuh
All d_temp_storage overloads replace stream-parameterized execution with const EnvT& env and route kernels through dispatch_with_env_and_tuning before calling detail::select::dispatch or detail::unique_by_key::dispatch.
CUB test coverage for environment-based APIs
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
New test cases validate temp-storage sizing (nullptr query then allocation) and correctness across multiple execution environments: cudaStream_t, cuda::stream, cuda::stream_ref, cuda::std::execution::env, cuda::execution::gpu, and cuda::execution::gpu with stream binding.
PSTL backend updates for existing algorithms
libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h, libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h, libcudacxx/include/cuda/std/__pstl/cuda/shift_left.h, libcudacxx/include/cuda/std/__pstl/cuda/unique.h, libcudacxx/include/cuda/std/__pstl/dispatch.h
copy_if, remove_if, and shift_left backends pass execution policy instead of CUDA stream to CUB device APIs and use raw-pointer storage accessors. PSTL unique is refactored to use DeviceSelect::Unique directly and remove DispatchSelectIf templating. Dispatch enum adds __unique_copy.
PSTL unique_copy backend implementation
libcudacxx/include/cuda/std/__pstl/cuda/unique_copy.h, libcudacxx/include/cuda/std/__pstl/unique_copy.h
New CUDA backend dispatch for PSTL unique_copy: __par_impl queries DeviceSelect::Unique temp-storage, allocates via local helper, launches kernel into output iterator, copies selected count to host, and returns output iterator advanced by count. operator() routes random-access paths through CUDA backend with error mapping and fallback to ::cuda::std::unique_copy.

important: Possibly related PRs

  • NVIDIA/cccl#8880: Both PRs modify cub/cub/device/device_select.cuh to route DeviceSelect through detail::dispatch_with_env_and_tuning for environment-based/tuning dispatch.

important: Suggested labels

backport branch/3.3.x, backport branch/3.4.x

important: Suggested reviewers

  • gonidelis
  • shwina
  • gevtushenko

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

@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)
libcudacxx/include/cuda/std/__pstl/cuda/find_if.h (1)

33-33: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

suggestion: add a direct #include <cub/detail/choose_offset.cuh>. This change now names CUB_NS_QUALIFIER::detail::choose_offset_t explicitly, but the file only gets that declaration transitively through <cub/device/device_find.cuh>, which makes the header brittle if device_find.cuh stops pulling it in. As per coding guidelines, files must include all headers for the symbols they use, no transitive header inclusions are allowed, and the most precise include should be used.

Also applies to: 75-75

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 95310559-3026-4b80-a2fb-9e2139d95ed9

📥 Commits

Reviewing files that changed from the base of the PR and between 19ffe4f and 3c05a4a.

📒 Files selected for processing (6)
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh
  • cub/cub/device/device_select.cuh
  • cub/test/catch2_test_device_find_env.cu
  • cub/test/catch2_test_device_select_unique_by_key.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/find_if.h

@miscco

miscco commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

I have no idea why some unrelated code is suddenly broken 😿

@github-actions

This comment has been minimized.

auto d_temp = c2h::device_vector<uint8_t>(expected_allocation_size, thrust::no_init);
void* temp_storage = thrust::raw_pointer_cast(d_temp.data());

auto test_unique_by_key = [&](const auto& env) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test only calls the no-predicate one, can we add a call passing cuda::std::equal_to<>{} + env to cover the modified sfinae?

@gonidelis

Copy link
Copy Markdown
Member

insane, I've been chasing that CI bug for 2 hours. It's super not minimally reproducable. I guess the only solution would be to move the env tests to a separate file. it's some sort of c2h, gcc12, libcu++/thrust messiness

with the new env test in the same TU, a shared iterator value_type resolves to unsigned int, which breaks the unrelated legacy vsmem test's thrust::copy().

@miscco
miscco force-pushed the device_select_unique_by_key branch from 3c05a4a to d080ad9 Compare June 12, 2026 07:35
@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the device_select_unique_by_key branch from d080ad9 to a57c6f1 Compare June 12, 2026 11:13

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
libcudacxx/include/cuda/std/__pstl/cuda/unique_copy.h (1)

39-40: 💤 Low value

suggestion: <cuda/std/__algorithm/unique.h> appears unused; only unique_copy is called in the fallback path (line 163). Consider removing line 39 to avoid transitive-include bloat.

Source: Coding guidelines

cub/test/catch2_test_device_select_if.cu (1)

204-222: ⚡ Quick win

suggestion: This env-path test is missing an exact result check. It only proves that the prefix satisfies le and the suffix stays default-initialized; it never checks the exact selected count or stable output against a reference. That leaves room for env-dispatch regressions that drop matching elements or reorder them while still passing this test.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 20cbf943-5a0a-47ec-96b0-764b3f2ca5a2

📥 Commits

Reviewing files that changed from the base of the PR and between d080ad9 and a57c6f1.

📒 Files selected for processing (13)
  • cub/cub/device/device_select.cuh
  • 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.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/shift_left.h
  • libcudacxx/include/cuda/std/__pstl/cuda/unique.h
  • libcudacxx/include/cuda/std/__pstl/cuda/unique_copy.h
  • libcudacxx/include/cuda/std/__pstl/dispatch.h
  • libcudacxx/include/cuda/std/__pstl/unique_copy.h
✅ Files skipped from review due to trivial changes (1)
  • libcudacxx/include/cuda/std/__pstl/dispatch.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • cub/test/catch2_test_device_select_unique_by_key.cu

Comment on lines +206 to +209
C2H_TEST("DeviceSelect::FlaggedIf works with user provided memory and environment",
"[device][select_if]",
all_types,
flag_types)

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

important: The new env test is tagged for select_if, not select_flagged_if. Filtered select_flagged_if runs will skip this coverage, which makes the new dispatch path easy to miss in targeted testing.

Comment on lines +198 to +293
C2H_TEST("DeviceSelect::Flagged works with user provided memory and environment", "[device][select_flagged]", all_types)
{
using type = typename c2h::get<0, TestType>;

const int num_items = GENERATE_COPY(take(2, random(1, 1000000)));
c2h::device_vector<type> in(num_items);
c2h::device_vector<type> out(num_items);
c2h::gen(C2H_SEED(2), in);

c2h::device_vector<int> flags(num_items);
c2h::gen(C2H_SEED(1), flags, 0, 1);
const int num_selected = static_cast<int>(thrust::count(c2h::device_policy, flags.begin(), flags.end(), 1));
const c2h::host_vector<type> reference = get_reference(in, flags);

// Needs to be device accessible
c2h::device_vector<int> num_selected_out(1, 0);
int* d_num_selected_out = thrust::raw_pointer_cast(num_selected_out.data());

size_t expected_allocation_size = 0;
auto error = cub::DeviceSelect::Flagged(
static_cast<void*>(nullptr),
expected_allocation_size,
in.data(),
flags.begin(),
out.data(),
d_num_selected_out,
num_items);
REQUIRE(error == cudaSuccess);
REQUIRE(cudaSuccess == cudaPeekAtLastError());
REQUIRE(cudaSuccess == cudaDeviceSynchronize());

auto d_temp = c2h::device_vector<uint8_t>(expected_allocation_size, thrust::no_init);
void* temp_storage = thrust::raw_pointer_cast(d_temp.data());

auto test_flagged = [&](const auto& env) {
size_t num_bytes = 0;
error = cub::DeviceSelect::Flagged(
static_cast<void*>(nullptr), num_bytes, in.data(), flags.begin(), out.data(), d_num_selected_out, num_items, env);
REQUIRE(error == cudaSuccess);
REQUIRE(cudaSuccess == cudaPeekAtLastError());
REQUIRE(cudaSuccess == cudaDeviceSynchronize());
REQUIRE(expected_allocation_size == num_bytes);

error = cub::DeviceSelect::Flagged(
temp_storage, num_bytes, in.data(), flags.begin(), out.data(), d_num_selected_out, num_items, env);
REQUIRE(error == cudaSuccess);
REQUIRE(cudaSuccess == cudaPeekAtLastError());
REQUIRE(cudaSuccess == cudaDeviceSynchronize());

out.resize(num_selected_out[0]);
REQUIRE(num_selected == num_selected_out[0]);
REQUIRE(reference == out);
};

int current_device;
error = cudaGetDevice(&current_device);
REQUIRE(error == cudaSuccess);

SECTION("DeviceSelect::Flagged works with cudaStream_t")
{
cuda::stream stream{cuda::devices[current_device]};
test_flagged(stream.get());
}

SECTION("DeviceSelect::Flagged works with cuda::stream")
{
cuda::stream stream{cuda::devices[current_device]};
test_flagged(stream);
}

SECTION("DeviceSelect::Flagged works with cuda::stream_ref")
{
cuda::stream stream{cuda::devices[current_device]};
cuda::stream_ref stream_ref{stream};
test_flagged(stream_ref);
}

SECTION("DeviceSelect::Flagged works with cuda::std::execution::env")
{
cuda::std::execution::env env{};
test_flagged(env);
}

SECTION("DeviceSelect::Flagged works with cuda::execution::gpu")
{
const auto policy = cuda::execution::gpu;
test_flagged(policy);
}

SECTION("DeviceSelect::Flagged works with cuda::execution::gpu with stream")
{
cuda::stream stream{cuda::devices[current_device]};
const auto policy = cuda::execution::gpu.with(cuda::get_stream, stream);
test_flagged(policy);
}
}

@coderabbitai coderabbitai Bot Jun 12, 2026 •

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.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

important: The new env-path tests should be isolated into separate translation units. The PR discussion already ties same-TU env tests to unrelated gcc12/c2h/libcu++ failures, and these additions keep the same pattern in 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, and cub/test/catch2_test_device_select_unique.cu. Move the env-only coverage into dedicated .cu files so the new API paths stop perturbing the legacy test instantiations. Based on PR discussion about the translation-unit interaction.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

didn't know you were reading our discussions @coderabbitai :)

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.

@gonidelis — yes, PR comments and discussion are part of the context I use to calibrate review feedback. The translation-unit interaction you described is exactly why I flagged the placement concern.

(´• ω •`) 🐇


🧠 Learnings used
Learnt from: sleeepyjack
Repo: NVIDIA/cccl PR: 8857
File: cudax/include/cuda/experimental/__cuco/__hyperloglog/hyperloglog_impl.cuh:426-428
Timestamp: 2026-05-06T23:47:17.597Z
Learning: In the CCCL/CUDA C++ Core Libraries codebase (NVIDIA/cccl), treat `_CCCL_API` as host-and-device callable. `_CCCL_API` expands to `_CCCL_HOST_DEVICE` via `libcudacxx/include/cuda/std/__cccl/visibility.h`, so functions marked with `_CCCL_API` may be invoked from both host and device code. When reviewing device-code contexts, do not flag `_CCCL_API`-annotated functions as if they were host-only.

Learnt from: NaderAlAwar
Repo: NVIDIA/cccl PR: 9171
File: libcudacxx/include/cuda/std/__cccl/diagnostic.h:126-126
Timestamp: 2026-06-03T13:24:36.356Z
Learning: When reviewing code that uses NVIDIA NVCC/NVRTC diagnostic suppression pragmas, treat `nv_diag_suppress` as supporting comma-separated warning numbers in a single directive. For example, `_Pragma("nv_diag_suppress 1444,20199")` (or an equivalent `#pragma nv_diag_suppress 1444,20199`) is valid; do not flag comma-separated warning IDs inside `nv_diag_suppress` pragmas as unsupported.

@gonidelis gonidelis Jun 12, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since you are at it, if you can find why the unrelated failure goes away once in separate TUs that owuld be great :)

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.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find vsmem-related tests in CUB
rg -rn "vsmem" cub/test/ --type=cu -C3 | head -80

# Find what "shared iterator" is used in device_select tests
rg -rn "shared" cub/test/catch2_test_device_select --type=cu -C3 | head -60

# Look for value_type or iterator_traits specializations in c2h or catch2_test_device_select_common
rg -rn "value_type" cub/test/catch2_test_device_select_common.cuh -C3 | head -60

# Look for the env test in unique_by_key (mentioned in PR discussion as TU trigger)
rg -rn "value_type\|unsigned int\|uint32_t\|shared" cub/test/catch2_test_device_select_unique_by_key.cu -C3 | head -60

# Look for template specializations that might cause ODR issues
rg -rn "template.*specializ\|iterator_traits\|thrust::iterator_traits" cub/test/ --type=cu -C3 | head -60

Length of output: 1114


🏁 Script executed:

#!/bin/bash
# Search for vsmem in the broader cub test suite
rg -rn "vsmem" cub/ -C3 | head -100

# Look at the catch2_test_device_select_unique_by_key.cu new test content
cat cub/test/catch2_test_device_select_unique_by_key.cu | head -200

# Check what iterator types are being used with thrust::copy in select tests
rg -rn "thrust::copy\|vsmem\|shared_iter\|SharedIter" cub/ -C5 | head -100

Length of output: 12544


🏁 Script executed:

#!/bin/bash
# Look at the vsmem test for device select if
cat cub/test/catch2_test_device_select_if_vsmem.cu

# Check what shared iterators are used in unique_by_key test - specifically thrust::copy usage
rg -n "thrust::copy\|counting_iterator\|value_type\|shared" cub/test/catch2_test_device_select_unique_by_key.cu -C3 | head -100

# Check the c2h shared iterator infrastructure
rg -rn "shared\|value_type" cub/cub/iterator/ -C3 | head -80
rg -rn "SharedIter\|shared_iter" cub/ -C3 | head -80

# Look for value_type in catch2_test_device_select_if_vsmem.cu
rg -n "value_type\|thrust::copy\|counting_iterator\|uint\|unsigned" cub/test/catch2_test_device_select_if_vsmem.cu -C3 | head -80

Length of output: 2546


🏁 Script executed:

#!/bin/bash
# Get the full unique_by_key test to find thrust::copy and shared iterator usage
cat cub/test/catch2_test_device_select_unique_by_key.cu | tail -300

# Search for thrust::copy in all select test files
rg -n "thrust::copy" cub/test/ -C5 | head -100

# Check cuda::counting_iterator default template argument
rg -rn "counting_iterator" cub/cub/ -C3 | head -40
rg -rn "class counting_iterator\|struct counting_iterator\|counting_iterator =" libcudacxx/include/cuda/ -C5 | head -60

# Check if there's a default template parameter for counting_iterator that maps to unsigned int
rg -rn "counting_iterator" libcudacxx/include/cuda/iterator -C5 | head -60
fd "counting_iterator" libcudacxx/include/

Length of output: 26945



@gonidelis — found the failing test and the likely mechanism:

The affected test is "DeviceSelect::UniqueByKey works and uses vsmem for large types" in catch2_test_device_select_unique_by_key.cu:

auto vals_it = cuda::transform_iterator(cuda::counting_iterator(0U), index_to_huge_type_op_t<val_type>{});
// ...
thrust::copy(vals_it, vals_it + num_items, reference_vals.begin()); // reference_vals is host_vector<HugeType>

cuda::counting_iterator(0U) — CTAD deduces value_type = unsigned int. The transform iterator's value_type should then be resolved by Thrust's result_of<index_to_huge_type_op_t<val_type>(unsigned int)> → the huge custom type. That's what makes thrust::copy work.

Why adding the env test breaks it in the same TU:

The new test adds #include <cuda/devices> and #include <cuda/std/execution>. Those headers introduce additional template specializations and overloads that become visible to Thrust's iterator trait machinery — specifically thrust::result_of or thrust::invoke_result — when resolving value_type for the transform iterator. With gcc12, this resolution path gets perturbed and falls back to the base iterator's value_type (unsigned int) instead of the functor's return type (HugeType). thrust::copy then sees a source with value_type = unsigned int copying into host_vector<HugeType> → type mismatch failure.

Why separate TUs fix it: the new env-related headers are absent from the TU that contains the vsmem test, so result_of resolves correctly without interference.

The underlying bug is a gcc12-specific sensitivity in Thrust's transform_iterator value-type deduction when additional cuda::std/execution-policy specializations become visible in the same TU. Worth filing against libcudacxx/Thrust with that minimal reproducer pattern (thrust::result_of + cuda::transform_iterator + gcc12 + <cuda/std/execution> in scope).


🧠 Learnings used
Learnt from: sleeepyjack
Repo: NVIDIA/cccl PR: 8857
File: cudax/include/cuda/experimental/__cuco/__hyperloglog/hyperloglog_impl.cuh:426-428
Timestamp: 2026-05-06T23:47:17.597Z
Learning: In the CCCL/CUDA C++ Core Libraries codebase (NVIDIA/cccl), treat `_CCCL_API` as host-and-device callable. `_CCCL_API` expands to `_CCCL_HOST_DEVICE` via `libcudacxx/include/cuda/std/__cccl/visibility.h`, so functions marked with `_CCCL_API` may be invoked from both host and device code. When reviewing device-code contexts, do not flag `_CCCL_API`-annotated functions as if they were host-only.

Learnt from: NaderAlAwar
Repo: NVIDIA/cccl PR: 9171
File: libcudacxx/include/cuda/std/__cccl/diagnostic.h:126-126
Timestamp: 2026-06-03T13:24:36.356Z
Learning: When reviewing code that uses NVIDIA NVCC/NVRTC diagnostic suppression pragmas, treat `nv_diag_suppress` as supporting comma-separated warning numbers in a single directive. For example, `_Pragma("nv_diag_suppress 1444,20199")` (or an equivalent `#pragma nv_diag_suppress 1444,20199`) is valid; do not flag comma-separated warning IDs inside `nv_diag_suppress` pragmas as unsupported.

@github-actions

This comment has been minimized.

@gonidelis

Copy link
Copy Markdown
Member

@miscco i pushed a split into two different TUs it should fix the cuda12 gcc12 container ci bug. feel free to undo it if you don't want it

@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_select_unique_by_key_env.cu (1)

146-146: 📐 Maintainability & Code Quality | ⚡ Quick win

suggestion: Line 146 asserts identical temp-storage size across env variants, but env-based dispatch can legally select different policies/tunings and therefore different num_bytes. Keep the per-env query/launch flow, but relax this to REQUIRE(num_bytes > 0 || num_items == 0) (or just drop the equality assertion) so the test validates correctness instead of an implementation detail.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 58a3d517-e478-4922-973c-ac6cf6dcb9bd

📥 Commits

Reviewing files that changed from the base of the PR and between a57c6f1 and 3b85cc5.

📒 Files selected for processing (2)
  • cub/test/catch2_test_device_select_unique_by_key.cu
  • cub/test/catch2_test_device_select_unique_by_key_env.cu
💤 Files with no reviewable changes (1)
  • cub/test/catch2_test_device_select_unique_by_key.cu

@github-actions

This comment has been minimized.

miscco and others added 3 commits June 15, 2026 09:07
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 changed the base branch from main to device_select_unique_env June 15, 2026 07:32
@miscco
miscco force-pushed the device_select_unique_by_key branch from 3b85cc5 to cf96faa Compare June 15, 2026 07:34
@miscco miscco closed this Jun 15, 2026
@miscco
miscco deleted the device_select_unique_by_key branch June 15, 2026 07:38
@github-actions

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 2h 31m: Pass: 17%/287 | Total: 9d 18h | Max: 2h 31m | Hits: 34%/202241

See results here.

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