Skip to content

Commit ef98efd

Browse files
committed
Merge branch 'sycl' into e2e-split
2 parents 2811890 + 1581225 commit ef98efd

File tree

114 files changed

+1570
-384
lines changed

Some content is hidden

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

114 files changed

+1570
-384
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11471,6 +11471,12 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1147111471
if (Args.hasArg(options::OPT_fsycl_embed_ir))
1147211472
CmdArgs.push_back(Args.MakeArgString("-sycl-embed-ir"));
1147311473

11474+
if (Args.hasFlag(options::OPT_fsycl_allow_device_image_dependencies,
11475+
options::OPT_fno_sycl_allow_device_image_dependencies,
11476+
false))
11477+
CmdArgs.push_back(
11478+
Args.MakeArgString("-sycl-allow-device-image-dependencies"));
11479+
1147411480
// Formulate and add any offload-wrapper and AOT specific options. These
1147511481
// are additional options passed in via -Xsycl-target-linker and
1147611482
// -Xsycl-target-backend.

clang/lib/Driver/ToolChains/SYCL.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- SYCL.h - SYCL ToolChain Implementations -----------------*- C++ -*-===//
1+
//===--- SYCL.h - SYCL ToolChain Implementations ----------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -158,8 +158,8 @@ SmallVector<std::string, 8> getDeviceLibraries(const Compilation &C,
158158
bool IsSpirvAOT);
159159

160160
// Populates the SYCL device traits macros.
161-
void populateSYCLDeviceTraitsMacrosArgs(Compilation &C,
162-
const llvm::opt::ArgList &Args,
161+
void populateSYCLDeviceTraitsMacrosArgs(
162+
Compilation &C, const llvm::opt::ArgList &Args,
163163
const SmallVectorImpl<std::pair<const ToolChain *, StringRef>> &Targets);
164164

165165
bool shouldDoPerObjectFileLinking(const Compilation &C);
@@ -180,11 +180,11 @@ class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
180180
private:
181181
/// \return llvm-link output file name.
182182
const char *constructLLVMLinkCommand(Compilation &C, const JobAction &JA,
183-
const InputInfo &Output,
184-
const llvm::opt::ArgList &Args,
185-
llvm::StringRef SubArchName,
186-
llvm::StringRef OutputFilePrefix,
187-
const InputInfoList &InputFiles) const;
183+
const InputInfo &Output,
184+
const llvm::opt::ArgList &Args,
185+
llvm::StringRef SubArchName,
186+
llvm::StringRef OutputFilePrefix,
187+
const InputInfoList &InputFiles) const;
188188
};
189189

190190
/// Directly call FPGA Compiler and Linker
@@ -241,7 +241,7 @@ template <auto GPUArh> std::optional<StringRef> isGPUTarget(StringRef Target) {
241241
if (Target.starts_with(GPUArh)) {
242242
return resolveGenDevice(Target);
243243
}
244-
return std::nullopt;
244+
return std::nullopt;
245245
}
246246

247247
} // end namespace gen
@@ -280,9 +280,10 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain {
280280
llvm::opt::DerivedArgList *
281281
TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
282282
Action::OffloadKind DeviceOffloadKind) const override;
283-
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
284-
llvm::opt::ArgStringList &CC1Args,
285-
Action::OffloadKind DeviceOffloadKind) const override;
283+
void
284+
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
285+
llvm::opt::ArgStringList &CC1Args,
286+
Action::OffloadKind DeviceOffloadKind) const override;
286287
void AddImpliedTargetArgs(const llvm::Triple &Triple,
287288
const llvm::opt::ArgList &Args,
288289
llvm::opt::ArgStringList &CmdArgs,
@@ -324,7 +325,8 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain {
324325
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
325326
void AddSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
326327
llvm::opt::ArgStringList &CC1Args) const override;
327-
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
328+
void
329+
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
328330
llvm::opt::ArgStringList &CC1Args) const override;
329331
void AddClangCXXStdlibIncludeArgs(
330332
const llvm::opt::ArgList &Args,
@@ -357,7 +359,8 @@ inline bool isSYCLNativeCPU(const llvm::opt::ArgList &Args) {
357359
return false;
358360
}
359361

360-
inline bool isSYCLNativeCPU(const llvm::Triple &HostT, const llvm::Triple &DevT) {
362+
inline bool isSYCLNativeCPU(const llvm::Triple &HostT,
363+
const llvm::Triple &DevT) {
361364
return HostT == DevT;
362365
}
363366

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,13 +3950,26 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
39503950
}
39513951

39523952
// Default inits the type, then calls the init-method in the body.
3953+
// A type may not have a public default constructor as per its spec so
3954+
// typically if this is the case the default constructor will be private and
3955+
// in such cases we must manually override the access specifier from private
3956+
// to public just for the duration of this default initialization.
3957+
// TODO: Revisit this approach once https://github.com/intel/llvm/issues/16061
3958+
// is closed.
39533959
bool handleSpecialType(FieldDecl *FD, QualType Ty) {
3960+
const auto *RecordDecl = Ty->getAsCXXRecordDecl();
3961+
AccessSpecifier DefaultConstructorAccess;
3962+
auto DefaultConstructor =
3963+
std::find_if(RecordDecl->ctor_begin(), RecordDecl->ctor_end(),
3964+
[](auto it) { return it->isDefaultConstructor(); });
3965+
DefaultConstructorAccess = DefaultConstructor->getAccess();
3966+
DefaultConstructor->setAccess(AS_public);
3967+
39543968
addFieldInit(FD, Ty, std::nullopt,
39553969
InitializationKind::CreateDefault(KernelCallerSrcLoc));
3956-
3970+
DefaultConstructor->setAccess(DefaultConstructorAccess);
39573971
addFieldMemberExpr(FD, Ty);
39583972

3959-
const auto *RecordDecl = Ty->getAsCXXRecordDecl();
39603973
createSpecialMethodCall(RecordDecl, getInitMethodName(), BodyStmts);
39613974
CXXMethodDecl *FinalizeMethod =
39623975
getMethodByName(RecordDecl, FinalizeMethodName);
@@ -3970,9 +3983,17 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
39703983
}
39713984

39723985
bool handleSpecialType(const CXXBaseSpecifier &BS, QualType Ty) {
3973-
const auto *RecordDecl = Ty->getAsCXXRecordDecl();
3986+
const auto *BaseRecordDecl = BS.getType()->getAsCXXRecordDecl();
3987+
AccessSpecifier DefaultConstructorAccess;
3988+
auto DefaultConstructor =
3989+
std::find_if(BaseRecordDecl->ctor_begin(), BaseRecordDecl->ctor_end(),
3990+
[](auto it) { return it->isDefaultConstructor(); });
3991+
DefaultConstructorAccess = DefaultConstructor->getAccess();
3992+
DefaultConstructor->setAccess(AS_public);
3993+
39743994
addBaseInit(BS, Ty, InitializationKind::CreateDefault(KernelCallerSrcLoc));
3975-
createSpecialMethodCall(RecordDecl, getInitMethodName(), BodyStmts);
3995+
DefaultConstructor->setAccess(DefaultConstructorAccess);
3996+
createSpecialMethodCall(BaseRecordDecl, getInitMethodName(), BodyStmts);
39763997
return true;
39773998
}
39783999

@@ -4669,16 +4690,21 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
46694690
bool handleSyclSpecialType(const CXXRecordDecl *RD,
46704691
const CXXBaseSpecifier &BC,
46714692
QualType FieldTy) final {
4672-
const auto *AccTy =
4673-
cast<ClassTemplateSpecializationDecl>(FieldTy->getAsRecordDecl());
4674-
assert(AccTy->getTemplateArgs().size() >= 2 &&
4675-
"Incorrect template args for Accessor Type");
4676-
int Dims = static_cast<int>(
4677-
AccTy->getTemplateArgs()[1].getAsIntegral().getExtValue());
4678-
int Info = getAccessTarget(FieldTy, AccTy) | (Dims << 11);
4679-
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info,
4680-
CurOffset +
4681-
offsetOf(RD, BC.getType()->getAsCXXRecordDecl()));
4693+
if (isSyclAccessorType(FieldTy)) {
4694+
const auto *AccTy =
4695+
cast<ClassTemplateSpecializationDecl>(FieldTy->getAsRecordDecl());
4696+
assert(AccTy->getTemplateArgs().size() >= 2 &&
4697+
"Incorrect template args for Accessor Type");
4698+
int Dims = static_cast<int>(
4699+
AccTy->getTemplateArgs()[1].getAsIntegral().getExtValue());
4700+
int Info = getAccessTarget(FieldTy, AccTy) | (Dims << 11);
4701+
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info,
4702+
CurOffset +
4703+
offsetOf(RD, BC.getType()->getAsCXXRecordDecl()));
4704+
} else if (SemaSYCL::isSyclType(FieldTy, SYCLTypeAttr::work_group_memory)) {
4705+
addParam(FieldTy, SYCLIntegrationHeader::kind_work_group_memory,
4706+
offsetOf(RD, BC.getType()->getAsCXXRecordDecl()));
4707+
}
46824708
return true;
46834709
}
46844710

clang/test/Driver/sycl-offload-new-driver.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,19 @@
195195
// RUN: --offload-new-driver 2>&1 \
196196
// RUN: | FileCheck -check-prefix NVPTX_CUDA_PATH %s
197197
// NVPTX_CUDA_PATH: clang-linker-wrapper{{.*}} "--cuda-path={{.*}}Inputs/CUDA_80/usr/local/cuda"
198+
199+
/// Check for -sycl-allow-device-image-dependencies transmission to clang-linker-wrapper tool
200+
// RUN: %clangxx -fsycl -### --offload-new-driver \
201+
// RUN: -fsycl-allow-device-image-dependencies %s 2>&1 \
202+
// RUN: | FileCheck -check-prefix CHECK_DYNAMIC_LINKING %s
203+
// CHECK_DYNAMIC_LINKING: clang-linker-wrapper{{.*}} "-sycl-allow-device-image-dependencies"
204+
205+
/// Check that -sycl-allow-device-image-dependencies is not passed to clang-linker-wrapper tool
206+
// RUN: %clangxx -fsycl -### --offload-new-driver \
207+
// RUN: -fno-sycl-allow-device-image-dependencies %s 2>&1 \
208+
// RUN: | FileCheck -check-prefix CHECK_NO_DYNAMIC_LINKING %s
209+
210+
/// Check that -sycl-allow-device-image-dependencies is not passed to clang-linker-wrapper tool
211+
// RUN: %clangxx -fsycl -### --offload-new-driver %s 2>&1 \
212+
// RUN: | FileCheck -check-prefix CHECK_NO_DYNAMIC_LINKING %s
213+
// CHECK_NO_DYNAMIC_LINKING-NOT: clang-linker-wrapper{{.*}} "-sycl-allow-device-image-dependencies"

clang/test/SemaSYCL/Inputs/sycl.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,23 @@ class __SYCL_TYPE(multi_ptr) multi_ptr<T, AS, access::decorated::legacy> {
448448
pointer_t m_Pointer;
449449
};
450450

451+
// Dummy implementation of work_group_memory for use in SemaSYCL tests.
452+
template <typename DataT>
453+
class __attribute__((sycl_special_class))
454+
__SYCL_TYPE(work_group_memory) work_group_memory {
455+
456+
// Default constructor for objects later initialized with __init member.
457+
work_group_memory() = default;
458+
459+
public:
460+
work_group_memory(handler &CGH) {}
461+
462+
void __init(__attribute((opencl_local)) DataT *Ptr) { this->Ptr = Ptr; }
463+
void use() const {}
464+
private:
465+
__attribute((opencl_local)) DataT *Ptr;
466+
};
467+
451468
namespace ext {
452469
namespace oneapi {
453470
namespace experimental {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -ast-dump -sycl-std=2020 %s | FileCheck %s
2+
3+
// Check that AST is correctly generated for kernel arguments that inherit from work group memory.
4+
5+
#include "sycl.hpp"
6+
7+
sycl::queue myQueue;
8+
9+
struct WorkGroupMemoryDerived :
10+
sycl::work_group_memory<int> {
11+
};
12+
13+
int main() {
14+
myQueue.submit([&](sycl::handler &h) {
15+
WorkGroupMemoryDerived DerivedObject{ h };
16+
h.parallel_for<class kernel>([=] {
17+
DerivedObject.use();
18+
});
19+
});
20+
return 0;
21+
}
22+
23+
// CHECK: FunctionDecl {{.*}}kernel{{.*}} 'void (__local int *)'
24+
// CHECK-NEXT: ParmVarDecl {{.*}}used _arg__base '__local int *'
25+
// CHECK-NEXT: CompoundStmt {{.*}}
26+
// CHECK-NEXT: DeclStmt {{.*}}
27+
// CHECK-NEXT: VarDecl {{.*}} used __SYCLKernel {{.*}} cinit
28+
// CHECK-NEXT: InitListExpr {{.*}}
29+
// CHECK-NEXT: InitListExpr {{.*}} 'WorkGroupMemoryDerived'
30+
// CHECK-NEXT: CXXConstructExpr {{.*}} 'sycl::work_group_memory<int>' 'void () noexcept'
31+
// CHECK-NEXT: CXXMemberCallExpr {{.*}} 'void'
32+
// CHECK-NEXT: MemberExpr {{.*}} 'void (__local int *)' lvalue .__init {{.*}}
33+
// CHECK-NEXT: MemberExpr {{.*}} 'WorkGroupMemoryDerived' lvalue .DerivedObject
34+
// CHECK-NEXT: DeclRefExpr {{.*}} lvalue Var {{.*}} '__SYCLKernel'
35+
// CHECK-NEXT: ImplicitCastExpr {{.*}} '__local int *' <LValueToRValue>
36+
// CHECK-NEXT: DeclRefExpr {{.*}} '__local int *' lvalue ParmVar {{.*}} '_arg__base' '__local int *'
37+
// CHECK-NEXT: CompoundStmt {{.*}}
38+
// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'void' '()'
39+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'auto (*)() const -> void' <FunctionToPointerDecay>
40+
// CHECK-NEXT: DeclRefExpr {{.*}}'auto () const -> void' lvalue CXXMethod {{.*}} 'operator()' 'auto () const -> void'
41+
// CHECK-NEXT: ImplicitCastExpr {{.*}}
42+
// CHECK-NEXT: DeclRefExpr {{.*}}lvalue Var {{.*}} '__SYCLKernel'
43+

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ getTripleBasedSYCLPostLinkOpts(const ArgList &Args,
676676
if ((!Args.hasFlag(OPT_no_sycl_remove_unused_external_funcs,
677677
OPT_sycl_remove_unused_external_funcs, false) &&
678678
!SYCLNativeCPU) &&
679+
!Args.hasArg(OPT_sycl_allow_device_image_dependencies) &&
679680
!Triple.isNVPTX() && !Triple.isAMDGPU())
680681
PostLinkArgs.push_back("-emit-only-kernels-as-entry-points");
681682

@@ -1111,8 +1112,10 @@ wrapSYCLBinariesFromFile(std::vector<module_split::SplitModule> &SplitModules,
11111112
if (!MBOrDesc)
11121113
return createFileError(SI.ModuleFilePath, MBOrDesc.getError());
11131114

1114-
StringRef ImageTarget = IsEmbeddedIR ? StringRef(EmbeddedIRTarget) : StringRef(RegularTarget);
1115-
Images.emplace_back(std::move(*MBOrDesc), SI.Properties, SI.Symbols, ImageTarget);
1115+
StringRef ImageTarget =
1116+
IsEmbeddedIR ? StringRef(EmbeddedIRTarget) : StringRef(RegularTarget);
1117+
Images.emplace_back(std::move(*MBOrDesc), SI.Properties, SI.Symbols,
1118+
ImageTarget);
11161119
}
11171120

11181121
LLVMContext C;
@@ -1197,7 +1200,8 @@ static Expected<StringRef> runCompile(StringRef &InputFile,
11971200
static Expected<StringRef>
11981201
runWrapperAndCompile(std::vector<module_split::SplitModule> &SplitModules,
11991202
const ArgList &Args, bool IsEmbeddedIR = false) {
1200-
auto OutputFile = sycl::wrapSYCLBinariesFromFile(SplitModules, Args, IsEmbeddedIR);
1203+
auto OutputFile =
1204+
sycl::wrapSYCLBinariesFromFile(SplitModules, Args, IsEmbeddedIR);
12011205
if (!OutputFile)
12021206
return OutputFile.takeError();
12031207
// call to clang
@@ -2416,8 +2420,8 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
24162420
// of sycl-post-link (filetable referencing LLVM Bitcode + symbols)
24172421
// through the offload wrapper and link the resulting object to the
24182422
// application.
2419-
auto OutputFile =
2420-
sycl::runWrapperAndCompile(SplitModules, LinkerArgs, /* IsEmbeddedIR */ true);
2423+
auto OutputFile = sycl::runWrapperAndCompile(SplitModules, LinkerArgs,
2424+
/* IsEmbeddedIR */ true);
24212425
if (!OutputFile)
24222426
return OutputFile.takeError();
24232427
WrappedOutput.push_back(*OutputFile);

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,8 @@ Flags<[WrapperOnlyOption]>, HelpText<"Embed LLVM IR for runtime kernel fusion">
243243
def sycl_dump_device_code_EQ : Joined<["--", "-"], "sycl-dump-device-code=">,
244244
Flags<[WrapperOnlyOption]>,
245245
HelpText<"Path to the folder where the tool dumps SPIR-V device code. Other formats aren't dumped.">;
246+
247+
// Options to enable/disable device dynamic linking.
248+
def sycl_allow_device_image_dependencies : Flag<["--", "-"], "sycl-allow-device-image-dependencies">,
249+
Flags<[WrapperOnlyOption, HelpHidden]>,
250+
HelpText<"Allow dependencies between device code images">;

libdevice/nativecpu_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "device.h"
1818
#include <cstdint>
1919
#include <sycl/__spirv/spirv_ops.hpp>
20-
#include <sycl/types.hpp>
20+
#include <sycl/vector.hpp>
2121

2222
// including state definition from Native CPU UR adapter
2323
#include "nativecpu_state.hpp"

sycl-jit/jit-compiler/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ add_llvm_library(sycl-jit
1919
BitReader
2020
Core
2121
Support
22+
Option
2223
Analysis
2324
IPO
2425
TransformUtils
2526
Passes
27+
IRReader
2628
Linker
2729
ScalarOpts
2830
InstCombine

0 commit comments

Comments
 (0)