Skip to content

Commit 9263931

Browse files
committed
[SYCL] Assume SYCL device functions are convergent
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. Reviewed By: Naghasan Differential Revision: https://reviews.llvm.org/D87282
1 parent c5a4900 commit 9263931

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
@@ -2882,7 +2882,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
28822882
Opts.Coroutines = Opts.CPlusPlus20 || Args.hasArg(OPT_fcoroutines_ts);
28832883

28842884
Opts.ConvergentFunctions = Opts.OpenCL || (Opts.CUDA && Opts.CUDAIsDevice) ||
2885-
Args.hasArg(OPT_fconvergent_functions);
2885+
Opts.SYCLIsDevice ||
2886+
Args.hasArg(OPT_fconvergent_functions);
28862887

28872888
Opts.DoubleSquareBracketAttributes =
28882889
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)