Skip to content

Add optional sticky fixed-point overflow tracking (CUDF_TRACK_FIXED_POINT_OVERFLOW)#22356

Draft
Avinash-Raj wants to merge 2 commits intorapidsai:mainfrom
Avinash-Raj:avi/decimal-overflow
Draft

Add optional sticky fixed-point overflow tracking (CUDF_TRACK_FIXED_POINT_OVERFLOW)#22356
Avinash-Raj wants to merge 2 commits intorapidsai:mainfrom
Avinash-Raj:avi/decimal-overflow

Conversation

@Avinash-Raj
Copy link
Copy Markdown
Contributor

Summary

  • Introduces an opt-in CMake flag CUDF_TRACK_FIXED_POINT_OVERFLOW (default OFF). When enabled, defines CUDF_TRACK_FIXED_POINT_OVERFLOW for the cudf target (PUBLIC) so headers and translation units agree on fixed_point layout.
  • When the macro is defined, fixed_point carries a sticky _overflow_flag, exposed as overflow_occurred(), updated on +, -, *, / and rescaled() (including shift overflow via detail::shift_overflows).
  • Overflow predicates still assert only under __CUDACC_DEBUG__; enabling tracking does not by itself turn overflows into exceptions.
  • This flag is required to ensure velox-cudf throws an exception whenever an decimal overflow occurs.

@Avinash-Raj Avinash-Raj requested review from a team as code owners May 2, 2026 07:58
@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels May 2, 2026
@Avinash-Raj Avinash-Raj changed the title Add optional sticky fixed-point overflow tracking (CUDF_TRACK_FIXED_POINT_OVERFLOW) [Draft] Add optional sticky fixed-point overflow tracking (CUDF_TRACK_FIXED_POINT_OVERFLOW) May 2, 2026
@Avinash-Raj Avinash-Raj marked this pull request as draft May 2, 2026 07:59
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 2, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@Avinash-Raj Avinash-Raj changed the title [Draft] Add optional sticky fixed-point overflow tracking (CUDF_TRACK_FIXED_POINT_OVERFLOW) Add optional sticky fixed-point overflow tracking (CUDF_TRACK_FIXED_POINT_OVERFLOW) May 2, 2026
@bdice
Copy link
Copy Markdown
Contributor

bdice commented May 2, 2026

I would favor adding new operators/functions rather than a compile-time flag — we want to be able to ship one build of cuDF that works universally.

@devavret
Copy link
Copy Markdown
Contributor

devavret commented May 4, 2026

@bdice I'd imagine this is not limited to scalar functions like binaryops and such. We'd also need to detect overflow in aggregations like groupby and reduce. And those would require overloading the existing +,* operators.

What's your opinion on adding a new type maybe called safe_decimal.

Spark should also have a concept of arithmetic exception for overflows. How do they support this with libcudf decimal?

@mattgara
Copy link
Copy Markdown

mattgara commented May 4, 2026

What's your opinion on adding a new type maybe called safe_decimal.

Inline with this thinking, we could extend cudf's fixed_point to implement this:

enum class overflow_tracking { off, on };

template <typename Rep, Radix Rad,
          overflow_tracking Track = overflow_tracking::off>
class fixed_point{ ...

and use if constexpr (Track == overflow_tracking::on) to branch the implementation based on this configuration. Effectively, this should be compile-time semantically equivalent to having a safe_decimal, but with less code duplication.

@ttnghia
Copy link
Copy Markdown
Contributor

ttnghia commented May 4, 2026

This is related to ANSI support that I've recently filed: #21676
We can use some kind of input enum like mentioned above, and custom return type as my suggestion.

@Avinash-Raj
Copy link
Copy Markdown
Contributor Author

Ok, replaced the CMake CUDF_TRACK_FIXED_POINT_OVERFLOW flag with an opt-in overflow_tracking NTTP on numeric::fixed_point and add decimal*_safe / type_id::DECIMAL*_SAFE so velox-cudf gets per-element overflow detection without requiring a separate libcudf build.

@pmattione-nvidia
Copy link
Copy Markdown
Contributor

You might want to put overflow tracking into the floating <--> decimal conversion code as well (include/cudf/fixed_point/detail/floating_conversion.hpp). E.g. there are the guarded_left_shift() and guarded_right_shift() functions, and there are potential overflows in convert_floating_to_integral_shifting(), shift_to_decimal_pospow(), and shift_to_decimal_negpow(). All potential overflow sites are mentioned explicitly in the code comments in these functions.

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

Labels

CMake CMake build issue libcudf Affects libcudf (C++/CUDA) code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants