Skip to content

Test for corner-cases in mul_overflow.pass.cpp#9792

Open
acosmicflamingo wants to merge 4 commits into
NVIDIA:mainfrom
acosmicflamingo:mul-overflow-corner-cases
Open

Test for corner-cases in mul_overflow.pass.cpp#9792
acosmicflamingo wants to merge 4 commits into
NVIDIA:mainfrom
acosmicflamingo:mul-overflow-corner-cases

Conversation

@acosmicflamingo

@acosmicflamingo acosmicflamingo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

While working on optimizing mul_overflow kernel to resolve #7739, I have been using a local test-suite to catch corner-cases to ensure I don't introduce any regressions. For some odd reason, I am finding that when I added the tests to mul_overflow.pass.cpp in the other PR, I'd see an atrocious execution time:

--------------------------------------------------------------------------
94.41s: libcu++ :: cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp
4.89s: libcu++ :: std/algorithms/alg.nonmodifying/alg.count/pstl.count_if.pass.cpp
4.88s: libcu++ :: std/algorithms/alg.nonmodifying/alg.for_each/pstl.for_each.pass.cpp
4.81s: libcu++ :: std/algorithms/alg.nonmodifying/alg.for_each/pstl.for_each_n.pass.cpp
4.76s: libcu++ :: std/algorithms/alg.nonmodifying/alg.all_of/pstl.all_of.pass.cpp
4.70s: libcu++ :: std/numerics/numeric.ops/reduce/pstl.reduce.pass.cpp
4.70s: libcu++ :: std/algorithms/alg.nonmodifying/alg.find/pstl.find_if.pass.cpp
4.49s: libcu++ :: std/algorithms/alg.nonmodifying/alg.find/pstl.find.pass.cpp
3.54s: libcu++ :: std/algorithms/alg.nonmodifying/alg.count/pstl.count.pass.cpp
3.50s: libcu++ :: std/algorithms/alg.nonmodifying/alg.find/pstl.find_if_not.pass.cpp
3.37s: libcu++ :: std/algorithms/alg.nonmodifying/alg.none_of/pstl.none_of.pass.cpp
3.26s: libcu++ :: std/algorithms/alg.nonmodifying/alg.any_of/pstl.any_of.pass.cpp
2.47s: libcu++ :: cuda/containers/views/mdspan/default_accessor/accessor.relation.fail.cpp
2.30s: libcu++ :: std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.fail.cpp
2.21s: libcu++ :: std/utilities/meta/meta.trans/meta.trans.other/result_of.fail.cpp
2.15s: libcu++ :: std/text/format/format.fmt.string/ctor_fails/3.fail.cpp
2.15s: libcu++ :: std/text/format/format.fmt.string/ctor_fails/4.fail.cpp
2.13s: libcu++ :: std/algorithms/alg.sorting/alg.sort/sort/sort_constexpr.pass.cpp
2.06s: libcu++ :: std/text/format/format.fmt.string/ctor_fails/1.fail.cpp
2.05s: libcu++ :: std/iterators/iterator.container/empty.container.fail.cpp

This PR (and CI run results) would assure me that the slow times are truly local in scope, while making sure that the current version of mul_overflow covers all corner-cases.

I also added test_corner_cases below test_exhaustive since I didn't want to have it called repeatedly (especially because I'm explicitly controlling types to test the corner cases).

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Jul 10, 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.

@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 10, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Progress in CCCL Jul 10, 2026
@acosmicflamingo

Copy link
Copy Markdown
Contributor Author

@fbusato if you agree with the approach, can you run /ok to test so we can see what the CI output is?

@acosmicflamingo acosmicflamingo marked this pull request as ready for review July 10, 2026 22:00
@acosmicflamingo acosmicflamingo requested a review from a team as a code owner July 10, 2026 22:00
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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: 3efb4f23-612c-442b-b119-076e6d5a2e43

📥 Commits

Reviewing files that changed from the base of the PR and between 32c21be and ece8939.

📒 Files selected for processing (1)
  • libcudacxx/test/libcudacxx/cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Expanded multiplication overflow coverage to include additional unsigned integer type combinations.
    • Added targeted corner-case checks for boundary behaviors, including signed min/max interactions, guarded wider-result scenarios, and specific 128-bit unsigned cases.
    • Improved and renamed the exhaustive validation driver to strengthen overall coverage.

Walkthrough

Changes

Multiply overflow test coverage

Layer / File(s) Summary
Expand exhaustive coverage
libcudacxx/test/libcudacxx/cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp
The exhaustive driver is renamed to test_exhaustive, and unsigned int is added to the tested type list.
Add corner-case execution
libcudacxx/test/libcudacxx/cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp
test_corner_cases() adds signed, unsigned, boundary, and __uint128_t multiplication assertions, and main invokes both test paths.

Assessment against linked issues

Objective Addressed Explanation
Optimize the device implementation of cuda::mul_overflow [#7739] The pull request changes only the multiplication-overflow test and does not modify the cuda::mul_overflow implementation.

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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
libcudacxx/test/libcudacxx/cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp (2)

110-130: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Add an explicit fixed-width-integer header for the new aliases and use the cuda::std aliases required by this test suite. These lines currently rely on transitive exposure of int8_t, int32_t, int64_t, uint32_t, and uint64_t. As per coding guidelines, include all headers needed by used symbols and do not rely on transitive includes.

Source: Coding guidelines


133-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Declare uint128_max as constexpr; its initializer is compile-time evaluable. As per coding guidelines, compile-time-evaluable variables must be constexpr.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e1e97b45-bf14-4c29-9e0a-f5bb7f5ca52e

📥 Commits

Reviewing files that changed from the base of the PR and between 0fa6cea and 32c21be.

📒 Files selected for processing (1)
  • libcudacxx/test/libcudacxx/cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp

Comment thread libcudacxx/test/libcudacxx/cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp Outdated
Comment thread libcudacxx/test/libcudacxx/cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp Outdated
@fbusato

fbusato commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

/ok to test ece8939

@fbusato fbusato requested a review from davebayer July 10, 2026 23:39
@github-actions

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 2h 11m: Pass: 97%/71 | Total: 2d 01h | Max: 1h 59m | Hits: 99%/328843

See results here.

@acosmicflamingo

Copy link
Copy Markdown
Contributor Author

Although the test failures themselves do not seem to be related to this PR, I actually found that there is a slowdown! This is from libcu++ nvcc GCC / [CTK13.3 GCC15 C++17] Build(amd64) log:

2026-07-11T00:08:31.4070895Z 5 warning(s) in tests
2026-07-11T00:08:31.4205936Z Slowest Tests:
2026-07-11T00:08:31.4206356Z --------------------------------------------------------------------------
2026-07-11T00:08:31.4206839Z 139.30s: libcu++ :: cuda/numeric/overflow.arithmetic/mul_overflow.pass.cpp
2026-07-11T00:08:31.4207250Z 15.07s: libcu++ :: cuda/argument/argument_traits.pass.cpp
...

However, with other runs I have noticed that the slowest tests very quite a bit. Here are two random ones I pulled up:

# From https://github.com/NVIDIA/cccl/pull/8740
2026-07-06T23:54:32.4247194Z 5 warning(s) in tests
2026-07-06T23:54:32.4364490Z Slowest Tests:
2026-07-06T23:54:32.4364889Z --------------------------------------------------------------------------
2026-07-06T23:54:32.4365397Z 46.15s: libcu++ :: std/algorithms/alg.nonmodifying/alg.any_of/pstl.any_of.pass.cpp
2026-07-06T23:54:32.4365933Z 45.16s: libcu++ :: std/algorithms/alg.nonmodifying/alg.for_each/pstl.for_each_n.pass.cpp
2026-07-06T23:54:32.4366554Z 44.37s: libcu++ :: std/algorithms/alg.nonmodifying/alg.count/pstl.count.pass.cpp
2026-07-06T23:54:32.4367040Z 42.52s: libcu++ :: std/algorithms/alg.nonmodifying/alg.for_each/pstl.for_each.pass.cpp
2026-07-06T23:54:32.4367542Z 42.49s: libcu++ :: std/algorithms/alg.nonmodifying/alg.none_of/pstl.none_of.pass.cpp
2026-07-06T23:54:32.4368002Z 42.29s: libcu++ :: std/algorithms/alg.nonmodifying/alg.find/pstl.find.pass.cpp
2026-07-06T23:54:32.4368471Z 41.71s: libcu++ :: std/algorithms/alg.nonmodifying/alg.find/pstl.find_if_not.pass.cpp

# From https://github.com/NVIDIA/cccl/pull/9694
2026-07-02T16:19:45.3816915Z 5 warning(s) in tests
2026-07-02T16:19:45.3932122Z Slowest Tests:
2026-07-02T16:19:45.3932481Z --------------------------------------------------------------------------
2026-07-02T16:19:45.3933312Z 274.54s: libcu++ :: std/algorithms/alg.modifying/alg.copy/copy_ptr.pass.cpp
2026-07-02T16:19:45.3933821Z 229.07s: libcu++ :: std/algorithms/alg.modifying/alg.move/move.pass.cpp
2026-07-02T16:19:45.3934254Z 218.02s: libcu++ :: std/algorithms/alg.modifying/alg.move/move_backward.pass.cpp
2026-07-02T16:19:45.3934768Z 201.21s: libcu++ :: cuda/pipeline/pipeline_group_concept_thread_scope_block.pass.cpp
2026-07-02T16:19:45.3935233Z 174.62s: libcu++ :: std/algorithms/alg.modifying/alg.copy/copy_backward.pass.cpp
2026-07-02T16:19:45.3935689Z 146.03s: libcu++ :: cuda/pipeline/pipeline_group_concept_thread_scope_device.pass.cpp
2026-07-02T16:19:45.3936147Z 145.12s: libcu++ :: cuda/numeric/overflow.arithmetic/add_overflow.pass.cpp
2026-07-02T16:19:45.3936583Z 136.65s: libcu++ :: std/algorithms/alg.modifying/alg.generate/generate_n.pass.cpp
2026-07-02T16:19:45.3937046Z 135.44s: libcu++ :: cuda/pipeline/pipeline_group_concept_thread_scope_system.pass.cpp
2026-07-02T16:19:45.3937499Z 132.23s: libcu++ :: cuda/numeric/overflow.arithmetic/sub_overflow.pass.cpp
2026-07-02T16:19:45.3937904Z 125.03s: libcu++ :: cuda/memcpy_async/memcpy_async_large.pass.cpp
2026-07-02T16:19:45.3938325Z 124.49s: libcu++ :: cuda/pipeline/pipeline_memcpy_async_thread_scope_block_32.pass.cpp

@acosmicflamingo

acosmicflamingo commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Great news; I am finding that this behavior might actually be completely expected, and that the kernels are being cached. I can deterministically get the slowdown by making sure the compiler has not come across the .cpp file in a particular state before. For example, merely copying and pasting a line and flipping the operands will cause a slowdown in the first run.

With that being said, merging this now would make the mul_overflow optimization PR easier to sift through, but I'm fine with it being merged there if y'all want 🙇🏽‍♂️

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.

[FEA]: Optimize cuda::mul_overflow

2 participants