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

Bugfix for reduce-by-segment with differing input and output types #1987

Merged
merged 3 commits into from
Jan 3, 2025

Conversation

mmichel11
Copy link
Contributor

@mmichel11 mmichel11 commented Jan 3, 2025

For differing input and output key / value types, we cannot store an input element into a variable that is the output type. This is especially important for discard iterators in the output where we are met with a compile-time error if we attempt to store an input into this type as it can hold no value.

A test case has been added which combines zip and discard iterators. This catches the compilation issue before the fix.

For differing key types, we cannot store an input key into a variable that is
the output key type. This is important for discard iterators in the output where
we are met with a compile-time error if we attempt to do so.

Signed-off-by: Matthew Michel <[email protected]>
@mmichel11 mmichel11 changed the title Hotfix for reduce-by-segment with differing input and output types Bugfix for reduce-by-segment with differing input and output types Jan 3, 2025
auto end_keys_in = oneapi::dpl::make_zip_iterator(d_keys1 + n, d_keys2 + n);
auto begin_vals_in = oneapi::dpl::make_zip_iterator(d_values1, d_values2);
auto begin_keys_out = oneapi::dpl::make_zip_iterator(d_output_keys, oneapi::dpl::discard_iterator());
auto begin_vals_out = oneapi::dpl::make_zip_iterator(d_output_values1, d_output_values2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to include a discard iterator in the values as well? I think right now we are just hitting a compilation issue just with the key side of the issue, not the value side, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it makes sense to add this for completeness as the same issue would occur with a discard iterator in the output values. I have added it.

Comment on lines +943 to +945
const auto& __next_key = get<2>(__tup);
const auto& __current_key = get<3>(__tup);
const auto& __current_value = get<1>(get<0>(__tup));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if there is any advantage, but we could get the type with std::tuple_element_t<I, _Tup> rather than using auto.
Effectively I think we end up with the same code, without much more information about the types were using. Just mentioning it to see if you find reason to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think auto is a bit cleaner here since it is clear which tuple element type the variable will be from the rhs of the equal sign. Also, __current_value will become

const std::tuple_element_t<1, std::tuple_element_t<0, _Tup>>& __current_value = get<1>(get<0>(__tup));

which is more difficult to follow in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I agree. The only thing I stopped to think about is if somehow with the lvalue ref auto, we are possibly being less specific than we intend to be, but I definitely agree that what you have now is much cleaner.

I'm good with how you have it, I think.

Copy link
Contributor

@danhoeflinger danhoeflinger left a comment

Choose a reason for hiding this comment

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

LGTM, Good catch. If you want to make a tuple_element change, I'll re-approve then.

@mmichel11 mmichel11 merged commit 07dfb58 into main Jan 3, 2025
22 checks passed
@mmichel11 mmichel11 deleted the dev/mmichel11/hotfix_reduce_by_segment branch January 3, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants