Repository navigation
Description
Summary
The current CUB _env.cu tests do not consistently follow the conventions for testing the single-phase, environment-aware device API overloads documented in docs/cub/developer/test_overview.rst — "Testing Environment-Aware API Overloads" (see #11609). An audit of all 25 catch2_test_device_*_env.cu files found violations of both documented conventions. This issue tracks them so they can be cleaned up.
The two conventions:
expected_allocation_sizededup: exactly one"<algorithm> uses environment"check per public API entry point (checklist item 2), even when several entry points share the same internal implementation. Overloads differing only by a defaulted functor/comparator collapse to one entry point; overloads with a different parameter shape (DoubleBuffervs. pointer-pair, in-place vs. out-of-place,...Copyvariants, etc.) are separate entry points.TEST_LAUNCHguards: item 1 ("works with default environment") should be guarded#if TEST_LAUNCH == 0(it bypasses the launch wrapper); items 3–6 ("uses custom stream", "can be tuned", determinism, operator+environment) should be guarded#if TEST_LAUNCH != 1(launch id 1 forces the null stream and needsexpected_allocation_sizeupfront for its fixed-size arena, which these tests don't always provide).
1. expected_allocation_size dedup violations
Dominant pattern — re-checked in the "uses custom stream" test for an entry point already covered by "uses environment":
catch2_test_device_copy_env.cu—DeviceCopy::Batchedcatch2_test_device_memcpy_env.cu—DeviceMemcpy::Batchedcatch2_test_device_run_length_encode_env.cu—Encode,NonTrivialRunscatch2_test_device_histogram_env.cu— all 4 entry points (HistogramEven,HistogramRange,MultiHistogramEven,MultiHistogramRange), each checked 4x (env + custom-stream, x 1D/2D) instead of once — 16 checks where 4 sufficecatch2_test_device_radix_sort_env.cu—SortKeys,SortKeysDescending,SortPairs,SortPairsDescending(pointer-pair variants)catch2_test_device_segmented_radix_sort_env.cu— same 4 pointer-pair entry points, plusSortPairsDoubleBuffercatch2_test_device_segmented_sort_pairs_env.cu—SortPairs,SortPairsDescending(pointer + DoubleBuffer)
Default-vs-custom-functor overloads not collapsed to one check:
catch2_test_device_reduce_env.cu—ArgMin,ArgMax(2x each: with/withoutcompare_op)catch2_test_device_select_env.cu—Unique(out-of-place),Unique(in-place),UniqueByKey(2x each: default vs. customequality_op)catch2_test_device_reduce_arg_minmax_env.cu— the compare_op variant duplicates the base check (needs a closer look: the file uses one parametrized test for bothArgMinMax/ArgMinLastMax, so it's unclear whether 1 or 2 genuine entry points are involved)
Same entry point re-checked in an unrelated correctness variant:
catch2_test_device_reduce_env.cu—Reducechecked 3x (base,not_guaranteedfallback,no_init),Sumchecked 2x (base,not_guaranteedfallback)
Missing entirely (entry point has zero expected_allocation_size check):
catch2_test_device_segmented_reduce_env.cu— all 6 fixed-size-segment entry pointscatch2_test_device_radix_sort_env.cu— all 4 plain-DoubleBufferentry pointscatch2_test_device_topk_env.cu,catch2_test_device_for_env.cu,catch2_test_device_transform_env.cu— item 2 entirely absent (none of these route through thelaunch_envwrapper)
Fully compliant: catch2_test_device_adjacent_difference_env.cu, catch2_test_device_find_env.cu, catch2_test_device_find_bound_sorted_values_env.cu, catch2_test_device_scan_env.cu, catch2_test_device_scan_by_key_env.cu, catch2_test_device_segmented_scan_env.cu, catch2_test_device_partition_env.cu, catch2_test_device_merge_env.cu, catch2_test_device_merge_sort_env.cu, catch2_test_device_segmented_sort_keys_env.cu.
2. TEST_LAUNCH guard violations
Dominant pattern — "uses custom stream" tests left unguarded, running meaninglessly under launch id 1 (the harness forces the null stream there):
catch2_test_device_select_env.cu, catch2_test_device_partition_env.cu, catch2_test_device_merge_env.cu, catch2_test_device_merge_sort_env.cu, catch2_test_device_copy_env.cu, catch2_test_device_memcpy_env.cu, catch2_test_device_histogram_env.cu, catch2_test_device_run_length_encode_env.cu, catch2_test_device_radix_sort_env.cu, catch2_test_device_segmented_radix_sort_env.cu, catch2_test_device_segmented_sort_pairs_env.cu, catch2_test_device_find_env.cu (stream-kind sections). Only catch2_test_device_reduce_arg_minmax_env.cu guards this correctly with #if TEST_LAUNCH == 0.
Isolated bugs:
catch2_test_device_scan_env.cu— 7 of 11 item-1 ("works with default environment") tests sit inside a#if TEST_LAUNCH != 1block instead of#if TEST_LAUNCH == 0, so they compile/run twice instead of once.catch2_test_device_select_unique_by_key_env.cu— item-1-equivalent tests (direct API calls, no launch wrapper) are entirely unguarded, running 3x.catch2_test_device_segmented_radix_sort_env.cu— twoDoubleBufferitem-1 ("works with default environment") tests are unguarded, unlike their 6 guarded siblings.catch2_test_device_merge_env.cu/catch2_test_device_merge_sort_env.cu— one or two item-4 ("can be tuned") tests escape the#if TEST_LAUNCH != 1guard used by their siblings.catch2_test_device_radix_sort_env.cu— item-4 guard is actually#if TEST_LAUNCH == 0, but the matching#endifcomment says// TEST_LAUNCH != 1(stale/misleading comment; also unnecessarily excludes launch id 2).
Structural outliers (don't use the shared launch_env wrapper, so the TEST_LAUNCH axis mostly doesn't apply): catch2_test_device_for_env.cu, catch2_test_device_topk_env.cu, catch2_test_device_transform_env.cu. catch2_test_device_topk_env.cu additionally uses a nonstandard // %PARAM% TEST_LAUNCH lid 0:2 instead of the usual 0:1:2.
Root cause
Both violation patterns trace back to the same habit: copy-pasting expected_allocation_size(...) and/or a custom stream into every scenario variant of an entry point, instead of writing one dedicated "<algorithm> uses environment" test and letting other test cases (custom stream, tuning, determinism, functor variants) exercise only their own concern.
Suggested follow-up
Clean up the ~15 affected files: drop redundant expected_allocation_size checks (keeping the dedicated "uses environment" test per entry point), add the missing checks (segmented_reduce_env's fixed-size overloads, radix_sort_env's DoubleBuffer overloads), and guard "uses custom stream" tests with #if TEST_LAUNCH != 1 wherever currently unguarded. catch2_test_device_reduce_env.cu's Reduce/Sum triple/double-checks and select_env.cu's functor-overload duplicates should also be trimmed to one check each.
🤖 Filed with Claude Code
Activity