Skip to content

[ESIMD] Fix sampler/stream parameter handling for ESIMD kernels #5165

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 11 commits into from
Jan 21, 2022
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: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11627,6 +11627,8 @@ def err_sycl_expected_finalize_method : Error<
def ext_sycl_2020_attr_spelling : ExtWarn<
"use of attribute %0 is a SYCL 2020 extension">,
InGroup<Sycl2017Compat>;
def err_sycl_esimd_not_supported_for_type : Error<
"type %0 is not supported in ESIMD context">;
def err_sycl_taking_address_of_wrong_function : Error<
"taking address of a function not marked with "
"'intel::device_indirectly_callable' attribute is not allowed in SYCL device "
Expand Down
19 changes: 14 additions & 5 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,7 @@ void KernelObjVisitor::visitArray(const CXXRecordDecl *Owner, FieldDecl *Field,
// A type to check the validity of all of the argument types.
class SyclKernelFieldChecker : public SyclKernelFieldHandler {
bool IsInvalid = false;
bool IsSIMD = false;
DiagnosticsEngine &Diag;
// Check whether the object should be disallowed from being copied to kernel.
// Return true if not copyable, false if copyable.
Expand Down Expand Up @@ -1647,6 +1648,10 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
assert(Util::isSyclSpecialType(Ty) &&
"Should only be called on sycl special class types.");
const RecordDecl *RecD = Ty->getAsRecordDecl();
if (IsSIMD && !Util::isSyclType(Ty, "accessor", true /*Tmp*/))
return SemaRef.Diag(Loc.getBegin(),
diag::err_sycl_esimd_not_supported_for_type)
<< RecD;
if (const ClassTemplateSpecializationDecl *CTSD =
dyn_cast<ClassTemplateSpecializationDecl>(RecD)) {
const TemplateArgumentList &TAL = CTSD->getTemplateArgs();
Expand All @@ -1661,8 +1666,9 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
}

public:
SyclKernelFieldChecker(Sema &S)
: SyclKernelFieldHandler(S), Diag(S.getASTContext().getDiagnostics()) {}
SyclKernelFieldChecker(Sema &S, bool isSIMD)
: SyclKernelFieldHandler(S), Diag(S.getASTContext().getDiagnostics()),
IsSIMD(isSIMD) {}
static constexpr const bool VisitNthArrayElement = false;
bool isValid() { return !IsInvalid; }

Expand Down Expand Up @@ -2247,7 +2253,9 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
const CXXRecordDecl *RecordDecl = FieldTy->getAsCXXRecordDecl();
assert(RecordDecl && "The type must be a RecordDecl");
llvm::StringLiteral MethodName =
IsSIMD ? InitESIMDMethodName : InitMethodName;
(IsSIMD && Util::isSyclType(FieldTy, "accessor", true /*Tmp*/))
? InitESIMDMethodName
: InitMethodName;
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName);
assert(InitMethod && "The type must have the __init method");
for (const ParmVarDecl *Param : InitMethod->parameters())
Expand Down Expand Up @@ -3546,11 +3554,12 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc, SourceRange CallLoc,
if (KernelObj->isInvalidDecl())
return;

bool IsSIMDKernel = isESIMDKernelType(KernelObj);

SyclKernelDecompMarker DecompMarker(*this);
SyclKernelFieldChecker FieldChecker(*this);
SyclKernelFieldChecker FieldChecker(*this, IsSIMDKernel);
SyclKernelUnionChecker UnionChecker(*this);

bool IsSIMDKernel = isESIMDKernelType(KernelObj);
SyclKernelArgsSizeChecker ArgsSizeChecker(*this, Args[0]->getExprLoc(),
IsSIMDKernel);

Expand Down
26 changes: 26 additions & 0 deletions clang/test/SemaSYCL/esimd-special-class.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clang_cc1 -fsycl-is-device -verify -internal-isystem %S/Inputs -fsyntax-only %s

// The test is to ensure that the use of sycl_explicit_simd attribute doesn't
// crash when used with sampler or stream. Currently samplers/stream are not
// supported in esimd.

#include "sycl.hpp"
using namespace cl::sycl;
void test() {

queue q;

q.submit([&](handler &h) {
cl::sycl::sampler Smplr;
cl::sycl::stream Stream(1024, 128, h);
// expected-note@+1{{in instantiation of function template specialization}}
h.single_task<class SamplerTester>(
// expected-error@+1{{type 'sampler' is not supported in ESIMD context}}
[=]() [[intel::sycl_explicit_simd]] { Smplr.use(); });

// expected-note@+1{{in instantiation of function template specialization}}
h.single_task<class StreamTester>(
// expected-error@+1{{type 'stream' is not supported in ESIMD context}}
[=]() [[intel::sycl_explicit_simd]] { Stream.use(); });
});
}