feat(cudf): GPU Decimal (Part 4)#17806
Conversation
✅ Deploy Preview for meta-velox canceled.
|
| } | ||
| int sign = 1; | ||
| if (numerator < 0) { | ||
| numerator = -numerator; |
There was a problem hiding this comment.
Per @bdice:
This is UB if numerator == INT128_MIN.
| __int128_t scaled = numerator * scale; | ||
| __int128_t quotient = scaled / denom; | ||
| __int128_t remainder = scaled % denom; | ||
| if (remainder * 2 >= denom) { |
There was a problem hiding this comment.
Per @bdice:
This may help guard against overflow.
Suggested change
- if (remainder * 2 >= denom) {
- if (remainder >= denom - remainder) {
There was a problem hiding this comment.
Also per @bdice:
Just verifying: Is -1.5 supposed to round "half up" to -1 or "half away from zero" to -2? This does the latter. Please add a comment indicating the convention being followed.
|
|
||
| template <typename OutT> | ||
| __device__ OutT | ||
| decimalDivideImpl(__int128_t numerator, __int128_t denom, __int128_t scale) { |
There was a problem hiding this comment.
Per @bdice:
The parameter named scale is actually something like 10 ^ scale. We should name it more clearly, since scale is typically the exponent and not the value ten-to-the-exponent.
| denom = -denom; | ||
| sign = -sign; | ||
| } | ||
| __int128_t scaled = numerator * scale; |
There was a problem hiding this comment.
Per @bdice:
This function should explicitly document that the rescaling has the potential for UB (overflows).
| OutT* out; | ||
| __int128_t scale; | ||
|
|
||
| __device__ void operator()(int32_t idx) const { |
There was a problem hiding this comment.
Per @bdice:
As before, int32_t indicates a row index? Use cudf::size_type here and in the counting iterators if so.
| int32_t aRescale, | ||
| rmm::cuda_stream_view stream) { | ||
| if (inType == cudf::type_id::DECIMAL64) { | ||
| if (outType == cudf::type_id::DECIMAL64) { |
There was a problem hiding this comment.
Per @bdice:
We could use cudf::double_type_dispatcher here (potentially with a custom type map that only accepts numeric::decimal64 / numeric::decimal128), then use cudf::device_storage_type_t to recover the underlying types. It sounds like a lot of logic but it's reusable across the repeating dispatches for column/scalar variants.
There was a problem hiding this comment.
Done, but not using a custom type map, as it's not clear to me how to do that with a double_type_dispatcher and not sure it would make the code any cleaner, as we'd still need to further validate the type combinations even if the custom map only allowed certain types in at all. Adding CUDF_UNREACHABLE in the other-type-combinations stub instead.
|
|
||
| target_compile_options(velox_cudf_expression PRIVATE -Wno-missing-field-initializers) | ||
|
|
||
| set_target_properties(velox_cudf_expression PROPERTIES CUDA_STANDARD 20 CUDA_STANDARD_REQUIRED ON) |
There was a problem hiding this comment.
Moved to root CMakeLists.txt (possible contentious)
| enable_language(CUDA) | ||
| # Use same C++ standard throughout | ||
| set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) | ||
| set(CMAKE_CUDA_STANDARD_REQUIRED ${CMAKE_CXX_STANDARD_REQUIRED}) |
There was a problem hiding this comment.
Not sure why this was deemed necessary. It might have been a leftover from Part 2, although Part 2 obviously works just fine without it. Should it still be moved here (from the CMakeLists.txt in cudf/expression)? Will it break Wave, or at least offend those devs?
Selective Build Plan
Selective build plan |
65a3c66 to
95b71f3
Compare
This reverts commit e1a8cbf.
95b71f3 to
80fc52b
Compare
CI Failure Analysis
❌ Linux release with adapters — BUILD Failure View logsBuild errors: Linker error when building The Correlation with PR changes: This failure is not caused by this PR. PR #17806 only modifies files under Known issues:
Recommended fix: Rebase this PR branch onto the latest git fetch upstream && git rebase upstream/main |
Decimal expression code refactoring and tidying moved from Part 3.
@bdice's comments moved from #16751.