Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify trailing return types in AST operators. #18185

Open
wants to merge 1 commit into
base: branch-25.04
Choose a base branch
from

Conversation

bdice
Copy link
Contributor

@bdice bdice commented Mar 6, 2025

Description

Currently AST operators use decltype aggressively to determine their trailing return types.

In #17793 we found that CUDA 11 didn't work well with one such decltype trailing return type definition, resulting in a bug (root cause unknown).

This PR simplifies our definitions of trailing return types when the output type is known and does not depend on the input type.

We assume that comparison and logical operators (==, !=, <, >, <=, >=, &&, ||, !) are always acting on regular-enough types to give bool, as expected by the C++ standard when those operators are not overloaded by the user.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@bdice bdice requested a review from a team as a code owner March 6, 2025 19:22
@bdice bdice requested review from vyasr and mhaseeb123 March 6, 2025 19:22
@github-actions github-actions bot added the libcudf Affects libcudf (C++/CUDA) code. label Mar 6, 2025
@bdice bdice added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Mar 6, 2025
@bdice
Copy link
Contributor Author

bdice commented Mar 6, 2025

cc: @miscco @lamarrr

Comment on lines 765 to 769
template <typename InputT>
__device__ inline auto operator()(InputT input) -> decltype(!input)
__device__ inline auto operator()(InputT input) -> bool
{
return !input;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🙀

Comment on lines +775 to 784
template <typename From>
__device__ inline auto operator()(From f) -> To
{
if constexpr (cuda::std::is_floating_point_v<To>) {
if constexpr (is_fixed_point<From> && cuda::std::is_floating_point_v<To>) {
return convert_fixed_to_floating<To>(f);
} else {
return static_cast<To>(f);
}
}

template <typename From, typename cuda::std::enable_if_t<!is_fixed_point<From>()>* = nullptr>
__device__ inline auto operator()(From f) -> decltype(static_cast<To>(f))
{
return static_cast<To>(f);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

lets drop this one for now?

@bdice
Copy link
Contributor Author

bdice commented Mar 6, 2025

I’m seeing compilation errors for a bunch of these, including && between duration types. Part of the magic of the decltype is that if the trailing return type could not be deduced from the decltype expression, then the AST knows not to allow that path. By replacing that with bool, we are assuming all types can be and-ed together. I’ll probably need to take a very precise subset of these that are known to exist for all input types, perhaps (in)equality, identity, and some null-checks? Logical ops and casts probably won’t work. This PR may not actually yield much real progress, I’ll refine it and make sure it builds locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants