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

[SYCL] Add support for key/value sorting APIs #13942

Merged
merged 8 commits into from
Jun 12, 2024

Conversation

againull
Copy link
Contributor

@againull againull commented May 28, 2024

Add group_key_value_sorter sorters and sort_key_value_over_group APIs based on https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_group_sort.asciidoc extension.

This PR was split out from larger PR: #13713

Co-authored-by: "Andrei Fedorov andrey.fedorov@intel.com"
Co-authored-by: "Romanov Vlad vlad.romanov@intel.com"

range_size, comp,
aligned_scratch_ptr + range_size * sizeof(T));
val = *local_copy;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add something like assert(false && "Scratch size less than value results in UB") in the else part? It will be helpful in debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately native assert is not supported by all devices and I believe fallback assert can add overhead (as it creates assert buffer and copies it back) and I'm not sure if it is reliable enough to use it in default execution path. That's why I didn't put assert here.

@againull
Copy link
Contributor Author

againull commented Jun 4, 2024

Tag @andreyfe1

: comp(comp_), scratch(scratch_) {}

template <typename Group>
T operator()([[maybe_unused]] Group g, [[maybe_unused]] T val) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it planned to add another operator(): void operator()(Group g, sycl::span<T, ElementsPerWorkItem> values, Properties properties); ?
The same for group_key_value_sorter and radix_sorters

Copy link
Contributor Author

@againull againull Jun 10, 2024

Choose a reason for hiding this comment

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

I didn't add them on purpose to split functionality into several PRs. Do you think it is better to create a single PR with all functionality?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I needed to make sure that it's not forgotten. I'm fine if it's covered in a separate PR

@againull againull marked this pull request as draft June 10, 2024 17:04
@againull againull marked this pull request as ready for review June 10, 2024 18:03
@againull
Copy link
Contributor Author

@uditagarwal97 @aelovikov-intel This PR was rebased on top of the latest changes and is ready for review.

Comment on lines 364 to 365
auto this_comp = this->comp;
auto comp_key_value = [this_comp](const KeyValue &lhs,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto this_comp = this->comp;
auto comp_key_value = [this_comp](const KeyValue &lhs,
auto comp_key_value = [this_comp = this->comp](const KeyValue &lhs,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -343,6 +343,41 @@ class group_sorter {
}
};

template <typename T, typename U, typename CompareT = std::less<>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename T/U to KeyTy/ValueTy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

Comment on lines 76 to 79
typename std::is_same<std::tuple<Key, Value>,
decltype(std::declval<Sorter>()(
std::declval<G>(), std::declval<Key>(),
std::declval<Value>()))>;
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 std::invoke_result_t would allow to simplify this a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, simplified.

g, KeyValue(key, value));
}

static constexpr std::size_t memory_required(sycl::memory_scope scope,
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the spec memory_required is not constexpr for default_sorters. Please, make corresponding changes for all default sorters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed.

@@ -343,6 +343,41 @@ class group_sorter {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is regarding https://github.com/intel/llvm/blob/sycl/sycl/include/sycl/ext/oneapi/experimental/group_helpers_sorters.hpp#L252

It's expected for joint_sorter (default and radix sorters both) to support oneDPL zip_iterator (https://github.com/intel/llvm/blob/sycl/sycl/include/sycl/ext/oneapi/experimental/group_helpers_sorters.hpp#L252 : Example 3).
Do you plan to add this support (no matter in this PR or a separate one)?

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 will look into this but not as part of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok. Thanks

@againull againull merged commit 3910d0c into intel:sycl Jun 12, 2024
14 checks passed
ianayl pushed a commit to ianayl/sycl that referenced this pull request Jun 13, 2024
Add group_key_value_sorter sorters and sort_key_value_over_group APIs
based on
https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_group_sort.asciidoc
extension.

This PR was split out from larger PR:
intel#13713

Co-authored-by: "Andrei Fedorov
[andrey.fedorov@intel.com](mailto:andrey.fedorov@intel.com)"
Co-authored-by: "Romanov Vlad
[vlad.romanov@intel.com](mailto:vlad.romanov@intel.com)"
@againull againull deleted the feature/key_value_scalar branch July 9, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants