|
| 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 | +} |
0 commit comments