Skip to content

Commit 010c535

Browse files
authored
[ESIMD] Fix sampler/stream parameter handling for ESIMD kernels (#5165)
sycl_explicit_simd attribute is crashing when used on a special class.
1 parent d0efca5 commit 010c535

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11627,6 +11627,8 @@ def err_sycl_expected_finalize_method : Error<
1162711627
def ext_sycl_2020_attr_spelling : ExtWarn<
1162811628
"use of attribute %0 is a SYCL 2020 extension">,
1162911629
InGroup<Sycl2017Compat>;
11630+
def err_sycl_esimd_not_supported_for_type : Error<
11631+
"type %0 is not supported in ESIMD context">;
1163011632
def err_sycl_taking_address_of_wrong_function : Error<
1163111633
"taking address of a function not marked with "
1163211634
"'intel::device_indirectly_callable' attribute is not allowed in SYCL device "

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,7 @@ void KernelObjVisitor::visitArray(const CXXRecordDecl *Owner, FieldDecl *Field,
15661566
// A type to check the validity of all of the argument types.
15671567
class SyclKernelFieldChecker : public SyclKernelFieldHandler {
15681568
bool IsInvalid = false;
1569+
bool IsSIMD = false;
15691570
DiagnosticsEngine &Diag;
15701571
// Check whether the object should be disallowed from being copied to kernel.
15711572
// Return true if not copyable, false if copyable.
@@ -1652,6 +1653,10 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
16521653
assert(Util::isSyclSpecialType(Ty) &&
16531654
"Should only be called on sycl special class types.");
16541655
const RecordDecl *RecD = Ty->getAsRecordDecl();
1656+
if (IsSIMD && !Util::isSyclType(Ty, "accessor", true /*Tmp*/))
1657+
return SemaRef.Diag(Loc.getBegin(),
1658+
diag::err_sycl_esimd_not_supported_for_type)
1659+
<< RecD;
16551660
if (const ClassTemplateSpecializationDecl *CTSD =
16561661
dyn_cast<ClassTemplateSpecializationDecl>(RecD)) {
16571662
const TemplateArgumentList &TAL = CTSD->getTemplateArgs();
@@ -1666,8 +1671,9 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
16661671
}
16671672

16681673
public:
1669-
SyclKernelFieldChecker(Sema &S)
1670-
: SyclKernelFieldHandler(S), Diag(S.getASTContext().getDiagnostics()) {}
1674+
SyclKernelFieldChecker(Sema &S, bool isSIMD)
1675+
: SyclKernelFieldHandler(S), Diag(S.getASTContext().getDiagnostics()),
1676+
IsSIMD(isSIMD) {}
16711677
static constexpr const bool VisitNthArrayElement = false;
16721678
bool isValid() { return !IsInvalid; }
16731679

@@ -2250,7 +2256,9 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
22502256
const CXXRecordDecl *RecordDecl = FieldTy->getAsCXXRecordDecl();
22512257
assert(RecordDecl && "The type must be a RecordDecl");
22522258
llvm::StringLiteral MethodName =
2253-
IsSIMD ? InitESIMDMethodName : InitMethodName;
2259+
(IsSIMD && Util::isSyclType(FieldTy, "accessor", true /*Tmp*/))
2260+
? InitESIMDMethodName
2261+
: InitMethodName;
22542262
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName);
22552263
assert(InitMethod && "The type must have the __init method");
22562264
for (const ParmVarDecl *Param : InitMethod->parameters())
@@ -3549,11 +3557,12 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc, SourceRange CallLoc,
35493557
if (KernelObj->isInvalidDecl())
35503558
return;
35513559

3560+
bool IsSIMDKernel = isESIMDKernelType(KernelObj);
3561+
35523562
SyclKernelDecompMarker DecompMarker(*this);
3553-
SyclKernelFieldChecker FieldChecker(*this);
3563+
SyclKernelFieldChecker FieldChecker(*this, IsSIMDKernel);
35543564
SyclKernelUnionChecker UnionChecker(*this);
35553565

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -verify -internal-isystem %S/Inputs -fsyntax-only %s
2+
3+
// The test is to ensure that the use of sycl_explicit_simd attribute doesn't
4+
// crash when used with sampler or stream. Currently samplers/stream are not
5+
// supported in esimd.
6+
7+
#include "sycl.hpp"
8+
using namespace cl::sycl;
9+
void test() {
10+
11+
queue q;
12+
13+
q.submit([&](handler &h) {
14+
cl::sycl::sampler Smplr;
15+
cl::sycl::stream Stream(1024, 128, h);
16+
// expected-note@+1{{in instantiation of function template specialization}}
17+
h.single_task<class SamplerTester>(
18+
// expected-error@+1{{type 'sampler' is not supported in ESIMD context}}
19+
[=]() [[intel::sycl_explicit_simd]] { Smplr.use(); });
20+
21+
// expected-note@+1{{in instantiation of function template specialization}}
22+
h.single_task<class StreamTester>(
23+
// expected-error@+1{{type 'stream' is not supported in ESIMD context}}
24+
[=]() [[intel::sycl_explicit_simd]] { Stream.use(); });
25+
});
26+
}

0 commit comments

Comments
 (0)