Skip to content

[SYCL] Disallow sycl_kernel attribute on host #4618

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

Merged
merged 3 commits into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ def SYCLGlobalVar : InheritableAttr {
def SYCLKernel : InheritableAttr {
let Spellings = [Clang<"sycl_kernel">];
let Subjects = SubjectList<[FunctionTmpl]>;
let LangOpts = [SYCLIsHost, SYCLIsDevice];
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let Documentation = [SYCLKernelDocs];
}

Expand Down
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
if (D && D->hasAttr<NoProfileFunctionAttr>())
Fn->addFnAttr(llvm::Attribute::NoProfile);

if (getLangOpts().SYCLIsHost && D && D->hasAttr<SYCLKernelAttr>())
Fn->addFnAttr("sycl_kernel");

if (getLangOpts().SYCLIsDevice && D) {
if (const auto *A = D->getAttr<SYCLIntelLoopFuseAttr>()) {
const auto *CE = cast<ConstantExpr>(A->getValue());
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9315,7 +9315,7 @@ static void handleSYCLKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
// Function template must have at least two template parameters so it
// can be used in OpenCL kernel generation.
const TemplateParameterList *TL = FT->getTemplateParameters();
if (S.LangOpts.SYCLIsDevice && TL->size() < 2) {
if (TL->size() < 2) {
S.Diag(FT->getLocation(), diag::warn_sycl_kernel_num_of_template_params);
return;
}
Expand Down
25 changes: 2 additions & 23 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6583,27 +6583,6 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
return D;
}

static void processSYCLKernel(Sema &S, FunctionDecl *FD, MangleContext &MC) {
if (S.LangOpts.SYCLIsDevice) {
S.ConstructOpenCLKernel(FD, MC);
} else if (S.LangOpts.SYCLIsHost) {
QualType KernelParamTy = (*FD->param_begin())->getType();
const CXXRecordDecl *CRD = (KernelParamTy->isReferenceType()
? KernelParamTy->getPointeeCXXRecordDecl()
: KernelParamTy->getAsCXXRecordDecl());
if (!CRD) {
S.Diag(FD->getLocation(), diag::err_sycl_kernel_not_function_object);
FD->setInvalidDecl();
return;
}

for (auto *Method : CRD->methods())
if (Method->getOverloadedOperator() == OO_Call &&
!Method->hasAttr<AlwaysInlineAttr>())
Method->addAttr(AlwaysInlineAttr::CreateImplicit(S.getASTContext()));
}
}

static void processFunctionInstantiation(Sema &S,
SourceLocation PointOfInstantiation,
FunctionDecl *FD,
Expand All @@ -6613,8 +6592,8 @@ static void processFunctionInstantiation(Sema &S,
DefinitionRequired, true);
if (!FD->isDefined())
return;
if (FD->hasAttr<SYCLKernelAttr>())
processSYCLKernel(S, FD, MC);
if (S.LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelAttr>())
S.ConstructOpenCLKernel(FD, MC);
FD->setInstantiationIsPending(false);
}

Expand Down
44 changes: 0 additions & 44 deletions clang/test/CodeGenSYCL/sycl_kernel-host.cpp

This file was deleted.

24 changes: 5 additions & 19 deletions clang/test/SemaSYCL/kernel-attribute.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
// RUN: %clang_cc1 -fsycl-is-host -DHOST -fsyntax-only -verify %s

#ifndef HOST
// Only function templates
[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
__attribute__((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
Expand All @@ -14,13 +15,11 @@ __attribute__((sycl_kernel(1))) void foo(T P); // expected-error {{'sycl_kernel'
template <typename T, typename A, int I>
[[clang::sycl_kernel(1)]] void foo1(T P);// expected-error {{'sycl_kernel' attribute takes no arguments}}

#ifndef HOST
// At least two template parameters
template <typename T>
__attribute__((sycl_kernel)) void foo(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
template <typename T>
[[clang::sycl_kernel]] void foo1(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
#endif

// First two template parameters cannot be non-type template parameters
template <typename T, int A>
Expand All @@ -46,22 +45,9 @@ __attribute__((sycl_kernel)) void foo(T P);
template <typename T, typename A, int I>
[[clang::sycl_kernel]] void foo1(T P);

#ifdef HOST
// No diagnostics
template <typename Func>
void __attribute__((sycl_kernel))
KernelImpl4(const Func &f, int i, double d) {
f(i, d);
}
#else

template <typename Name, typename Func>
void __attribute__((sycl_kernel))
Kernel(const Func &f) {
KernelImpl4(f, 1, 2.0);
}

void func() {
auto Lambda = [](int i, double d) { d += i; };
Kernel<class Foo>(Lambda);
}
// expected-no-diagnostics
template <typename T, typename A>
__attribute__((sycl_kernel)) void foo(T P);
#endif