Skip to content

[SYCL] Fix use_root_sync handling #17739

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

Merged
merged 6 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ class __SYCL_EXPORT handler {

constexpr bool UsesRootSync = PropertiesT::template has_property<
sycl::ext::oneapi::experimental::use_root_sync_key>();
setKernelIsCooperative(UsesRootSync);
if (UsesRootSync) {
setKernelIsCooperative(UsesRootSync);
}
if constexpr (PropertiesT::template has_property<
sycl::ext::oneapi::experimental::
work_group_progress_key>()) {
Expand Down
54 changes: 30 additions & 24 deletions sycl/test-e2e/GroupAlgorithm/root_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// XFAIL: (opencl && !cpu && !accelerator)
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/14641

// TODO: Currently using the -Wno-deprecated-declarations flag due to issue
// https://github.com/intel/llvm/issues/16451. Rewrite testRootGroup() amd
// remove the flag once the issue is resolved.
// RUN: %{build} -I . -o %t.out -Wno-deprecated-declarations %if target-nvidia %{ -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_70 %}
// RUN: %{build} -I . -o %t.out %if target-nvidia %{ -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_70 %}
// RUN: %{run} %t.out

// Disabled temporarily while investigation into the failure is ongoing.
Expand Down Expand Up @@ -63,6 +60,34 @@ void testQueriesAndProperties() {
check_max_num_work_group_sync(maxWGsWithLimits);
}

template <typename T> struct TestKernel1 {
T m_data;
TestKernel1(T &data_) : m_data(data_) {}
void operator()(sycl::nd_item<1> it) const {
volatile float X = 1.0f;
volatile float Y = 1.0f;
auto root = it.ext_oneapi_get_root_group();
m_data[root.get_local_id()] = root.get_local_id();
sycl::group_barrier(root);
// Delay half of the workgroups with extra work to check that the barrier
// synchronizes the whole device.
if (it.get_group(0) % 2 == 0) {
X += sycl::sin(X);
Y += sycl::cos(Y);
}
root = sycl::ext::oneapi::experimental::this_work_item::get_root_group<1>();
int sum = m_data[root.get_local_id()] +
m_data[root.get_local_range() - root.get_local_id() - 1];
sycl::group_barrier(root);
m_data[root.get_local_id()] = sum;
}
auto get(sycl::ext::oneapi::experimental::properties_tag) const {
return sycl::ext::oneapi::experimental::properties{
sycl::ext::oneapi::experimental::use_root_sync};
;
}
};

void testRootGroup() {
sycl::queue q;
const auto bundle =
Expand All @@ -79,26 +104,7 @@ void testRootGroup() {
const auto range = sycl::nd_range<1>{maxWGs * WorkGroupSize, WorkGroupSize};
q.submit([&](sycl::handler &h) {
sycl::accessor data{dataBuf, h};
h.parallel_for<
class RootGroupKernel>(range, props, [=](sycl::nd_item<1> it) {
volatile float X = 1.0f;
volatile float Y = 1.0f;
auto root = it.ext_oneapi_get_root_group();
data[root.get_local_id()] = root.get_local_id();
sycl::group_barrier(root);
// Delay half of the workgroups with extra work to check that the barrier
// synchronizes the whole device.
if (it.get_group(0) % 2 == 0) {
X += sycl::sin(X);
Y += sycl::cos(Y);
}
root =
sycl::ext::oneapi::experimental::this_work_item::get_root_group<1>();
int sum = data[root.get_local_id()] +
data[root.get_local_range() - root.get_local_id() - 1];
sycl::group_barrier(root);
data[root.get_local_id()] = sum;
});
h.parallel_for<class RootGroupKernel>(range, TestKernel1(data));
});
sycl::host_accessor data{dataBuf};
const int workItemCount = static_cast<int>(range.get_global_range().size());
Expand Down