-
Notifications
You must be signed in to change notification settings - Fork 743
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] Support or diagnose use of namespace std types as kernel type … #1579
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1649,30 +1649,27 @@ void SYCLIntegrationHeader::emitFwdDecl(raw_ostream &O, const Decl *D, | |
auto *NS = dyn_cast_or_null<NamespaceDecl>(DC); | ||
|
||
if (!NS) { | ||
if (!DC->isTranslationUnit()) { | ||
const TagDecl *TD = isa<ClassTemplateDecl>(D) | ||
? cast<ClassTemplateDecl>(D)->getTemplatedDecl() | ||
: dyn_cast<TagDecl>(D); | ||
|
||
if (TD && !UnnamedLambdaSupport) { | ||
// defined class constituting the kernel name is not globally | ||
// accessible - contradicts the spec | ||
const bool KernelNameIsMissing = TD->getName().empty(); | ||
if (KernelNameIsMissing) { | ||
const TagDecl *TD = isa<ClassTemplateDecl>(D) | ||
? cast<ClassTemplateDecl>(D)->getTemplatedDecl() | ||
: dyn_cast<TagDecl>(D); | ||
if (!TD) | ||
break; | ||
|
||
const bool KernelNameIsMissing = TD->getName().empty(); | ||
if (KernelNameIsMissing) | ||
Diag.Report(KernelLocation, diag::err_sycl_kernel_incorrectly_named) | ||
<< /* kernel name is missing */ 0; | ||
else if (!DC->isTranslationUnit()) { | ||
// defined class constituting the kernel name is not globally | ||
// accessible - contradicts the spec | ||
if (!UnnamedLambdaSupport) { | ||
if (TD->isCompleteDefinition()) | ||
Diag.Report(KernelLocation, diag::err_sycl_kernel_incorrectly_named) | ||
<< /* kernel name is missing */ 0; | ||
// Don't emit note if kernel name was completely omitted | ||
} else { | ||
if (TD->isCompleteDefinition()) | ||
Diag.Report(KernelLocation, | ||
diag::err_sycl_kernel_incorrectly_named) | ||
<< /* kernel name is not globally-visible */ 1; | ||
else | ||
Diag.Report(KernelLocation, diag::warn_sycl_implicit_decl); | ||
Diag.Report(D->getSourceRange().getBegin(), | ||
diag::note_previous_decl) | ||
<< TD->getName(); | ||
} | ||
<< /* kernel name is not globally-visible */ 1; | ||
else | ||
Diag.Report(KernelLocation, diag::warn_sycl_implicit_decl); | ||
Diag.Report(D->getSourceRange().getBegin(), diag::note_previous_decl) | ||
<< TD->getName(); | ||
} | ||
} | ||
break; | ||
|
@@ -1826,8 +1823,10 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) { | |
O << "// This is auto-generated SYCL integration header.\n"; | ||
O << "\n"; | ||
|
||
O << "#include <cstddef>\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need these changes to the generated header (this and the next change). Because there is no promise that std types work as lambda name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @premanandrao, could you address this comment, please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bader , @jtmott-intel is working on it. |
||
O << "#include <CL/sycl/detail/defines.hpp>\n"; | ||
O << "#include <CL/sycl/detail/kernel_desc.hpp>\n"; | ||
O << "using nullptr_t = std::nullptr_t;\n"; | ||
|
||
O << "\n"; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h %s | ||
// RUN: FileCheck -input-file=%t.h %s | ||
// | ||
// CHECK: #include <cstddef> | ||
// CHECK-NEXT: #include <CL/sycl/detail/defines.hpp> | ||
// CHECK-NEXT: #include <CL/sycl/detail/kernel_desc.hpp> | ||
// CHECK-NEXT: using nullptr_t = std::nullptr_t; | ||
// | ||
// CHECK: static constexpr | ||
// CHECK-NEXT: const char* const kernel_names[] = { | ||
// CHECK-NEXT: "_ZTSDn" | ||
// CHECK-NEXT: "_ZTSSt4byte" | ||
// CHECK-NEXT: "_ZTSm", | ||
// CHECK-NEXT: "_ZTSl" | ||
// CHECK-NEXT: }; | ||
// | ||
// CHECK: static constexpr | ||
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = { | ||
// CHECK-NEXT: //--- _ZTSDn | ||
// CHECK-EMPTY: | ||
// CHECK-NEXT: //--- _ZTSSt4byte | ||
// CHECK-EMPTY: | ||
// CHECK-NEXT: //--- _ZTSm | ||
// CHECK-EMPTY: | ||
// CHECK-NEXT: //--- _ZTSl | ||
// CHECK-EMPTY: | ||
// CHECK-NEXT: }; | ||
// | ||
// CHECK: static constexpr | ||
// CHECK-NEXT: const unsigned kernel_signature_start[] = { | ||
// CHECK-NEXT: 0, // _ZTSDn | ||
// CHECK-NEXT: 1, // _ZTSSt4byte | ||
// CHECK-NEXT: 2, // _ZTSm | ||
// CHECK-NEXT: 3 // _ZTSl | ||
// CHECK-NEXT: }; | ||
|
||
// CHECK: template <> struct KernelInfo<nullptr_t> { | ||
// CHECK: template <> struct KernelInfo<::std::byte> { | ||
// CHECK: template <> struct KernelInfo<unsigned long> { | ||
// CHECK: template <> struct KernelInfo<long> { | ||
|
||
void usage() { | ||
} | ||
|
||
namespace std { | ||
typedef long unsigned int size_t; | ||
typedef long int ptrdiff_t; | ||
typedef decltype(nullptr) nullptr_t; | ||
enum class byte : unsigned char {}; | ||
} // namespace std | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
int main() { | ||
kernel_single_task<std::nullptr_t>([]() { usage(); }); | ||
kernel_single_task<std::byte>([=]() {}); | ||
kernel_single_task<std::size_t>([=]() {}); | ||
kernel_single_task<std::ptrdiff_t>([=]() {}); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this needs to be lower-level than this, since would this work with 'int'? Or the other builtin types? I don't think they are tagdecls, but they are probably named decls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the fundamental types and other builtin types, we don't even get here. We enter here only for those types for which a forward declaration is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. @kbobrovs is most familiar with the Int header stuff, so I'll leave the review to him.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @erichkeane