|
| 1 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 2 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out |
| 3 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 4 | +// |
| 5 | +// UNSUPPORTED: cuda || hip |
| 6 | + |
| 7 | +#include <sycl/sycl.hpp> |
| 8 | +#include <vector> |
| 9 | +namespace syclex = sycl::ext::oneapi::experimental; |
| 10 | + |
| 11 | +class TestKernel; |
| 12 | + |
| 13 | +int main() { |
| 14 | + sycl::queue Q; |
| 15 | + |
| 16 | + auto SGSizes = Q.get_device().get_info<sycl::info::device::sub_group_sizes>(); |
| 17 | + if (std::find(SGSizes.begin(), SGSizes.end(), 32) == SGSizes.end()) { |
| 18 | + std::cout << "Test skipped due to missing support for sub-group size 32." |
| 19 | + << std::endl; |
| 20 | + return 0; |
| 21 | + } |
| 22 | + |
| 23 | + sycl::buffer<bool, 1> MatchBuf{sycl::range{32}}; |
| 24 | + sycl::buffer<bool, 1> LeaderBuf{sycl::range{32}}; |
| 25 | + |
| 26 | + const auto NDR = sycl::nd_range<1>{32, 32}; |
| 27 | + Q.submit([&](sycl::handler &CGH) { |
| 28 | + sycl::accessor MatchAcc{MatchBuf, CGH, sycl::write_only}; |
| 29 | + sycl::accessor LeaderAcc{LeaderBuf, CGH, sycl::write_only}; |
| 30 | + const auto KernelFunc = |
| 31 | + [=](sycl::nd_item<1> item) [[sycl::reqd_sub_group_size(32)]] { |
| 32 | + auto WI = item.get_global_id(); |
| 33 | + auto SG = item.get_sub_group(); |
| 34 | + |
| 35 | + // Split into odd and even work-items via control flow |
| 36 | + // Branches deliberately duplicated to test impact of optimizations |
| 37 | + if (item.get_global_id() % 2 == 0) { |
| 38 | + auto TangleGroup = syclex::get_tangle_group(SG); |
| 39 | + |
| 40 | + bool Match = true; |
| 41 | + Match &= (TangleGroup.get_group_id() == 0); |
| 42 | + Match &= (TangleGroup.get_local_id() == SG.get_local_id() / 2); |
| 43 | + Match &= (TangleGroup.get_group_range() == 1); |
| 44 | + Match &= (TangleGroup.get_local_range() == 16); |
| 45 | + MatchAcc[WI] = Match; |
| 46 | + LeaderAcc[WI] = TangleGroup.leader(); |
| 47 | + } else { |
| 48 | + auto TangleGroup = syclex::get_tangle_group(SG); |
| 49 | + |
| 50 | + bool Match = true; |
| 51 | + Match &= (TangleGroup.get_group_id() == 0); |
| 52 | + Match &= (TangleGroup.get_local_id() == SG.get_local_id() / 2); |
| 53 | + Match &= (TangleGroup.get_group_range() == 1); |
| 54 | + Match &= (TangleGroup.get_local_range() == 16); |
| 55 | + MatchAcc[WI] = Match; |
| 56 | + LeaderAcc[WI] = TangleGroup.leader(); |
| 57 | + } |
| 58 | + }; |
| 59 | + CGH.parallel_for<TestKernel>(NDR, KernelFunc); |
| 60 | + }); |
| 61 | + |
| 62 | + sycl::host_accessor MatchAcc{MatchBuf, sycl::read_only}; |
| 63 | + sycl::host_accessor LeaderAcc{LeaderBuf, sycl::read_only}; |
| 64 | + for (int WI = 0; WI < 32; ++WI) { |
| 65 | + assert(MatchAcc[WI] == true); |
| 66 | + assert(LeaderAcc[WI] == (WI < 2)); |
| 67 | + } |
| 68 | + return 0; |
| 69 | +} |
0 commit comments