Skip to content

Commit 62ea9a2

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents 3c74232 + 702642c commit 62ea9a2

File tree

5 files changed

+98
-38
lines changed

5 files changed

+98
-38
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5145,14 +5145,33 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
51455145

51465146
// For an FPGA archive, we add the unbundling step above to take care of
51475147
// the device side, but also unbundle here to extract the host side
5148-
for (const auto &LI : LinkerInputs) {
5148+
bool EarlyLink = false;
5149+
if (const Arg *A = Args.getLastArg(options::OPT_fsycl_link_EQ))
5150+
EarlyLink = A->getValue() == StringRef("early");
5151+
for (auto &LI : LinkerInputs) {
51495152
Action *UnbundlerInput = nullptr;
5153+
auto wrapObject = [&] {
5154+
if (EarlyLink && Args.hasArg(options::OPT_fintelfpga)) {
5155+
// Only wrap the object with -fsycl-link=early
5156+
auto *BC = C.MakeAction<OffloadWrapperJobAction>(LI, types::TY_LLVM_BC);
5157+
auto *ASM = C.MakeAction<BackendJobAction>(BC, types::TY_PP_Asm);
5158+
LI = C.MakeAction<AssembleJobAction>(ASM, types::TY_Object);
5159+
}
5160+
};
51505161
if (auto *IA = dyn_cast<InputAction>(LI)) {
51515162
if (IA->getType() == types::TY_FPGA_AOCR ||
51525163
IA->getType() == types::TY_FPGA_AOCX) {
51535164
// Add to unbundler.
51545165
UnbundlerInput = LI;
5166+
} else {
5167+
std::string FileName = IA->getInputArg().getAsString(Args);
5168+
if ((IA->getType() == types::TY_Object && !isObjectFile(FileName)) ||
5169+
IA->getInputArg().getOption().hasFlag(options::LinkerInput))
5170+
continue;
5171+
wrapObject();
51555172
}
5173+
} else {
5174+
wrapObject();
51565175
}
51575176
if (UnbundlerInput && !PL.empty()) {
51585177
if (auto *IA = dyn_cast<InputAction>(UnbundlerInput)) {
@@ -6166,8 +6185,6 @@ InputInfo Driver::BuildJobsForActionNoCache(
61666185
OffloadingPrefix += "-wrapper";
61676186
if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
61686187
BaseInput = FinalOutput->getValue();
6169-
else
6170-
BaseInput = getDefaultImageName();
61716188
}
61726189
}
61736190
Result = InputInfo(A, GetNamedOutputPath(C, *JA, BaseInput, BoundArch,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,10 +4056,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
40564056
// device toolchain.
40574057
bool UseSYCLTriple = IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice);
40584058

4059-
// Adjust IsWindowsXYZ for CUDA/HIP compilations. Even when compiling in
4059+
// Adjust IsWindowsXYZ for CUDA/HIP/SYCL compilations. Even when compiling in
40604060
// device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
40614061
// Windows), we need to pass Windows-specific flags to cc1.
4062-
if (IsCuda || IsHIP)
4062+
if (IsCuda || IsHIP || IsSYCL)
40634063
IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment();
40644064

40654065
// C++ is not supported for IAMCU.
@@ -5199,7 +5199,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51995199
/*Joined=*/true);
52005200
else if (IsWindowsMSVC)
52015201
ImplyVCPPCXXVer = true;
5202-
else if (IsSYCL)
5202+
5203+
if (IsSYCL && types::isCXX(InputType) &&
5204+
!Args.hasArg(options::OPT__SLASH_std))
52035205
// For DPC++, we default to -std=c++17 for all compilations. Use of -std
52045206
// on the command line will override.
52055207
CmdArgs.push_back("-std=c++17");
@@ -5783,12 +5785,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57835785
}
57845786

57855787
if (LanguageStandard.empty()) {
5786-
if (IsMSVC2015Compatible)
5787-
if (IsSYCL)
5788-
// For DPC++, C++17 is the default.
5789-
LanguageStandard = "-std=c++17";
5790-
else
5791-
LanguageStandard = "-std=c++14";
5788+
if (IsSYCL)
5789+
// For DPC++, C++17 is the default.
5790+
LanguageStandard = "-std=c++17";
5791+
else if (IsMSVC2015Compatible)
5792+
LanguageStandard = "-std=c++14";
57925793
else
57935794
LanguageStandard = "-std=c++11";
57945795
}
@@ -7732,6 +7733,30 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
77327733
assert(JA.getInputs().size() == Inputs.size() &&
77337734
"Not have inputs for all dependence actions??");
77347735

7736+
// For FPGA, we wrap the host objects before archiving them when using
7737+
// -fsycl-link. This allows for better extraction control from the
7738+
// archive when we need the host objects for subsequent compilations.
7739+
if (OffloadingKind == Action::OFK_None &&
7740+
C.getArgs().hasArg(options::OPT_fintelfpga) &&
7741+
C.getArgs().hasArg(options::OPT_fsycl_link_EQ)) {
7742+
7743+
// Add offload targets and inputs.
7744+
CmdArgs.push_back(C.getArgs().MakeArgString(
7745+
Twine("-kind=") + Action::GetOffloadKindName(OffloadingKind)));
7746+
CmdArgs.push_back(
7747+
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));
7748+
7749+
// Add input.
7750+
assert(Inputs[0].isFilename() && "Invalid input.");
7751+
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));
7752+
7753+
C.addCommand(std::make_unique<Command>(
7754+
JA, *this, ResponseFileSupport::None(),
7755+
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
7756+
CmdArgs, Inputs));
7757+
return;
7758+
}
7759+
77357760
// Add offload targets and inputs.
77367761
for (unsigned I = 0; I < Inputs.size(); ++I) {
77377762
// Get input's Offload Kind and ToolChain.

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
// CHK-FPGA-LINK: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.1" "-spirv-debug-info-version=legacy" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes" "[[OUTPUT2]]"
3636
// CHK-FPGA-EARLY: aoc{{.*}} "-o" "[[OUTPUT4:.+\.aocr]]" "[[OUTPUT3]]" "-sycl" "-rtl"
3737
// CHK-FPGA-IMAGE: aoc{{.*}} "-o" "[[OUTPUT5:.+\.aocx]]" "[[OUTPUT3]]" "-sycl"
38-
// CHK-FPGA-LINK: llvm-ar{{.*}} "cr" "libfoo.a" "[[INPUT]]"
38+
// CHK-FPGA-LINK: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" {{.*}} "-kind=sycl"
39+
// CHK-FPGA-LINK: llc{{.*}} "-o" "[[OBJOUTDEV:.+\.o]]" "[[WRAPOUT]]"
40+
// CHK-FPGA-EARLY: clang-offload-wrapper{{.*}} "-host" "x86_64-unknown-linux-gnu" "-o" "[[WRAPOUTHOST:.+\.bc]]" "-kind=host"
41+
// CHK-FPGA-EARLY: clang{{.*}} "-o" "[[OBJOUT:.+\.o]]" {{.*}} "[[WRAPOUTHOST]]"
42+
// CHK-FPGA-EARLY: llvm-ar{{.*}} "cr" "libfoo.a" "[[OBJOUT]]" "[[OBJOUTDEV]]"
43+
// CHK-FPGA-IMAGE: llvm-ar{{.*}} "cr" "libfoo.a" "[[INPUT]]" "[[OBJOUTDEV]]"
3944

4045
// Output designation should not be used for unbundling step
4146
// RUN: touch %t.o
@@ -60,7 +65,11 @@
6065
// CHK-FPGA-LINK-WIN: sycl-post-link{{.*}} "-ir-output-only" "-spec-const=default" "-o" "[[OUTPUT2:.+\.bc]]" "[[OUTPUT2_1]]"
6166
// CHK-FPGA-LINK-WIN: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.1" "-spirv-debug-info-version=legacy" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes" "[[OUTPUT2]]"
6267
// CHK-FPGA-LINK-WIN: aoc{{.*}} "-o" "[[OUTPUT5:.+\.aocr]]" "[[OUTPUT3]]" "-sycl" "-rtl"
63-
// CHK-FPGA-LINK-WIN: lib.exe{{.*}} "[[INPUT]]" {{.*}} "-OUT:libfoo.lib"
68+
// CHK-FPGA-LINK-WIN: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" {{.*}} "-kind=sycl"
69+
// CHK-FPGA-LINK-WIN: llc{{.*}} "-o" "[[OBJOUTDEV:.+\.obj]]" "[[WRAPOUT]]"
70+
// CHK-FPGA-LINK-WIN: clang-offload-wrapper{{.*}} "-o" "[[WRAPOUTHOST:.+\.bc]]" "-kind=host"
71+
// CHK-FPGA-LINK-WIN: clang{{.*}} "-o" "[[OBJOUT:.+\.obj]]" {{.*}} "[[WRAPOUTHOST]]"
72+
// CHK-FPGA-LINK-WIN: lib.exe{{.*}} "[[OBJOUT]]" "[[OBJOUTDEV]]" {{.*}} "-OUT:libfoo.lib"
6473

6574
/// Check -fintelfpga -fsycl-link with an FPGA archive
6675
// Create the dummy archive
@@ -83,7 +92,7 @@
8392
// CHK-FPGA-LINK-LIB-EARLY: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "-target=fpga_aocr-intel-unknown-sycldevice" "-kind=sycl" "[[OUTPUT4]]"
8493
// CHK-FPGA-LINK-LIB: llc{{.*}} "-filetype=obj" "-o" "[[OUTPUT5:.+\.o]]"
8594
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-inputs=[[INPUT]]" "-outputs=[[OUTPUT1:.+\.txt]]" "-unbundle"
86-
// CHK-FPGA-LINK-LIB: llvm-ar{{.*}} "cr" {{.*}} "@[[OUTPUT1]]"
95+
// CHK-FPGA-LINK-LIB-IMAGE: llvm-ar{{.*}} "cr" {{.*}} "@[[OUTPUT1]]"
8796

8897
/// Check the warning's emission for -fsycl-link's appending behavior
8998
// RUN: touch dummy.a
@@ -186,28 +195,29 @@
186195
/// -fintelfpga -fsycl-link from source
187196
// RUN: touch %t.cpp
188197
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \
189-
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-SRC,CHK-FPGA-LINK-SRC-DEFAULT %s
190-
// RUN: %clang_cl -### -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \
191-
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-SRC,CHK-FPGA-LINK-SRC-CL %s
198+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-SRC %s
199+
// RUN: %clang_cl -### --target=x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \
200+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-SRC %s
192201
// CHK-FPGA-LINK-SRC: 0: input, "[[INPUT:.+\.cpp]]", c++, (host-sycl)
193202
// CHK-FPGA-LINK-SRC: 1: preprocessor, {0}, c++-cpp-output, (host-sycl)
194203
// CHK-FPGA-LINK-SRC: 2: input, "[[INPUT]]", c++, (device-sycl)
195204
// CHK-FPGA-LINK-SRC: 3: preprocessor, {2}, c++-cpp-output, (device-sycl)
196205
// CHK-FPGA-LINK-SRC: 4: compiler, {3}, sycl-header, (device-sycl)
197-
// CHK-FPGA-LINK-SRC-DEFAULT: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {4}, c++-cpp-output
198-
// CHK-FPGA-LINK-SRC-CL: 5: offload, "host-sycl (x86_64-pc-windows-msvc)" {1}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {4}, c++-cpp-output
206+
// CHK-FPGA-LINK-SRC: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {4}, c++-cpp-output
199207
// CHK-FPGA-LINK-SRC: 6: compiler, {5}, ir, (host-sycl)
200208
// CHK-FPGA-LINK-SRC: 7: backend, {6}, assembler, (host-sycl)
201209
// CHK-FPGA-LINK-SRC: 8: assembler, {7}, object, (host-sycl)
202-
// CHK-FPGA-LINK-SRC: 9: linker, {8}, archive, (host-sycl)
203-
// CHK-FPGA-LINK-SRC: 10: compiler, {3}, ir, (device-sycl)
204-
// CHK-FPGA-LINK-SRC: 11: linker, {10}, ir, (device-sycl)
205-
// CHK-FPGA-LINK-SRC: 12: sycl-post-link, {11}, ir, (device-sycl)
206-
// CHK-FPGA-LINK-SRC: 13: llvm-spirv, {12}, spirv, (device-sycl)
207-
// CHK-FPGA-LINK-SRC: 14: backend-compiler, {13}, fpga_aocr, (device-sycl)
208-
// CHK-FPGA-LINK-SRC: 15: clang-offload-wrapper, {14}, object, (device-sycl)
209-
// CHK-FPGA-LINK-SRC-DEFAULT: 16: offload, "host-sycl (x86_64-unknown-linux-gnu)" {9}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {15}, archive
210-
// CHK-FPGA-LINK-SRC-CL: 16: offload, "host-sycl (x86_64-pc-windows-msvc)" {9}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {15}, archive
210+
// CHK-FPGA-LINK-SRC: 9: clang-offload-wrapper, {8}, ir, (host-sycl)
211+
// CHK-FPGA-LINK-SRC: 10: backend, {9}, assembler, (host-sycl)
212+
// CHK-FPGA-LINK-SRC: 11: assembler, {10}, object, (host-sycl)
213+
// CHK-FPGA-LINK-SRC: 12: linker, {11}, archive, (host-sycl)
214+
// CHK-FPGA-LINK-SRC: 13: compiler, {3}, ir, (device-sycl)
215+
// CHK-FPGA-LINK-SRC: 14: linker, {13}, ir, (device-sycl)
216+
// CHK-FPGA-LINK-SRC: 15: sycl-post-link, {14}, ir, (device-sycl)
217+
// CHK-FPGA-LINK-SRC: 16: llvm-spirv, {15}, spirv, (device-sycl)
218+
// CHK-FPGA-LINK-SRC: 17: backend-compiler, {16}, fpga_aocr, (device-sycl)
219+
// CHK-FPGA-LINK-SRC: 18: clang-offload-wrapper, {17}, object, (device-sycl)
220+
// CHK-FPGA-LINK-SRC: 19: offload, "host-sycl (x86_64-unknown-linux-gnu)" {12}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {18}, archive
211221

212222
/// -fintelfpga with -reuse-exe=
213223
// RUN: touch %t.cpp

clang/test/Driver/sycl-offload.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,9 @@
898898
// -std=c++17 override check
899899
// RUN: %clangxx -### -c -fsycl -std=c++14 -xc++ %s 2>&1 | FileCheck -check-prefix=CHECK-STD-OVR %s
900900
// RUN: %clang_cl -### -c -fsycl /std:c++14 -TP %s 2>&1 | FileCheck -check-prefix=CHECK-STD-OVR %s
901-
// CHECK-STD-OVR: clang{{.*}} "-std=c++14"
901+
// CHECK-STD-OVR: clang{{.*}} "-emit-llvm-bc" {{.*}} "-std=c++14"
902+
// CHECK-STD-OVR: clang{{.*}} "-fsyntax-only" {{.*}} "-std=c++14"
903+
// CHECK-STD-OVR: clang{{.*}} "-emit-obj" {{.*}} "-std=c++14"
902904
// CHECK-STD-OVR-NOT: clang{{.*}} "-std=c++17"
903905

904906
// TODO: SYCL specific fail - analyze and enable

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,20 @@ getOrBuild(KernelProgramCache &KPCache, KeyT &&CacheKey, AcquireFT &&Acquire,
218218
}
219219
}
220220

221+
// TODO replace this with a new PI API function
221222
static bool isDeviceBinaryTypeSupported(const context &C,
222223
RT::PiDeviceBinaryType Format) {
224+
// All formats except PI_DEVICE_BINARY_TYPE_SPIRV are supported.
225+
if (Format != PI_DEVICE_BINARY_TYPE_SPIRV)
226+
return true;
227+
223228
const backend ContextBackend =
224229
detail::getSyclObjImpl(C)->getPlugin().getBackend();
225230

226231
// The CUDA backend cannot use SPIR-V
227-
if (ContextBackend == backend::cuda && Format == PI_DEVICE_BINARY_TYPE_SPIRV)
232+
if (ContextBackend == backend::cuda)
228233
return false;
229234

230-
// All formats except PI_DEVICE_BINARY_TYPE_SPIRV are supported.
231-
if (Format != PI_DEVICE_BINARY_TYPE_SPIRV)
232-
return true;
233-
234235
vector_class<device> Devices = C.get_devices();
235236

236237
// Program type is SPIR-V, so we need a device compiler to do JIT.
@@ -240,9 +241,14 @@ static bool isDeviceBinaryTypeSupported(const context &C,
240241
}
241242

242243
// OpenCL 2.1 and greater require clCreateProgramWithIL
243-
if ((ContextBackend == backend::opencl) &&
244-
C.get_platform().get_info<info::platform::version>() >= "2.1")
245-
return true;
244+
if (ContextBackend == backend::opencl) {
245+
std::string ver = C.get_platform().get_info<info::platform::version>();
246+
if (ver.find("OpenCL 1.0") == std::string::npos &&
247+
ver.find("OpenCL 1.1") == std::string::npos &&
248+
ver.find("OpenCL 1.2") == std::string::npos &&
249+
ver.find("OpenCL 2.0") == std::string::npos)
250+
return true;
251+
}
246252

247253
for (const device &D : Devices) {
248254
// We need cl_khr_il_program extension to be present

0 commit comments

Comments
 (0)