-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Added a new test case for sub-group attributes #537
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// RUN: %clangxx -fsycl %s -o %t.out | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUNx: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
//==------- attributes.cpp - SYCL sub_group attributes test ----*- C++ -*---==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "helper.hpp" | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
#define KERNEL_FUNCTOR_WITH_SIZE(SIZE) \ | ||
class KernelFunctor##SIZE { \ | ||
public: \ | ||
[[cl::intel_reqd_sub_group_size(SIZE)]] void \ | ||
operator()(cl::sycl::nd_item<1> Item) { \ | ||
const auto GID = Item.get_global_id(); \ | ||
} \ | ||
}; | ||
|
||
KERNEL_FUNCTOR_WITH_SIZE(1); | ||
KERNEL_FUNCTOR_WITH_SIZE(2); | ||
KERNEL_FUNCTOR_WITH_SIZE(4); | ||
KERNEL_FUNCTOR_WITH_SIZE(8); | ||
KERNEL_FUNCTOR_WITH_SIZE(16); | ||
|
||
#undef KERNEL_FUNCTOR_WITH_SIZE | ||
|
||
inline uint32_t flp2(uint32_t X) { | ||
X = X | (X >> 1); | ||
X = X | (X >> 2); | ||
X = X | (X >> 4); | ||
X = X | (X >> 8); | ||
X = X | (X >> 16); | ||
return X - (X >> 1); | ||
} | ||
|
||
template <typename Fn> inline void submit(cl::sycl::queue &Q) { | ||
Q.submit([](cl::sycl::handler &cgh) { | ||
Fn F; | ||
cgh.parallel_for(cl::sycl::nd_range<1>{64, 16}, F); | ||
}); | ||
} | ||
|
||
int main() { | ||
queue Queue; | ||
device Device = Queue.get_device(); | ||
|
||
// According to specification, this kernel query requires `cl_khr_subgroups` | ||
// or `cl_intel_subgroups`, and also `cl_intel_required_subgroup_size` | ||
if ((!Device.has_extension("cl_intel_subgroups") && | ||
!Device.has_extension("cl_khr_subgroups")) || | ||
!Device.has_extension("cl_intel_required_subgroup_size")) { | ||
std::cout << "Skipping test\n"; | ||
return 0; | ||
} | ||
|
||
try { | ||
const auto SGSizes = Device.get_info<info::device::sub_group_sizes>(); | ||
|
||
for (const auto SGSize : SGSizes) { | ||
// Get the previous power of 2 | ||
auto ReqdSize = flp2(SGSize); | ||
|
||
cl::sycl::program Prog(Queue.get_context()); | ||
|
||
// Store the `cl::sycl::kernel` into a vector because `cl::sycl::kernel` | ||
// doesn't have default constructor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the comment. |
||
cl::sycl::vector_class<cl::sycl::kernel> TheKernel; | ||
|
||
switch (ReqdSize) { | ||
case 16: | ||
Prog.build_with_kernel_type<KernelFunctor16>(); | ||
TheKernel.push_back(Prog.get_kernel<KernelFunctor16>()); | ||
submit<KernelFunctor16>(Queue); | ||
break; | ||
case 8: | ||
Prog.build_with_kernel_type<KernelFunctor8>(); | ||
TheKernel.push_back(Prog.get_kernel<KernelFunctor8>()); | ||
submit<KernelFunctor8>(Queue); | ||
break; | ||
case 4: | ||
Prog.build_with_kernel_type<KernelFunctor4>(); | ||
TheKernel.push_back(Prog.get_kernel<KernelFunctor4>()); | ||
submit<KernelFunctor4>(Queue); | ||
break; | ||
case 2: | ||
Prog.build_with_kernel_type<KernelFunctor2>(); | ||
TheKernel.push_back(Prog.get_kernel<KernelFunctor2>()); | ||
submit<KernelFunctor2>(Queue); | ||
break; | ||
case 1: | ||
Prog.build_with_kernel_type<KernelFunctor1>(); | ||
TheKernel.push_back(Prog.get_kernel<KernelFunctor1>()); | ||
submit<KernelFunctor1>(Queue); | ||
break; | ||
default: | ||
throw feature_not_supported("sub-group size is not supported"); | ||
} | ||
|
||
auto Kernel = TheKernel[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see... You are emulating a C++17 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure whether it makes sense to request it. :) |
||
|
||
auto Res = Kernel.get_sub_group_info< | ||
cl::sycl::info::kernel_sub_group::compile_sub_group_size>(Device); | ||
|
||
exit_if_not_equal<size_t>(Res, ReqdSize, "compile_sub_group_size"); | ||
} | ||
} catch (exception e) { | ||
std::cout << "SYCL exception caught: " << e.what(); | ||
return 1; | ||
} | ||
|
||
std::cout << "Test passed.\n"; | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this test looks good. I have only one concern that it might not work properly on any OpenCL RT with sub-groups support.
The problem is that all kernel functions described here are going to be included into a one device program which will be compiled later by a device compiler - and this might cause errors because apparently device doesn't have to support all sub-group sizes listed in here and it is legal to fail compilation if requested sub-group size is not supported.
Probably it is a bug in our implementation, that
build_with_kernel_type
actually performs build of all kernels instead of just one, but I don't know SYCL spec so good to say for sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remembered there's a ticket created by Evgeniy describing the issue of building all kernels.