Skip to content

Commit f257098

Browse files
authored
[SYCLomatic] Emit warning for dynamic parallelism (#2251)
Signed-off-by: Jiang, Zhiwei <[email protected]>
1 parent 41bd229 commit f257098

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8407,6 +8407,12 @@ void KernelCallRule::runRule(
84078407
auto FD = getAssistNodeAsType<FunctionDecl>(Result, "callContext");
84088408
if (!FD)
84098409
return;
8410+
if (FD->hasAttr<CUDAGlobalAttr>()) {
8411+
report(KCall->getBeginLoc(), Diagnostics::NOT_SUPPORT_DYN_PARALLEL,
8412+
false);
8413+
return;
8414+
}
8415+
84108416
const auto &SM = (*Result.Context).getSourceManager();
84118417

84128418
if (SM.isMacroArgExpansion(KCall->getCallee()->getBeginLoc())) {

clang/lib/DPCT/Diagnostics.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ DEF_WARNING(NOT_DEVICE_COPYABLE, 1128, MEDIUM_LEVEL, "The type \"%0\" is not dev
286286
DEF_COMMENT(NOT_DEVICE_COPYABLE, 1128, MEDIUM_LEVEL, "The type \"{0}\" is not device copyable for {1}. It is used in the SYCL kernel, please rewrite the code.")
287287
DEF_WARNING(NOT_DEVICE_COPYABLE_ADD_SPECIALIZATION, 1129, MEDIUM_LEVEL, "The type \"%0\" is used in the SYCL kernel, but it is not device copyable. The sycl::is_device_copyable specialization has been added for this type. Please review the code.")
288288
DEF_COMMENT(NOT_DEVICE_COPYABLE_ADD_SPECIALIZATION, 1129, MEDIUM_LEVEL, "The type \"{0}\" is used in the SYCL kernel, but it is not device copyable. The sycl::is_device_copyable specialization has been added for this type. Please review the code.")
289+
DEF_WARNING(NOT_SUPPORT_DYN_PARALLEL, 1130, HIGH_LEVEL, "SYCL 2020 standard does not support dynamic parallelism (launching kernel in device code). Please rewrite the code.")
290+
DEF_COMMENT(NOT_SUPPORT_DYN_PARALLEL, 1130, HIGH_LEVEL, "SYCL 2020 standard does not support dynamic parallelism (launching kernel in device code). Please rewrite the code.")
289291
// clang-format on
290292

291293
#undef DEF_COMMENT

clang/test/dpct/nestedqueue.cu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,19 @@ __host__ void foo4(){
7474
cublasIsamax(handle, n, x_S, incx, result);
7575
}
7676

77+
__global__ void childKernel() {}
78+
__global__ void parentKernel() {
79+
// CHECK: /*
80+
// CHECK-NEXT: DPCT1130:{{[0-9]+}}: SYCL 2020 standard does not support dynamic parallelism (launching kernel in device code). Please rewrite the code.
81+
// CHECK-NEXT: */
82+
// CHECK-NEXT: childKernel<<<1, 1>>>();
83+
childKernel<<<1, 1>>>();
84+
}
85+
void foo5() {
86+
// CHECK: dpct::get_out_of_order_queue().parallel_for(
87+
// CHECK-NEXT: sycl::nd_range<3>(sycl::range<3>(1, 1, 1), sycl::range<3>(1, 1, 1)),
88+
// CHECK-NEXT: [=](sycl::nd_item<3> item_ct1) {
89+
// CHECK-NEXT: parentKernel();
90+
// CHECK-NEXT: });
91+
parentKernel<<<1, 1>>>();
92+
}

0 commit comments

Comments
 (0)