Skip to content

Commit fda7dc7

Browse files
authored
[SYCL][ESIMD] Support root group barriers (#15585)
The required driver isn't available in CI yet, but I manually verified it. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 5750eaf commit fda7dc7

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

llvm/lib/SYCLLowerIR/ESIMD/ESIMDVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static const char *LegalSYCLFunctions[] = {
5353
"^sycl::_V1::multi_ptr<.+>::.+",
5454
"^sycl::_V1::nd_item<.+>::.+",
5555
"^sycl::_V1::group<.+>::.+",
56+
"^sycl::_V1::group_barrier<.+>",
5657
"^sycl::_V1::sub_group::.+",
5758
"^sycl::_V1::range<.+>::.+",
5859
"^sycl::_V1::kernel_handler::.+",
@@ -64,9 +65,12 @@ static const char *LegalSYCLFunctions[] = {
6465
"^sycl::_V1::operator.+<.+>",
6566
"^sycl::_V1::ext::oneapi::experimental::properties",
6667
"^sycl::_V1::ext::oneapi::experimental::detail::ExtractProperties",
68+
"^sycl::_V1::ext::oneapi::experimental::root_group<.+>::.+",
69+
"^sycl::_V1::ext::oneapi::experimental::this_group<.+>",
6770
"^sycl::_V1::ext::oneapi::sub_group::.+",
6871
"^sycl::_V1::ext::oneapi::experimental::spec_constant<.+>::.+",
6972
"^sycl::_V1::ext::oneapi::experimental::this_sub_group",
73+
"^sycl::_V1::ext::oneapi::experimental::this_work_item::get_root_group<.+>",
7074
"^sycl::_V1::ext::oneapi::experimental::uniform<.+>::.+",
7175
"^sycl::_V1::ext::oneapi::bfloat16::.+",
7276
"^sycl::_V1::ext::oneapi::experimental::if_architecture_is"};

sycl/test-e2e/ESIMD/group_barrier.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//==----- group_barrier.cpp - ESIMD root group barrier test -----==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------===//
8+
// REQUIRES: arch-intel_gpu_pvc || gpu-intel-dg2
9+
// REQUIRES-INTEL-DRIVER: lin: 30751
10+
11+
// RUN: %{build} -o %t.out
12+
// RUN: %{run} %t.out
13+
14+
#include "esimd_test_utils.hpp"
15+
#include <sycl/ext/oneapi/experimental/root_group.hpp>
16+
#include <sycl/group_barrier.hpp>
17+
18+
static constexpr int WorkGroupSize = 16;
19+
20+
static constexpr int VL = 16;
21+
int main() {
22+
bool Pass = true;
23+
sycl::queue q;
24+
esimd_test::printTestLabel(q);
25+
const auto MaxWGs = 8;
26+
size_t WorkItemCount = MaxWGs * WorkGroupSize * VL;
27+
28+
const auto Props = sycl::ext::oneapi::experimental::properties{
29+
sycl::ext::oneapi::experimental::use_root_sync};
30+
sycl::buffer<int> DataBuf{sycl::range{WorkItemCount}};
31+
const auto Range = sycl::nd_range<1>{MaxWGs * WorkGroupSize, WorkGroupSize};
32+
q.submit([&](sycl::handler &h) {
33+
sycl::accessor Data{DataBuf, h};
34+
h.parallel_for(Range, Props, [=](sycl::nd_item<1> it) SYCL_ESIMD_KERNEL {
35+
int ID = it.get_global_linear_id();
36+
__ESIMD_NS::simd<int, VL> V(ID, 1);
37+
// Write data to another kernel's data to verify the barrier works.
38+
__ESIMD_NS::block_store(
39+
Data, (WorkItemCount * sizeof(int)) - (ID * sizeof(int) * VL), V);
40+
if (ID % 2 == 1) {
41+
auto Root = it.ext_oneapi_get_root_group();
42+
sycl::group_barrier(Root);
43+
} else {
44+
auto Root =
45+
sycl::ext::oneapi::experimental::this_work_item::get_root_group<
46+
1>();
47+
sycl::group_barrier(Root);
48+
}
49+
__ESIMD_NS::simd<int, VL> VOther(ID * VL, 1);
50+
__ESIMD_NS::block_store(Data, ID * sizeof(int) * VL, VOther);
51+
});
52+
}).wait();
53+
sycl::host_accessor Data{DataBuf};
54+
int ErrCnt = 0;
55+
for (int I = 0; I < WorkItemCount; I++) {
56+
if (Data[I] != I) {
57+
Pass = false;
58+
if (++ErrCnt < 16)
59+
std::cout << "Data[" << std::to_string(I)
60+
<< "] != " << std::to_string(I) << "\n";
61+
}
62+
}
63+
if (Pass)
64+
std::cout << "Passed\n";
65+
else
66+
std::cout << "Failed\n";
67+
return !Pass;
68+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clangxx -fsycl -c -fsycl-device-only -Xclang -emit-llvm %s -o - | FileCheck %s
2+
3+
#include <sycl/ext/intel/esimd.hpp>
4+
#include <sycl/ext/oneapi/experimental/root_group.hpp>
5+
#include <sycl/group_barrier.hpp>
6+
#include <sycl/sycl.hpp>
7+
8+
using namespace sycl;
9+
using namespace sycl::ext::intel::esimd;
10+
11+
SYCL_ESIMD_FUNCTION SYCL_EXTERNAL void
12+
func(sycl::ext::oneapi::experimental::root_group<1> &rg) {
13+
// CHECK: call spir_func void @_Z22__spirv_ControlBarrier{{.*}}(i32 noundef 1, i32 noundef 1, i32 noundef 912)
14+
sycl::group_barrier(rg);
15+
}

0 commit comments

Comments
 (0)