Skip to content

Commit 1df7b59

Browse files
authored
[SYCL] Incorrect diagnostic for __spirv calls (#6058)
When the reqd_sub_group_size attribute is applied on a sycl kernel, we check that SYCL_EXTERNAL functions called from such kernels also have the same sub_group_size. This need not be enforced on __spirv intrinsics since they are mapped tp the equivalent SPIR-V operations.
1 parent 9677b9f commit 1df7b59

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,6 +3719,12 @@ static void CheckSYCL2020SubGroupSizes(Sema &S, FunctionDecl *SYCLKernel,
37193719
CalcEffectiveSubGroup(S.Context, S.getLangOpts(), FD))
37203720
return;
37213721

3722+
// No need to validate __spirv routines here since they
3723+
// are mapped to the equivalent SPIRV operations.
3724+
const IdentifierInfo *II = FD->getIdentifier();
3725+
if (II && II->getName().startswith("__spirv_"))
3726+
return;
3727+
37223728
// Else we need to figure out why they don't match.
37233729
SourceLocation FDAttrLoc = GetSubGroupLoc(FD);
37243730
SourceLocation KernelAttrLoc = GetSubGroupLoc(SYCLKernel);

clang/test/CodeGenSYCL/Inputs/sycl.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
extern "C" int printf(const char* fmt, ...);
66

7+
#ifdef __SYCL_DEVICE_ONLY__
8+
__attribute__((convergent)) extern SYCL_EXTERNAL void
9+
__spirv_ControlBarrier(int, int, int) noexcept;
10+
#endif
11+
712
// Dummy runtime classes to model SYCL API.
813
inline namespace cl {
914
namespace sycl {
@@ -399,10 +404,19 @@ kernel_parallel_for(const KernelType &KernelFunc) {
399404
KernelFunc(id<Dims>());
400405
}
401406

407+
// Dummy parallel_for_work_item function to mimic calls from
408+
// parallel_for_work_group.
409+
void parallel_for_work_item() {
410+
#ifdef __SYCL_DEVICE_ONLY__
411+
__spirv_ControlBarrier(0, 0, 0);
412+
#endif
413+
}
414+
402415
template <typename KernelName, typename KernelType, int Dims>
403416
ATTR_SYCL_KERNEL void
404417
kernel_parallel_for_work_group(const KernelType &KernelFunc) {
405418
KernelFunc(group<Dims>());
419+
parallel_for_work_item();
406420
}
407421

408422
class handler {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -internal-isystem %S/Inputs -fdeclare-spirv-builtins %s -emit-llvm -o - | FileCheck %s
2+
3+
// Test that when __spirv intrinsics are invoked from kernel functions
4+
// that have a sub_group_size specified, that such invocations don't
5+
// trigger the error diagnostic that the intrinsic routines must also
6+
// marked with the same attribute.
7+
8+
#include "Inputs/sycl.hpp"
9+
10+
int main() {
11+
sycl::queue q;
12+
13+
q.submit([&](sycl::handler &cgh) {
14+
auto kernel_ = [=](sycl::group<1> item) [[intel::sub_group_size(8)]] {
15+
};
16+
17+
cgh.parallel_for_work_group<class kernel_class>(
18+
cl::sycl::range<1>(), cl::sycl::range<1>(), kernel_);
19+
});
20+
return 0;
21+
}
22+
23+
// CHECK: define dso_local spir_kernel void @{{.*}}main{{.*}}kernel_class() {{.*}} !intel_reqd_sub_group_size ![[SUBGROUPSIZE:[0-9]+]]
24+
// CHECK: tail call spir_func void @{{.*}}__spirv_ControlBarrier{{.*}}({{.*}})
25+
26+
// CHECK: declare spir_func void @{{.*}}__spirv_ControlBarrier{{.*}}({{.*}})
27+
28+
// CHECK: ![[SUBGROUPSIZE]] = !{i32 8}

0 commit comments

Comments
 (0)