Skip to content

Commit a310952

Browse files
authored
[SYCL][libdevice] Add IMF support in devicelib (#5999)
To provide support for math APIs and functions, not included in standard or <CL/sycl.hpp>. These math APIs are implemented in "imf" (Intel math functions) SYCL device library. All function names are decorated with __imf_ prefix. These functions may be further categorized into: * Different accuracy implementation for some math functions such as log, exp, cos, sin… * Type cast util functions for float, double, half, bfloat16 * Integer type util functions * SIMD util functions * Half type util functions * Bfloat16 type util functions This PR is 1st of a series of patches to add “imf” SYCL device library, it includes type cast util functions for float, double and integer type util functions. Signed-off-by: jinge90 ge.jin@intel.com
1 parent 8f97fe2 commit a310952

34 files changed

+3606
-22
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4922,9 +4922,9 @@ def fno_sycl_dead_args_optimization : Flag<["-"], "fno-sycl-dead-args-optimizati
49224922
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Disables "
49234923
"elimination of DPC++ dead kernel arguments">;
49244924
def fsycl_device_lib_EQ : CommaJoined<["-"], "fsycl-device-lib=">, Group<sycl_Group>, Flags<[NoXarchOption, CoreOption]>,
4925-
Values<"libc, libm-fp32, libm-fp64, all">, HelpText<"Control inclusion of "
4925+
Values<"libc, libm-fp32, libm-fp64, libimf-fp32, libimf-fp64, all">, HelpText<"Control inclusion of "
49264926
"device libraries into device binary linkage. Valid arguments "
4927-
"are libc, libm-fp32, libm-fp64, all">;
4927+
"are libc, libm-fp32, libm-fp64, libimf-fp32, libimf-fp64, all">;
49284928
def fno_sycl_device_lib_EQ : CommaJoined<["-"], "fno-sycl-device-lib=">, Group<sycl_Group>, Flags<[NoXarchOption, CoreOption]>,
49294929
Values<"libc, libm-fp32, libm-fp64, all">, HelpText<"Control exclusion of "
49304930
"device libraries from device binary linkage. Valid arguments "

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,10 +4775,9 @@ class OffloadingActionBuilder final {
47754775
int NumOfDeviceLibLinked = 0;
47764776
// Currently, all SYCL device libraries will be linked by default. Linkage
47774777
// of "internal" libraries cannot be affected via -fno-sycl-device-lib.
4778-
llvm::StringMap<bool> devicelib_link_info = {{"libc", true},
4779-
{"libm-fp32", true},
4780-
{"libm-fp64", true},
4781-
{"internal", true}};
4778+
llvm::StringMap<bool> devicelib_link_info = {
4779+
{"libc", true}, {"libm-fp32", true}, {"libm-fp64", true},
4780+
{"libimf-fp32", true}, {"libimf-fp64", true}, {"internal", true}};
47824781
if (Arg *A = Args.getLastArg(options::OPT_fsycl_device_lib_EQ,
47834782
options::OPT_fno_sycl_device_lib_EQ)) {
47844783
if (A->getValues().size() == 0)
@@ -4825,6 +4824,8 @@ class OffloadingActionBuilder final {
48254824
#if defined(_WIN32)
48264825
{"libsycl-msvc-math", "libm-fp32"},
48274826
#endif
4827+
{"libsycl-imf", "libimf-fp32"},
4828+
{"libsycl-imf-fp64", "libimf-fp64"}
48284829
};
48294830
// For AOT compilation, we need to link sycl_device_fallback_libs as
48304831
// default too.
@@ -4834,7 +4835,9 @@ class OffloadingActionBuilder final {
48344835
{"libsycl-fallback-complex", "libm-fp32"},
48354836
{"libsycl-fallback-complex-fp64", "libm-fp64"},
48364837
{"libsycl-fallback-cmath", "libm-fp32"},
4837-
{"libsycl-fallback-cmath-fp64", "libm-fp64"}};
4838+
{"libsycl-fallback-cmath-fp64", "libm-fp64"},
4839+
{"libsycl-fallback-imf", "libimf-fp32"},
4840+
{"libsycl-fallback-imf-fp64", "libimf-fp64"}};
48384841
// ITT annotation libraries are linked in separately whenever the device
48394842
// code instrumentation is enabled.
48404843
const SYCLDeviceLibsList sycl_device_annotation_libs = {

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
693693
if (Args.hasArg(options::OPT_fsycl) &&
694694
!Args.hasArg(options::OPT_nolibsycl)) {
695695
CmdArgs.push_back("-lsycl");
696+
CmdArgs.push_back("-lsycl-devicelib-host");
696697
// Use of -fintelfpga implies -lOpenCL.
697698
// FIXME: Adjust to use plugin interface when available.
698699
if (Args.hasArg(options::OPT_fintelfpga))

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
139139
CmdArgs.push_back("-defaultlib:sycld.lib");
140140
else
141141
CmdArgs.push_back("-defaultlib:sycl.lib");
142+
CmdArgs.push_back("-defaultlib:sycl-devicelib-host.lib");
142143
}
143144

144145
for (const auto *A : Args.filtered(options::OPT_foffload_static_lib_EQ))

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
130130
// The list should match pre-built SYCL device library files located in
131131
// compiler package. Once we add or remove any SYCL device library files,
132132
// the list should be updated accordingly.
133-
134133
static llvm::SmallVector<StringRef, 16> SYCLDeviceLibList {
135134
"crt", "cmath", "cmath-fp64", "complex", "complex-fp64",
136135
#if defined(_WIN32)
137136
"msvc-math",
138137
#endif
139-
"itt-compiler-wrappers", "itt-stubs", "itt-user-wrappers",
140-
"fallback-cassert", "fallback-cstring", "fallback-cmath",
141-
"fallback-cmath-fp64", "fallback-complex", "fallback-complex-fp64"
138+
"imf", "imf-fp64", "itt-compiler-wrappers", "itt-stubs",
139+
"itt-user-wrappers", "fallback-cassert", "fallback-cstring",
140+
"fallback-cmath", "fallback-cmath-fp64", "fallback-complex",
141+
"fallback-complex-fp64", "fallback-imf", "fallback-imf-fp64"
142142
};
143143

144144
const char *SYCL::Linker::constructLLVMLinkCommand(

clang/test/Driver/Inputs/SYCL-windows/lib/libsycl-fallback-imf-fp64.obj

Whitespace-only changes.

clang/test/Driver/Inputs/SYCL-windows/lib/libsycl-fallback-imf.obj

Whitespace-only changes.

clang/test/Driver/Inputs/SYCL-windows/lib/libsycl-imf-fp64.obj

Whitespace-only changes.

clang/test/Driver/Inputs/SYCL-windows/lib/libsycl-imf.obj

Whitespace-only changes.

clang/test/Driver/Inputs/SYCL-windows/lib/libsycl-msvc-math.obj

Whitespace-only changes.

0 commit comments

Comments
 (0)