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

Groupby hash aggregations use sort-based implementation if nested-type columns are used as values #14412

Open
divyegala opened this issue Nov 14, 2023 · 5 comments
Assignees
Labels
0 - Backlog In queue waiting for assignment bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. Performance Performance related issue

Comments

@divyegala
Copy link
Member

divyegala commented Nov 14, 2023

We should be able to use nested-type columns as values and still be able to invoke a hash-based groupby, as hash-based is generally faster so we do not want to be silently using sort-based.

// Currently, input values (not keys) of STRUCT and LIST types are not supported in any of
// hash-based aggregations. For those situations, we fallback to sort-based aggregations.
if (v_type.id() == type_id::STRUCT or v_type.id() == type_id::LIST) { return false; }

Reference thread: #13795 (comment)

@divyegala divyegala added bug Something isn't working Needs Triage Need team to review and classify labels Nov 14, 2023
@bdice
Copy link
Contributor

bdice commented Nov 14, 2023

This code block is the piece in question:

// Currently, input values (not keys) of STRUCT and LIST types are not supported in any of
// hash-based aggregations. For those situations, we fallback to sort-based aggregations.
if (v_type.id() == type_id::STRUCT or v_type.id() == type_id::LIST) { return false; }

@ttnghia, you added this in #13676. Do you know if this fallback is still required, or why?

We discussed this a bit here: #13676 (comment)

Side note, I'm punching my past self -- I asked this question on that PR, and never submitted my review:
image

@ttnghia
Copy link
Contributor

ttnghia commented Nov 14, 2023

@ttnghia, you added this in #13676. Do you know if this fallback is still required, or why?

Because hash-based aggregations are implemented for plain type only, using the operator such as < instead of user-provided comparator. See struct update_target_element in cpp/include/cudf/detail/aggregation/aggregation.cuh.

If we want to support hash-based aggregates for nested types, we need to rewrite such struct update_target_element such that we can compare rows using a row comparator instead.

@bdice
Copy link
Contributor

bdice commented Nov 14, 2023

Great, that was helpful. I think we can do this. I think the rough plan would be to preprocess the table so we have device comparators that can be used, pass the preprocessed table info through all the aggregation machinery, and use the device comparator where needed in update_target_element. Does that sound right to you?

@ttnghia
Copy link
Contributor

ttnghia commented Nov 14, 2023

Yes that sounds good. Note that we only need to rework for ARGMIN and ARGMAX (other aggregations are SUM, PRODUCT etc that can't support nested types), not for everything thus the amount of work should not be very heavy.

@GregoryKimball GregoryKimball added 0 - Backlog In queue waiting for assignment libcudf Affects libcudf (C++/CUDA) code. and removed Needs Triage Need team to review and classify labels Dec 14, 2023
@GregoryKimball GregoryKimball moved this to Needs owner in libcudf Dec 14, 2023
@GregoryKimball GregoryKimball added feature request New feature or request Performance Performance related issue and removed feature request New feature or request labels Dec 14, 2023
@GregoryKimball GregoryKimball moved this from Needs owner to To be revisited in libcudf Feb 20, 2024
@PointKernel PointKernel self-assigned this Dec 18, 2024
@PointKernel
Copy link
Member

PointKernel commented Jan 16, 2025

To clarify, the reason we cannot use hash-based groupby for nested types is that there is currently no way to atomically update nested data on the device due to the lack of direct hardware support for such operations. A possible solution is to use an atomic lock table, which CCCL is expected to support in the future NVIDIA/cccl#990.

We should backlog this for now until the atomic lock table becomes available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 - Backlog In queue waiting for assignment bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. Performance Performance related issue
Projects
Status: To be revisited
Development

No branches or pull requests

5 participants