Skip to content

Commit 6ecce4f

Browse files
authored
[New offload driver][Device lib] Add SYCL device library files for all targets (#14102)
clang-linker-wrapper is not target-specific. i.e. it is not called for a single target device. It is called only once. Currently, clang-linker-wrapper is called only with device images with spir64 targets. So, the existing approach to capture the first target triple in the list of triples and use it for gathering sycl-device-library files is valid. As we plan to add support for more targets (AOT), we need to gather sycl-device-libraries for all targets. This PR addresses this change. Also, the triple should not be passed to the linker wrapper. The linker wrapper should get the triples from device images. Thanks --------- Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 934b46f commit 6ecce4f

File tree

4 files changed

+30
-54
lines changed

4 files changed

+30
-54
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11005,13 +11005,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1100511005
if (Args.hasArg(options::OPT_v))
1100611006
CmdArgs.push_back("--wrapper-verbose");
1100711007

11008-
// TODO(NOM2): Pass following options to clang-linker-wrapper.
11009-
// Please refer to sycl/doc/design/OffloadDesign.md for details.
11010-
// sycl-device-libraries
11011-
// sycl-device-library-location
11012-
// sycl-post-link-options
11013-
// llvm-spirv-options
11014-
1101511008
if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
1101611009
if (!A->getOption().matches(options::OPT_g0))
1101711010
CmdArgs.push_back("--device-debug");
@@ -11044,12 +11037,14 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1104411037
// Add any SYCL offloading specific options to the clang-linker-wrapper
1104511038
if (C.hasOffloadToolChain<Action::OFK_SYCL>()) {
1104611039
// -sycl-device-libraries=<comma separated list> contains all of the SYCL
11047-
// device specific libraries that are needed. This provides the list of
11048-
// files file only.
11049-
// TODO: This generic list will be populated with only device binaries
11050-
// for spir/spirv. Other targets (AOT and others) can represent a different
11051-
// set of device libraries. We will cross that bridge when we begin to
11052-
// enable the other possible targets.
11040+
// device specific libraries that are needed. This generic list will be
11041+
// populated with device binaries for all target triples in the current
11042+
// compilation flow.
11043+
11044+
// Create a comma separated list to pass along to the linker wrapper.
11045+
SmallString<256> LibList;
11046+
// TODO: TargetTriple should not be used here for creating linker wrapper
11047+
// options. It should also not be passed to the linker wrapper.
1105311048
llvm::Triple TargetTriple;
1105411049
auto ToolChainRange = C.getOffloadToolChains<Action::OFK_SYCL>();
1105511050
for (auto &I :
@@ -11058,38 +11053,24 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1105811053
if (TC->getTriple().isSPIROrSPIRV() &&
1105911054
TC->getTriple().getSubArch() == llvm::Triple::NoSubArch) {
1106011055
TargetTriple = TC->getTriple();
11061-
break;
11056+
SmallVector<std::string, 8> SYCLDeviceLibs;
11057+
bool IsSPIR = TargetTriple.isSPIROrSPIRV();
11058+
bool IsSpirvAOT = TargetTriple.isSPIRAOT();
11059+
bool UseJitLink =
11060+
IsSPIR &&
11061+
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
11062+
options::OPT_fno_sycl_device_lib_jit_link, false);
11063+
bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
11064+
SYCLDeviceLibs = SYCL::getDeviceLibraries(C, TargetTriple, UseAOTLink);
11065+
for (const auto &AddLib : SYCLDeviceLibs) {
11066+
if (LibList.size() > 0)
11067+
LibList += ",";
11068+
LibList += AddLib;
11069+
}
1106211070
}
1106311071
}
11064-
// Pass the device triple to the linker wrapper tool for SYCL offload.
11065-
// Only spir64 or spirv64 is currently passed.
11066-
// TODO(NOM1): Support target triples in a more generic way.
11067-
// TODO(NOM3): Investigate why passing spirv64-unknown-unknown does not
11068-
// work.
11069-
if (TargetTriple.isSPIR())
11070-
CmdArgs.push_back("--triple=spir64");
11071-
else if (TargetTriple.isSPIRV())
11072-
CmdArgs.push_back("--triple=spirv64");
11073-
11074-
SmallVector<std::string, 8> SYCLDeviceLibs;
11075-
auto IsSPIR = TargetTriple.isSPIROrSPIRV();
11076-
bool IsSpirvAOT = TargetTriple.isSPIRAOT();
11077-
bool UseJitLink =
11078-
IsSPIR &&
11079-
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
11080-
options::OPT_fno_sycl_device_lib_jit_link, false);
11081-
bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
11082-
SYCLDeviceLibs = SYCL::getDeviceLibraries(C, TargetTriple, UseAOTLink);
11083-
// Create a comma separated list to pass along to the linker wrapper.
11084-
SmallString<256> LibList;
11085-
for (const auto &AddLib : SYCLDeviceLibs) {
11086-
if (LibList.size() > 0)
11087-
LibList += ",";
11088-
LibList += AddLib;
11089-
}
1109011072
// -sycl-device-libraries=<libs> provides a comma separate list of
1109111073
// libraries to add to the device linking step.
11092-
// SYCL device libraries can be found.
1109311074
if (LibList.size())
1109411075
CmdArgs.push_back(
1109511076
Args.MakeArgString(Twine("-sycl-device-libraries=") + LibList));

clang/test/Driver/linker-wrapper-sycl-win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: system-windows
22

33
/// Check for list of commands for standalone clang-linker-wrapper run for sycl
4-
// RUN: clang-linker-wrapper -sycl-device-library-location=%S/Inputs -sycl-device-libraries=libsycl-crt.new.obj,libsycl-complex.new.obj -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-pc-windows-msvc" "--triple=spir64" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %S/Inputs/test-sycl.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-CMDS %s
4+
// RUN: clang-linker-wrapper -sycl-device-library-location=%S/Inputs -sycl-device-libraries=libsycl-crt.new.obj,libsycl-complex.new.obj -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-pc-windows-msvc" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %S/Inputs/test-sycl.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-CMDS %s
55
// CHK-CMDS: "{{.*}}spirv-to-ir-wrapper.exe" {{.*}} -o [[FIRSTLLVMLINKIN:.*]].bc --llvm-spirv-opts=--spirv-preserve-auxdata --llvm-spirv-opts=--spirv-target-env=SPV-IR --llvm-spirv-opts=--spirv-builtin-format=global
66
// CHK-CMDS-NEXT: "{{.*}}llvm-link.exe" [[FIRSTLLVMLINKIN:.*]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
77
// CHK-CMDS-NEXT: "{{.*}}llvm-link.exe" -only-needed [[FIRSTLLVMLINKOUT]].bc {{.*}}.bc {{.*}}.bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings

clang/test/Driver/sycl-linker-wrapper-image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %clang -cc1 -fsycl-is-device -disable-llvm-passes -triple=spir64-unknown-unknown %s -emit-llvm-bc -o %t.device.bc
55
// RUN: clang-offload-packager -o %t.fat --image=file=%t.device.bc,kind=sycl,triple=spir64-unknown-unknown
66
// RUN: %clang -cc1 %s -triple=x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.fat
7-
// RUN: clang-linker-wrapper --print-wrapped-module --host-triple=x86_64-unknown-linux-gnu --triple=spir64 \
7+
// RUN: clang-linker-wrapper --print-wrapped-module --host-triple=x86_64-unknown-linux-gnu \
88
// RUN: -sycl-device-library-location=%S/Inputs -sycl-post-link-options="-split=auto -symbols" \
99
// RUN: %t.o -o %t.out 2>&1 --linker-path="/usr/bin/ld" | FileCheck %s
1010

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@
2828
// CHK-FLOW-NEXT: clang-offload-packager{{.*}} "-o" "[[PACKOUT:.*]]" "--image=file=[[CC1DEVOUT]],triple=spir64-unknown-unknown,arch=,kind=sycl{{.*}}"
2929
// CHK-FLOW-NEXT: append-file{{.*}} "[[INPUT]]" "--append=[[FOOTER]].h" "--orig-filename=[[INPUT]]" "--output=[[APPENDOUT:.*]]" "--use-include"
3030
// CHK-FLOW-NEXT: clang{{.*}} "-cc1" "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include" "[[HEADER]].h" "-dependency-filter" "[[HEADER]].h" {{.*}} "-fsycl-is-host"{{.*}} "-full-main-file-name" "[[INPUT]]" {{.*}} "--offload-new-driver" {{.*}} "-fembed-offload-object=[[PACKOUT]]" {{.*}} "-o" "[[CC1FINALOUT:.*]]" "-x" "c++" "[[APPENDOUT]]"
31-
// CHK-FLOW-NEXT: clang-linker-wrapper{{.*}} "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64"{{.*}} "--linker-path={{.*}}/ld" {{.*}} "[[CC1FINALOUT]]"
31+
// CHK-FLOW-NEXT: clang-linker-wrapper{{.*}} "--host-triple=x86_64-unknown-linux-gnu"{{.*}} "--linker-path={{.*}}/ld" {{.*}} "[[CC1FINALOUT]]"
3232

3333
/// Verify options passed to clang-linker-wrapper
3434
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
3535
// RUN: --sysroot=%S/Inputs/SYCL -### %s 2>&1 \
3636
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS %s
37-
// WRAPPER_OPTIONS: clang-linker-wrapper{{.*}} "--triple=spir64"
38-
// WRAPPER_OPTIONS-SAME: "-sycl-device-libraries=libsycl-crt.new.o,libsycl-complex.new.o,libsycl-complex-fp64.new.o,libsycl-cmath.new.o,libsycl-cmath-fp64.new.o,libsycl-imf.new.o,libsycl-imf-fp64.new.o,libsycl-imf-bf16.new.o,libsycl-fallback-cassert.new.o,libsycl-fallback-cstring.new.o,libsycl-fallback-complex.new.o,libsycl-fallback-complex-fp64.new.o,libsycl-fallback-cmath.new.o,libsycl-fallback-cmath-fp64.new.o,libsycl-fallback-imf.new.o,libsycl-fallback-imf-fp64.new.o,libsycl-fallback-imf-bf16.new.o,libsycl-itt-user-wrappers.new.o,libsycl-itt-compiler-wrappers.new.o,libsycl-itt-stubs.new.o"
37+
// WRAPPER_OPTIONS: clang-linker-wrapper{{.*}} "-sycl-device-libraries=libsycl-crt.new.o,libsycl-complex.new.o,libsycl-complex-fp64.new.o,libsycl-cmath.new.o,libsycl-cmath-fp64.new.o,libsycl-imf.new.o,libsycl-imf-fp64.new.o,libsycl-imf-bf16.new.o,libsycl-fallback-cassert.new.o,libsycl-fallback-cstring.new.o,libsycl-fallback-complex.new.o,libsycl-fallback-complex-fp64.new.o,libsycl-fallback-cmath.new.o,libsycl-fallback-cmath-fp64.new.o,libsycl-fallback-imf.new.o,libsycl-fallback-imf-fp64.new.o,libsycl-fallback-imf-bf16.new.o,libsycl-itt-user-wrappers.new.o,libsycl-itt-compiler-wrappers.new.o,libsycl-itt-stubs.new.o"
3938
// WRAPPER_OPTIONS-SAME: "-sycl-device-library-location={{.*}}/lib"
4039

4140
/// Verify phases used to generate SPIR-V instead of LLVM-IR
@@ -56,14 +55,12 @@
5655
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
5756
// RUN: -Xspirv-translator -translator-opt -### %s 2>&1 \
5857
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_TRANSLATOR %s
59-
// WRAPPER_OPTIONS_TRANSLATOR: clang-linker-wrapper{{.*}} "--triple=spir64"
60-
// WRAPPER_OPTIONS_TRANSLATOR-SAME: "--llvm-spirv-options={{.*}}-translator-opt{{.*}}"
58+
// WRAPPER_OPTIONS_TRANSLATOR: clang-linker-wrapper{{.*}} "--llvm-spirv-options={{.*}}-translator-opt{{.*}}"
6159

6260
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
6361
// RUN: -Xdevice-post-link -post-link-opt -### %s 2>&1 \
6462
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_POSTLINK %s
65-
// WRAPPER_OPTIONS_POSTLINK: clang-linker-wrapper{{.*}} "--triple=spir64"
66-
// WRAPPER_OPTIONS_POSTLINK-SAME: "--sycl-post-link-options=-post-link-opt -O2 -device-globals -spec-const=native -split=auto -emit-only-kernels-as-entry-points -symbols -emit-exported-symbols -lower-esimd"
63+
// WRAPPER_OPTIONS_POSTLINK: clang-linker-wrapper{{.*}} "--sycl-post-link-options=-post-link-opt -O2 -device-globals -spec-const=native -split=auto -emit-only-kernels-as-entry-points -symbols -emit-exported-symbols -lower-esimd"
6764

6865
// -fsycl-device-only behavior
6966
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
@@ -148,14 +145,12 @@
148145
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
149146
// RUN: -Xsycl-target-backend -backend-opt -### %s 2>&1 \
150147
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_BACKEND %s
151-
// WRAPPER_OPTIONS_BACKEND: clang-linker-wrapper{{.*}} "--triple=spir64"
152-
// WRAPPER_OPTIONS_BACKEND-SAME: "--sycl-backend-compile-options={{.*}}-backend-opt{{.*}}"
148+
// WRAPPER_OPTIONS_BACKEND: clang-linker-wrapper{{.*}} "--sycl-backend-compile-options={{.*}}-backend-opt{{.*}}"
153149

154150
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \
155151
// RUN: -Xsycl-target-linker -link-opt -### %s 2>&1 \
156152
// RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_LINK %s
157-
// WRAPPER_OPTIONS_LINK: clang-linker-wrapper{{.*}} "--triple=spir64"
158-
// WRAPPER_OPTIONS_LINK-SAME: "--sycl-target-link-options={{.*}}-link-opt{{.*}}"
153+
// WRAPPER_OPTIONS_LINK: clang-linker-wrapper{{.*}} "--sycl-target-link-options={{.*}}-link-opt{{.*}}"
159154

160155
/// Test option passing behavior for clang-offload-wrapper options for AOT.
161156
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \

0 commit comments

Comments
 (0)