Skip to content

Commit 047e2ec

Browse files
authored
[SYCL] Assume SYCL device functions are convergent (#2367)
SYCL device compiler (similar to other SPMD compilers) assumes that functions are convergent by default to avoid invalid transformations. This attribute can be removed if compiler can prove that function does not have convergent operations.
1 parent f257378 commit 047e2ec

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2893,7 +2893,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
28932893
Opts.Coroutines = Opts.CPlusPlus20 || Args.hasArg(OPT_fcoroutines_ts);
28942894

28952895
Opts.ConvergentFunctions = Opts.OpenCL || (Opts.CUDA && Opts.CUDAIsDevice) ||
2896-
Args.hasArg(OPT_fconvergent_functions);
2896+
Opts.SYCLIsDevice ||
2897+
Args.hasArg(OPT_fconvergent_functions);
28972898

28982899
Opts.DoubleSquareBracketAttributes =
28992900
Args.hasFlag(OPT_fdouble_square_bracket_attributes,

clang/test/CodeGenSYCL/convergent.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -emit-llvm -disable-llvm-passes \
2+
// RUN: -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | \
3+
// RUN: FileCheck %s
4+
5+
// CHECK-DAG: Function Attrs:
6+
// CHECK-DAG-SAME: convergent
7+
// CHECK-DAG-NEXT: define void @_Z3foov
8+
void foo() {
9+
int a = 1;
10+
}
11+
12+
template <typename Name, typename Func>
13+
__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
14+
kernelFunc();
15+
}
16+
17+
int main() {
18+
kernel_single_task<class fake_kernel>([]() { foo(); });
19+
return 0;
20+
}

0 commit comments

Comments
 (0)