Skip to content

Commit 588661b

Browse files
committed
Merge sycl
2 parents 67ba8c9 + 79c460c commit 588661b

File tree

75 files changed

+4919
-1913
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4919
-1913
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ clang/tools/clang-offload-extract/ @sndmitriev @mlychkov @AlexeySachkov
101101
# Explicit SIMD
102102
SYCLLowerIR/ @kbobrovs @DenisBakhvalov
103103
esimd/ @kbobrovs @DenisBakhvalov
104-
sycl/include/CL/sycl/INTEL/esimd.hpp @kbobrovs @DenisBakhvalov
104+
sycl/include/sycl/ext/intel/experimental/esimd.hpp @kbobrovs @DenisBakhvalov
105105
sycl/doc/extensions/ExplicitSIMD/ @kbobrovs
106106

107107
# ITT annotations
108-
llvm/lib/Transforms/Instrumentation/SPIRITTAnnotations.cpp @MrSidims
109-
llvm/include/llvm/Transforms/Instrumentation/SPIRITTAnnotations.h @MrSidims
108+
llvm/lib/Transforms/Instrumentation/SPIRITTAnnotations.cpp @MrSidims @vzakhari
109+
llvm/include/llvm/Transforms/Instrumentation/SPIRITTAnnotations.h @MrSidims @vzakhari
110+
llvm/test/Transforms/SPIRITTAnnotations/* @MrSidims @vzakhari

buildbot/configure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def do_configure(args):
3030
llvm_enable_doxygen = 'OFF'
3131
llvm_enable_sphinx = 'OFF'
3232
llvm_build_shared_libs = 'OFF'
33+
llvm_enable_lld = 'OFF'
3334

3435
sycl_enable_xpti_tracing = 'ON'
3536

@@ -56,6 +57,9 @@ def do_configure(args):
5657
if args.shared_libs:
5758
llvm_build_shared_libs = 'ON'
5859

60+
if args.use_lld:
61+
llvm_enable_lld = 'ON'
62+
5963
install_dir = os.path.join(abs_obj_dir, "install")
6064

6165
cmake_cmd = [
@@ -81,7 +85,8 @@ def do_configure(args):
8185
"-DLLVM_ENABLE_DOXYGEN={}".format(llvm_enable_doxygen),
8286
"-DLLVM_ENABLE_SPHINX={}".format(llvm_enable_sphinx),
8387
"-DBUILD_SHARED_LIBS={}".format(llvm_build_shared_libs),
84-
"-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing)
88+
"-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing),
89+
"-DLLVM_ENABLE_LLD={}".format(llvm_enable_lld)
8590
]
8691

8792
if args.l0_headers and args.l0_loader:
@@ -151,6 +156,7 @@ def main():
151156
parser.add_argument("--use-libcxx", action="store_true", help="build sycl runtime with libcxx")
152157
parser.add_argument("--libcxx-include", metavar="LIBCXX_INCLUDE_PATH", help="libcxx include path")
153158
parser.add_argument("--libcxx-library", metavar="LIBCXX_LIBRARY_PATH", help="libcxx library path")
159+
parser.add_argument("--use-lld", action="store_true", help="Use LLD linker for build")
154160
args = parser.parse_args()
155161

156162
print("args:{}".format(args))

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11412,6 +11412,8 @@ def err_sycl_mismatch_group_size
1141211412
"have a sub group size that matches the size specified for the "
1141311413
"kernel">;
1141411414
def note_sycl_kernel_declared_here : Note<"kernel declared here">;
11415+
def err_sycl_expected_finalize_method : Error<
11416+
"expected a 'finalize' method for the 'stream' class">;
1141511417
def ext_sycl_2020_attr_spelling : ExtWarn<
1141611418
"use of attribute %0 is a SYCL 2020 extension">,
1141711419
InGroup<Sycl2017Compat>;

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ class SYCLIntegrationHeader {
316316
kind_sampler,
317317
kind_pointer,
318318
kind_specialization_constants_buffer,
319-
kind_last = kind_specialization_constants_buffer
319+
kind_stream,
320+
kind_last = kind_stream
320321
};
321322

322323
public:

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 34 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static constexpr llvm::StringLiteral InitESIMDMethodName = "__init_esimd";
6161
static constexpr llvm::StringLiteral InitSpecConstantsBuffer =
6262
"__init_specialization_constants_buffer";
6363
static constexpr llvm::StringLiteral FinalizeMethodName = "__finalize";
64+
static constexpr llvm::StringLiteral LibstdcxxFailedAssertion =
65+
"__failed_assertion";
6466
constexpr unsigned MaxKernelArgsSize = 2048;
6567

6668
namespace {
@@ -320,6 +322,21 @@ static bool isSYCLKernelBodyFunction(FunctionDecl *FD) {
320322
return FD->getOverloadedOperator() == OO_Call;
321323
}
322324

325+
static bool isSYCLUndefinedAllowed(const FunctionDecl *Callee,
326+
const SourceManager &SrcMgr) {
327+
if (!Callee)
328+
return false;
329+
330+
// libstdc++-11 introduced an undefined function "void __failed_assertion()"
331+
// which may lead to SemaSYCL check failure. However, this undefined function
332+
// is used to trigger some compilation error when the check fails at compile
333+
// time and will be ignored when the check succeeds. We allow calls to this
334+
// function to support some important std functions in SYCL device.
335+
return (Callee->getName() == LibstdcxxFailedAssertion) &&
336+
Callee->getNumParams() == 0 && Callee->getReturnType()->isVoidType() &&
337+
SrcMgr.isInSystemHeader(Callee->getLocation());
338+
}
339+
323340
// Helper function to report conflicting function attributes.
324341
// F - the function, A1 - function attribute, A2 - the attribute it conflicts
325342
// with.
@@ -1034,23 +1051,6 @@ class KernelObjVisitor {
10341051
VisitRecordFields(Owner, Handlers...);
10351052
}
10361053

1037-
// FIXME: Can this be refactored/handled some other way?
1038-
template <typename ParentTy, typename... HandlerTys>
1039-
void visitStreamRecord(const CXXRecordDecl *Owner, ParentTy &Parent,
1040-
CXXRecordDecl *Wrapper, QualType RecordTy,
1041-
HandlerTys &... Handlers) {
1042-
(void)std::initializer_list<int>{
1043-
(Handlers.enterStream(Owner, Parent, RecordTy), 0)...};
1044-
for (const auto &Field : Wrapper->fields()) {
1045-
QualType FieldTy = Field->getType();
1046-
// Required to initialize accessors inside streams.
1047-
if (Util::isSyclAccessorType(FieldTy))
1048-
KF_FOR_EACH(handleSyclAccessorType, Field, FieldTy);
1049-
}
1050-
(void)std::initializer_list<int>{
1051-
(Handlers.leaveStream(Owner, Parent, RecordTy), 0)...};
1052-
}
1053-
10541054
template <typename... HandlerTys>
10551055
void visitArrayElementImpl(const CXXRecordDecl *Owner, FieldDecl *ArrayField,
10561056
QualType ElementTy, uint64_t Index,
@@ -1125,12 +1125,9 @@ class KernelObjVisitor {
11251125
KF_FOR_EACH(handleSyclHalfType, Field, FieldTy);
11261126
else if (Util::isSyclSpecConstantType(FieldTy))
11271127
KF_FOR_EACH(handleSyclSpecConstantType, Field, FieldTy);
1128-
else if (Util::isSyclStreamType(FieldTy)) {
1129-
CXXRecordDecl *RD = FieldTy->getAsCXXRecordDecl();
1130-
// Handle accessors in stream class.
1128+
else if (Util::isSyclStreamType(FieldTy))
11311129
KF_FOR_EACH(handleSyclStreamType, Field, FieldTy);
1132-
visitStreamRecord(Owner, Field, RD, FieldTy, Handlers...);
1133-
} else if (FieldTy->isStructureOrClassType()) {
1130+
else if (FieldTy->isStructureOrClassType()) {
11341131
if (KF_FOR_EACH(handleStructType, Field, FieldTy)) {
11351132
CXXRecordDecl *RD = FieldTy->getAsCXXRecordDecl();
11361133
visitRecord(Owner, Field, RD, FieldTy, Handlers...);
@@ -1244,12 +1241,6 @@ class SyclKernelFieldHandlerBase {
12441241
virtual bool leaveStruct(const CXXRecordDecl *, FieldDecl *, QualType) {
12451242
return true;
12461243
}
1247-
virtual bool enterStream(const CXXRecordDecl *, FieldDecl *, QualType) {
1248-
return true;
1249-
}
1250-
virtual bool leaveStream(const CXXRecordDecl *, FieldDecl *, QualType) {
1251-
return true;
1252-
}
12531244
virtual bool enterStruct(const CXXRecordDecl *, const CXXBaseSpecifier &,
12541245
QualType) {
12551246
return true;
@@ -1697,18 +1688,6 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
16971688
return true;
16981689
}
16991690

1700-
// Stream is always decomposed (and whether it gets decomposed is handled in
1701-
// handleSyclStreamType), but we need a CollectionStack entry to capture the
1702-
// accessors that get handled.
1703-
bool enterStream(const CXXRecordDecl *, FieldDecl *, QualType) final {
1704-
CollectionStack.push_back(false);
1705-
return true;
1706-
}
1707-
bool leaveStream(const CXXRecordDecl *, FieldDecl *, QualType Ty) final {
1708-
CollectionStack.pop_back();
1709-
return true;
1710-
}
1711-
17121691
bool enterStruct(const CXXRecordDecl *, FieldDecl *, QualType) final {
17131692
CollectionStack.push_back(false);
17141693
return true;
@@ -1956,14 +1935,6 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
19561935
SemaRef.addSyclDeviceDecl(KernelDecl);
19571936
}
19581937

1959-
bool enterStream(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
1960-
return enterStruct(RD, FD, Ty);
1961-
}
1962-
1963-
bool leaveStream(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
1964-
return leaveStruct(RD, FD, Ty);
1965-
}
1966-
19671938
bool enterStruct(const CXXRecordDecl *, FieldDecl *, QualType) final {
19681939
++StructDepth;
19691940
return true;
@@ -2099,8 +2070,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
20992070
}
21002071

21012072
bool handleSyclStreamType(FieldDecl *FD, QualType FieldTy) final {
2102-
addParam(FD, FieldTy);
2103-
return true;
2073+
return handleSpecialType(FD, FieldTy);
21042074
}
21052075

21062076
bool handleSyclStreamType(const CXXRecordDecl *, const CXXBaseSpecifier &,
@@ -2419,15 +2389,6 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
24192389
}
24202390

24212391
bool handleSyclStreamType(FieldDecl *FD, QualType FieldTy) final {
2422-
// For the current implementation of stream class, the Visitor 'handles'
2423-
// stream argument and then visits each accessor field in stream. Therefore
2424-
// handleSpecialType in this case only adds a single argument for stream.
2425-
// The arguments corresponding to accessors in stream are handled in
2426-
// handleSyclAccessorType. The opt-report therefore does not diffrentiate
2427-
// between the accessors in streams and accessors captured by SYCL kernel.
2428-
// Once stream API is modified to use __init(), the visitor will no longer
2429-
// visit the stream object and opt-report output for stream class will be
2430-
// similar to that of other special types.
24312392
return handleSpecialType(
24322393
FD, FieldTy, KernelArgDescription(KernelArgDescription::Stream));
24332394
}
@@ -2805,6 +2766,13 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
28052766

28062767
const auto *RecordDecl = Ty->getAsCXXRecordDecl();
28072768
createSpecialMethodCall(RecordDecl, getInitMethodName(), BodyStmts);
2769+
CXXMethodDecl *FinalizeMethod =
2770+
getMethodByName(RecordDecl, FinalizeMethodName);
2771+
// A finalize-method is expected for stream class.
2772+
if (!FinalizeMethod && Util::isSyclStreamType(Ty))
2773+
SemaRef.Diag(FD->getLocation(), diag::err_sycl_expected_finalize_method);
2774+
else
2775+
createSpecialMethodCall(RecordDecl, FinalizeMethodName, FinalizeStmts);
28082776

28092777
removeFieldMemberExpr(FD, Ty);
28102778

@@ -2898,9 +2866,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
28982866
}
28992867

29002868
bool handleSyclStreamType(FieldDecl *FD, QualType Ty) final {
2901-
// Streams just get copied as a new init.
2902-
addSimpleFieldInit(FD, Ty);
2903-
return true;
2869+
return handleSpecialType(FD, Ty);
29042870
}
29052871

29062872
bool handleSyclStreamType(const CXXRecordDecl *, const CXXBaseSpecifier &BS,
@@ -2977,31 +2943,6 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
29772943
handleSpecialType(KernelHandlerArg->getType());
29782944
}
29792945

2980-
bool enterStream(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
2981-
++StructDepth;
2982-
// Add a dummy init expression to catch the accessor initializers.
2983-
const auto *StreamDecl = Ty->getAsCXXRecordDecl();
2984-
CollectionInitExprs.push_back(createInitListExpr(StreamDecl));
2985-
2986-
addFieldMemberExpr(FD, Ty);
2987-
return true;
2988-
}
2989-
2990-
bool leaveStream(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
2991-
--StructDepth;
2992-
// Stream requires that its 'init' calls happen after its accessors init
2993-
// calls, so add them here instead.
2994-
const auto *StreamDecl = Ty->getAsCXXRecordDecl();
2995-
2996-
createSpecialMethodCall(StreamDecl, getInitMethodName(), BodyStmts);
2997-
createSpecialMethodCall(StreamDecl, FinalizeMethodName, FinalizeStmts);
2998-
2999-
removeFieldMemberExpr(FD, Ty);
3000-
3001-
CollectionInitExprs.pop_back();
3002-
return true;
3003-
}
3004-
30052946
bool enterStruct(const CXXRecordDecl *RD, FieldDecl *FD, QualType Ty) final {
30062947
++StructDepth;
30072948
addCollectionInitListExpr(Ty->getAsCXXRecordDecl());
@@ -3315,7 +3256,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
33153256
}
33163257

33173258
bool handleSyclStreamType(FieldDecl *FD, QualType FieldTy) final {
3318-
addParam(FD, FieldTy, SYCLIntegrationHeader::kind_std_layout);
3259+
addParam(FD, FieldTy, SYCLIntegrationHeader::kind_stream);
33193260
return true;
33203261
}
33213262

@@ -3347,18 +3288,6 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
33473288
SYCLIntegrationHeader::kind_specialization_constants_buffer, 0);
33483289
}
33493290

3350-
bool enterStream(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
3351-
++StructDepth;
3352-
CurOffset += offsetOf(FD, Ty);
3353-
return true;
3354-
}
3355-
3356-
bool leaveStream(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
3357-
--StructDepth;
3358-
CurOffset -= offsetOf(FD, Ty);
3359-
return true;
3360-
}
3361-
33623291
bool enterStruct(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
33633292
++StructDepth;
33643293
CurOffset += offsetOf(FD, Ty);
@@ -4122,7 +4051,10 @@ void Sema::finalizeSYCLDelayedAnalysis(const FunctionDecl *Caller,
41224051
return;
41234052

41244053
// Diagnose if this is an undefined function and it is not a builtin.
4125-
if (!Callee->isDefined() && !Callee->getBuiltinID()) {
4054+
// Currently, there is an exception of "__failed_assertion" in libstdc++-11,
4055+
// this undefined function is used to trigger a compiling error.
4056+
if (!Callee->isDefined() && !Callee->getBuiltinID() &&
4057+
!isSYCLUndefinedAllowed(Callee, getSourceManager())) {
41264058
Diag(Loc, diag::err_sycl_restrict) << Sema::KernelCallUndefinedFunction;
41274059
Diag(Callee->getLocation(), diag::note_previous_decl) << Callee;
41284060
Diag(Caller->getLocation(), diag::note_called_by) << Caller;
@@ -4160,6 +4092,7 @@ static const char *paramKind2Str(KernelParamKind K) {
41604092
CASE(accessor);
41614093
CASE(std_layout);
41624094
CASE(sampler);
4095+
CASE(stream);
41634096
CASE(specialization_constants_buffer);
41644097
CASE(pointer);
41654098
}

clang/test/CodeGenSYCL/Inputs/sycl.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class accessor {
181181
void __init(__attribute__((opencl_global)) dataT *Ptr, range<dimensions> AccessRange,
182182
range<dimensions> MemRange, id<dimensions> Offset) {}
183183
void __init_esimd(__attribute__((opencl_global)) dataT *Ptr) {}
184+
friend class stream;
184185
};
185186

186187
template <int dimensions, access::mode accessmode, access::target accesstarget>
@@ -411,10 +412,22 @@ class stream {
411412
public:
412413
stream(unsigned long BufferSize, unsigned long MaxStatementSize,
413414
handler &CGH) {}
415+
#ifdef __SYCL_DEVICE_ONLY__
416+
// Default constructor for objects later initialized with __init member.
417+
stream() = default;
418+
#endif
414419

415-
void __init() {}
420+
void __init(__attribute((opencl_global)) char *Ptr, range<1> AccessRange,
421+
range<1> MemRange, id<1> Offset, int _FlushBufferSize) {
422+
Acc.__init(Ptr, AccessRange, MemRange, Offset);
423+
FlushBufferSize = _FlushBufferSize;
424+
}
416425

417426
void __finalize() {}
427+
428+
private:
429+
cl::sycl::accessor<char, 1, cl::sycl::access::mode::read_write> Acc;
430+
int FlushBufferSize;
418431
};
419432

420433
template <typename T>

0 commit comments

Comments
 (0)