Skip to content
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

[SYCL] Warn when number of kernel args exceeds maximum available on GPU #2361

Merged
merged 11 commits into from
Sep 2, 2020
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10990,6 +10990,9 @@ def err_sycl_restrict : Error<
"|use a const static or global variable that is neither zero-initialized "
"nor constant-initialized"
"}0">;
def warn_sycl_kernel_too_many_args : Warning<
"resulting number of kernel arguments %0 is greater than maximum supported "
"on GPU device - %1">;
def err_sycl_virtual_types : Error<
"No class with a vtable can be used in a SYCL kernel or any code included in the kernel">;
def note_sycl_recursive_function_declared_here: Note<"function implemented using recursion declared here">;
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum KernelInvocationKind {

const static std::string InitMethodName = "__init";
const static std::string FinalizeMethodName = "__finalize";
const static unsigned GPUMaxKernelArgsNum = 2000;
Fznamznon marked this conversation as resolved.
Show resolved Hide resolved

namespace {

Expand Down Expand Up @@ -1487,6 +1488,14 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
std::back_inserter(ArgTys),
[](const ParmVarDecl *PVD) { return PVD->getType(); });

// TODO: enable template instantiation tree for this diagnostic
Fznamznon marked this conversation as resolved.
Show resolved Hide resolved
if (SemaRef.Context.getTargetInfo().getTriple().getSubArch() ==
llvm::Triple::SPIRSubArch_gen)
if (Params.size() > GPUMaxKernelArgsNum)
SemaRef.Diag(KernelDecl->getLocation(),
diag::warn_sycl_kernel_too_many_args)
<< static_cast<unsigned>(Params.size()) << GPUMaxKernelArgsNum;

QualType FuncType = Ctx.getFunctionType(Ctx.VoidTy, ArgTys, Info);
KernelDecl->setType(FuncType);
KernelDecl->setParams(Params);
Expand Down
17 changes: 17 additions & 0 deletions clang/test/SemaSYCL/num-args-overflow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang_cc1 -fsycl -triple spir64_gen -DGPU -fsycl-is-device -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsycl -triple spir64 -fsycl-is-device -fsyntax-only -verify %s

template <typename Name, typename F>
__attribute__((sycl_kernel)) void kernel(F kernelFunc) {
kernelFunc();
}

void use() {
int Arr[2001];
#ifdef GPU
// expected-warning@+4 {{resulting number of kernel arguments 2001 is greater than maximum supported on GPU device - 2000}}
#else
// expected-no-diagnostics
#endif
kernel<class Foo>([=]() { (void)Arr[0]; });
}