Skip to content

[cub] Replace assert with CHECK or REQUIRE in tests#8999

Merged
davebayer merged 1 commit into
NVIDIA:mainfrom
davebayer:cub_replace_assert_with_catch2_macros
May 20, 2026
Merged

[cub] Replace assert with CHECK or REQUIRE in tests#8999
davebayer merged 1 commit into
NVIDIA:mainfrom
davebayer:cub_replace_assert_with_catch2_macros

Conversation

@davebayer
Copy link
Copy Markdown
Contributor

@davebayer davebayer commented May 15, 2026

Using assert outside of libcu++ for testing is not safe, because we compile with optimizations enabled and that meanst NDEBUG is defined, thus assert expands to noop. This PR replaces them with catch2 test macros.

@davebayer davebayer requested a review from a team as a code owner May 15, 2026 06:30
@davebayer davebayer requested a review from pauleonix May 15, 2026 06:30
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 15, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 15, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review 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: 070b0c74-4bea-4103-8422-4a110331012d

📥 Commits

Reviewing files that changed from the base of the PR and between 329af26 and c9b107a.

📒 Files selected for processing (9)
  • cub/cub/detail/integer_utils.cuh
  • cub/test/catch2_test_block_load_to_shared.cu
  • cub/test/catch2_test_block_radix_sort_custom.cu
  • cub/test/catch2_test_device_decoupled_look_back.cu
  • cub/test/catch2_test_device_segmented_scan.cu
  • cub/test/catch2_test_warp_scan.cu
  • cub/test/catch2_test_warp_scan_api.cu
  • cub/test/catch2_test_warp_scan_partial_helper.cuh
  • cub/test/internal/catch2_test_integer_utils.cu
💤 Files with no reviewable changes (2)
  • cub/test/internal/catch2_test_integer_utils.cu
  • cub/cub/detail/integer_utils.cuh
✅ Files skipped from review due to trivial changes (1)
  • cub/test/catch2_test_warp_scan.cu

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Replaced C runtime asserts with Catch2 CHECK/REQUIRE across multiple device and host tests for clearer test failures and diagnostics.
  • Chores
    • Removed internal integer/floating-point utility helpers from the codebase.

important:

Walkthrough

Test-only changes: device- and host-side C assert() usages are replaced with Catch2 test macros (REQUIRE, REQUIRE_DEVICE, CHECK) across multiple CUDA test files; a private integer utility header cub/cub/detail/integer_utils.cuh was removed.

important:

Changes

Catch2 assertion framework migration

Layer / File(s) Summary
Include setup and precondition assertions
cub/test/catch2_test_block_radix_sort_custom.cu, cub/test/catch2_test_device_decoupled_look_back.cu, cub/test/catch2_test_device_segmented_scan.cu, cub/test/catch2_test_warp_scan_partial_helper.cuh, cub/test/catch2_test_warp_scan.cu
Top-of-file includes remove NDEBUG/<cassert> patterns where present and precondition validations (e.g., small_size > 0, host-result size divisibility) use Catch2 REQUIRE.
Block-level kernels: alignment and radix-sort checks
cub/test/catch2_test_block_load_to_shared.cu, cub/test/catch2_test_block_radix_sort_custom.cu
Device-side shared-memory alignment check and block radix-sort kernel key/value verifications (ascending/descending, bit-subrange, blocked-to-striped, key/pair variants) use Catch2 REQUIRE_DEVICE/REQUIRE instead of assert.
Scan-related kernel checks
cub/test/catch2_test_device_decoupled_look_back.cu, cub/test/catch2_test_warp_scan_api.cu
Decoupled look-back tile data/aggregate validations and warp-scan API custom functor operand-range checks use Catch2 REQUIRE_DEVICE/REQUIRE.
Integer/floating-point utility tests and header removal
cub/test/internal/catch2_test_integer_utils.cu, cub/cub/detail/integer_utils.cuh
Integer split/merge and floating-point comparable-integer tests migrate assert -> Catch2 CHECK (fix assignment-in-assert to equality); the internal header cub/cub/detail/integer_utils.cuh was removed.

important: Possibly related PRs

  • NVIDIA/cccl#8928: Introduces device-capable Catch2 macros (including REQUIRE_DEVICE) used by these test migrations.

important: Suggested reviewers

  • pauleonix
  • bernhardmgruber
  • srinivasyadav18
  • gevtushenko

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0274cd35-7d0c-401a-865f-079699d7dda5

📥 Commits

Reviewing files that changed from the base of the PR and between db93bd1 and f6b8406.

📒 Files selected for processing (8)
  • cub/test/catch2_test_block_load_to_shared.cu
  • cub/test/catch2_test_block_radix_sort_custom.cu
  • cub/test/catch2_test_device_decoupled_look_back.cu
  • cub/test/catch2_test_device_segmented_scan.cu
  • cub/test/catch2_test_warp_scan.cu
  • cub/test/catch2_test_warp_scan_api.cu
  • cub/test/catch2_test_warp_scan_partial_helper.cuh
  • cub/test/internal/catch2_test_integer_utils.cu

Comment thread cub/test/catch2_test_block_load_to_shared.cu Outdated
Comment thread cub/test/internal/catch2_test_integer_utils.cu Outdated
@davebayer davebayer force-pushed the cub_replace_assert_with_catch2_macros branch from f6b8406 to 329af26 Compare May 15, 2026 07:32
@@ -1,142 +0,0 @@
// SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
#include <cub/detail/integer_utils.cuh>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've removed the source file & test. The functionality is not used anywhere in cub, plus it was never actually tested, because the assert expanded to noop instead of the test due to missing #undef NDEBUG

@github-actions

This comment has been minimized.

Comment on lines +83 to +85
CHECK(thread_keys[threadIdx.x][0] == expected_output[threadIdx.x][0]);
CHECK(thread_keys[threadIdx.x][1] == expected_output[threadIdx.x][1]);
CHECK(thread_keys[threadIdx.x][2] == expected_output[threadIdx.x][2]);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gevtushenko is strongly for using REQUIRE here and in the rest of the PR

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.

I remain against. As a person that has to figure out what's going on in case of a test failure, I need the largest context possible of meaningful information.

That means, I don't want to see dependent failures, like the failed comparison with an expected result after a failed call to radix sort. That call to radix sort needs a REQUIRE of course. But a comparison of the results keys and values needs a CHECK since in case of a mismatch in the result, I want to see the mismatch of the keys and values. This may allow me to deduce better, what kind of failure happened, without first modifying the test code and recompiling.

@gevtushenko what would be the advantage of REQUIRE here? I don't see it.

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.

To add some context from the code review hour: According to @davebayer CHECK in device code is currently implemented to do the same as REQUIRE because anything else would be hard to implement. So with the current implementation you get REQUIRE semantics anyway and @gevtushenko just argued that this state is confusing and that CHECK should not compile in device code if it can't provide the correct semantics.

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.

I see. I didn't see this was device code. Fine then!

@davebayer davebayer force-pushed the cub_replace_assert_with_catch2_macros branch from 329af26 to c9b107a Compare May 20, 2026 14:47
@github-actions
Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 11m: Pass: 100%/285 | Total: 2d 08h | Max: 42m 54s | Hits: 89%/217105

See results here.

@davebayer davebayer merged commit ea2615f into NVIDIA:main May 20, 2026
303 of 305 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL May 20, 2026
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.

4 participants