Skip to content

Commit 7c48cf7

Browse files
committed
[New offload driver][Device lib] Add SYCL device library files for all targets
Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 692c1d6 commit 7c48cf7

File tree

4 files changed

+28
-50
lines changed

4 files changed

+28
-50
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

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

10963-
// TODO(NOM2): Pass following options to clang-linker-wrapper.
10964-
// Please refer to sycl/doc/design/OffloadDesign.md for details.
10965-
// sycl-device-libraries
10966-
// sycl-device-library-location
10967-
// sycl-post-link-options
10968-
// llvm-spirv-options
10969-
1097010963
if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
1097110964
if (!A->getOption().matches(options::OPT_g0))
1097210965
CmdArgs.push_back("--device-debug");
@@ -10999,12 +10992,14 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1099910992
// Add any SYCL offloading specific options to the clang-linker-wrapper
1100010993
if (C.hasOffloadToolChain<Action::OFK_SYCL>()) {
1100110994
// -sycl-device-libraries=<comma separated list> contains all of the SYCL
11002-
// device specific libraries that are needed. This provides the list of
11003-
// files file only.
11004-
// TODO: This generic list will be populated with only device binaries
11005-
// for spir/spirv. Other targets (AOT and others) can represent a different
11006-
// set of device libraries. We will cross that bridge when we begin to
11007-
// enable the other possible targets.
10995+
// device specific libraries that are needed. This generic list will be
10996+
// populated with device binaries for all target triples in the current
10997+
// compilation flow.
10998+
10999+
// Create a comma separated list to pass along to the linker wrapper.
11000+
SmallString<256> LibList;
11001+
// TODO: TargetTriple should not be used here for creating linker wrapper
11002+
// options. It should also not be passed to the linker wrapper.
1100811003
llvm::Triple TargetTriple;
1100911004
auto ToolChainRange = C.getOffloadToolChains<Action::OFK_SYCL>();
1101011005
for (auto &I :
@@ -11013,38 +11008,24 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1101311008
if (TC->getTriple().isSPIROrSPIRV() &&
1101411009
TC->getTriple().getSubArch() == llvm::Triple::NoSubArch) {
1101511010
TargetTriple = TC->getTriple();
11016-
break;
11011+
SmallVector<std::string, 8> SYCLDeviceLibs;
11012+
auto IsSPIR = TargetTriple.isSPIROrSPIRV();
11013+
bool IsSpirvAOT = TargetTriple.isSPIRAOT();
11014+
bool UseJitLink =
11015+
IsSPIR &&
11016+
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
11017+
options::OPT_fno_sycl_device_lib_jit_link, false);
11018+
bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
11019+
SYCLDeviceLibs = SYCL::getDeviceLibraries(C, TargetTriple, UseAOTLink);
11020+
for (const auto &AddLib : SYCLDeviceLibs) {
11021+
if (LibList.size() > 0)
11022+
LibList += ",";
11023+
LibList += AddLib;
11024+
}
1101711025
}
1101811026
}
11019-
// Pass the device triple to the linker wrapper tool for SYCL offload.
11020-
// Only spir64 or spirv64 is currently passed.
11021-
// TODO(NOM1): Support target triples in a more generic way.
11022-
// TODO(NOM3): Investigate why passing spirv64-unknown-unknown does not
11023-
// work.
11024-
if (TargetTriple.isSPIR())
11025-
CmdArgs.push_back("--triple=spir64");
11026-
else if (TargetTriple.isSPIRV())
11027-
CmdArgs.push_back("--triple=spirv64");
11028-
11029-
SmallVector<std::string, 8> SYCLDeviceLibs;
11030-
auto IsSPIR = TargetTriple.isSPIROrSPIRV();
11031-
bool IsSpirvAOT = TargetTriple.isSPIRAOT();
11032-
bool UseJitLink =
11033-
IsSPIR &&
11034-
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
11035-
options::OPT_fno_sycl_device_lib_jit_link, false);
11036-
bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
11037-
SYCLDeviceLibs = SYCL::getDeviceLibraries(C, TargetTriple, UseAOTLink);
11038-
// Create a comma separated list to pass along to the linker wrapper.
11039-
SmallString<256> LibList;
11040-
for (const auto &AddLib : SYCLDeviceLibs) {
11041-
if (LibList.size() > 0)
11042-
LibList += ",";
11043-
LibList += AddLib;
11044-
}
1104511027
// -sycl-device-libraries=<libs> provides a comma separate list of
1104611028
// libraries to add to the device linking step.
11047-
// SYCL device libraries can be found.
1104811029
if (LibList.size())
1104911030
CmdArgs.push_back(
1105011031
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: 4 additions & 7 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 -spec-const=native -device-globals -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -split-esimd -lower-esimd"
63+
// WRAPPER_OPTIONS_POSTLINK: clang-linker-wrapper{{.*}} "--sycl-post-link-options=-post-link-opt -O2 -spec-const=native -device-globals -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -split-esimd -lower-esimd"
6764

6865
// -fsycl-device-only behavior
6966
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \

0 commit comments

Comments
 (0)