Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3b2ba9f
[SYCL] Embed required fallback spv into final executable
jinge90 Nov 13, 2024
1a51b0b
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 13, 2024
78a7013
remove function redefinition
jinge90 Nov 13, 2024
243f759
fix clang format
jinge90 Nov 13, 2024
349d7c2
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 13, 2024
9a25780
Pass devicelib path to sycl-post-link
jinge90 Nov 13, 2024
aa62091
pass sycl device lib spv dir to sycl-post-link in clang linker wrapper
jinge90 Nov 14, 2024
fd8bea1
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 14, 2024
b9b53ee
Remove sycl devicelib require mask collection
jinge90 Nov 14, 2024
5e907b2
fix clang formath
jinge90 Nov 14, 2024
aff431a
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 15, 2024
3595525
Embed required fallback spv in sycl-post-link
jinge90 Nov 18, 2024
7a05845
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 18, 2024
79d50b8
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 19, 2024
4be3ac8
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 20, 2024
f0ecc0a
Make sycl runtime to be compatible with binary built with legacy
jinge90 Nov 21, 2024
352eea3
fix bug when writing required devicelib extension to image
jinge90 Nov 21, 2024
59640a4
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 21, 2024
2976cde
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 25, 2024
331644e
extract required spv binary from exe
jinge90 Nov 25, 2024
69c6f7d
workaround for std::aligned_alloc
jinge90 Nov 25, 2024
07656ea
fix typo
jinge90 Nov 25, 2024
10ecbd0
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 26, 2024
77b0fbf
fix sycl-linker-wrapper-image.cpp lit failure
jinge90 Nov 26, 2024
8878ffc
fix sycl-post-link-options lit failure
jinge90 Nov 26, 2024
fce23f6
fix sycl-offload-new-driver.c lit failure
jinge90 Nov 26, 2024
df64058
don't pass spv dir path in AOT or devicelib is disabled
jinge90 Nov 26, 2024
22757c7
skip embeding spv when empty spv loc is specified
jinge90 Nov 26, 2024
1902e2e
fix build error
jinge90 Nov 26, 2024
353de1b
remove lit check for sycl device lib require mask
jinge90 Nov 26, 2024
8bbe976
fix sycl-post-link-options-win lit failure
jinge90 Nov 26, 2024
217daf2
no need to pass spv dir in AOT
jinge90 Nov 26, 2024
37e23f2
sync to latest sycl branch
jinge90 Nov 26, 2024
c1dc677
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Nov 27, 2024
094bcfc
fix new offload driver lit
jinge90 Nov 27, 2024
c310a45
check null ptr returned by aligned_alloc
jinge90 Nov 27, 2024
98a7e5c
support bfloat16 native spv
jinge90 Nov 27, 2024
0035e74
fix clang format
jinge90 Nov 27, 2024
230c8d9
fix incorrect usage of _aligned_malloc
jinge90 Nov 27, 2024
157fbda
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 2, 2024
3543b2d
remove sycl devicelib required binary property usage
jinge90 Dec 2, 2024
2e6387c
rename device-lib-spv-dir to device-lib-dir
jinge90 Dec 2, 2024
fa9e6b5
Embed required devicelib modules as device image
jinge90 Dec 2, 2024
02a84d4
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 2, 2024
c889b30
fix typo
jinge90 Dec 3, 2024
7004d14
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 3, 2024
768c110
add device image map in ProgramManager
jinge90 Dec 3, 2024
3930cbc
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 3, 2024
c51597f
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 4, 2024
42f4db5
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 4, 2024
57fb543
link device lib image when required
jinge90 Dec 4, 2024
2427553
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 4, 2024
e88fb52
add __devicelib_* function call as imported symbol
jinge90 Dec 6, 2024
1b83073
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 6, 2024
aba8d30
Use sycl shared library mechanism to link required fallback device li…
jinge90 Dec 6, 2024
1cc7a0d
link required fallback spv as shared libraries
jinge90 Dec 6, 2024
9e65b87
Merge remote-tracking branch 'upstream/sycl' into embed_fallback_svp
jinge90 Dec 6, 2024
84cd4da
sync with latest intel/llvm
jinge90 Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10952,6 +10952,7 @@ static void getNonTripleBasedSYCLPostLinkOpts(const ToolChain &TC,
const JobAction &JA,
const llvm::opt::ArgList &TCArgs,
ArgStringList &PostLinkArgs) {

// See if device code splitting is requested
if (Arg *A = TCArgs.getLastArg(options::OPT_fsycl_device_code_split_EQ)) {
auto CodeSplitValue = StringRef(A->getValue());
Expand All @@ -10977,6 +10978,39 @@ static void getNonTripleBasedSYCLPostLinkOpts(const ToolChain &TC,

if (allowDeviceImageDependencies(TCArgs))
addArgs(PostLinkArgs, TCArgs, {"-allow-device-image-dependencies"});

bool DeviceLibDisable = false;
Arg *DeviceLibArg = TCArgs.getLastArg(options::OPT_fsycl_device_lib_EQ,
options::OPT_fno_sycl_device_lib_EQ);
if (DeviceLibArg &&
DeviceLibArg->getOption().matches(options::OPT_fno_sycl_device_lib_EQ)) {
for (StringRef Val : DeviceLibArg->getValues()) {
if (Val == "all") {
DeviceLibDisable = true;
break;
}
}
}

// Fallback spv is NOT involved in AOT compilation or
// '-fno-sycl-device-lib=all' is applied by user explicitly.
if (TC.getTriple().isSPIROrSPIRV() && !TC.getTriple().isSPIRAOT() &&
!DeviceLibDisable) {
SYCLInstallationDetector SYCLInstall(TC.getDriver());
SmallVector<SmallString<128>, 4> DeviceLibLocCandidates;
SmallString<128> FallbackAssertName("libsycl-fallback-cassert.bc");
SYCLInstall.getSYCLDeviceLibPath(DeviceLibLocCandidates);
for (const auto &DeviceLibLoc : DeviceLibLocCandidates) {
SmallString<128> FullLibName(DeviceLibLoc);
llvm::sys::path::append(FullLibName, FallbackAssertName);
if (llvm::sys::fs::exists(FullLibName)) {
SmallString<128> SYCLDeviceLibDir("--device-lib-dir=");
SYCLDeviceLibDir += DeviceLibLoc.str();
addArgs(PostLinkArgs, TCArgs, {SYCLDeviceLibDir.str()});
break;
}
}
}
}

// On Intel targets we don't need non-kernel functions as entry points,
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/sycl-post-link-options-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %clangxx -### --target=x86_64-pc-windows-msvc -fsycl \
// RUN: -Xdevice-post-link -O0 %s 2>&1 \
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT_OLD %s
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "-properties" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-emit-imported-symbols" "-split-esimd" "-lower-esimd" "-O0"
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "--device-lib-dir={{.*}}" "-properties" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-emit-imported-symbols" "-split-esimd" "-lower-esimd" "-O0"
// -------
// Generate .o file as linker wrapper input.
//
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/sycl-post-link-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl -### \
// RUN: --no-offload-new-driver -Xdevice-post-link -O0 %s 2>&1 \
// RUN: | FileCheck -check-prefix OPTIONS_POSTLINK_JIT_OLD %s
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "-properties" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-emit-imported-symbols" "-split-esimd" "-lower-esimd" "-O0"
// OPTIONS_POSTLINK_JIT_OLD: sycl-post-link{{.*}} "-O2" "-device-globals" "--device-lib-dir={{.*}}" "-properties" "-spec-const=native" "-split=auto" "-emit-only-kernels-as-entry-points" "-emit-param-info" "-symbols" "-emit-exported-symbols" "-emit-imported-symbols" "-split-esimd" "-lower-esimd" "-O0"
//
// Generate .o file as linker wrapper input.
//
Expand Down
10 changes: 10 additions & 0 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ runSYCLPostLinkTool(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
SmallVector<StringRef, 8> CmdArgs;
CmdArgs.push_back(*SYCLPostLinkPath);
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
Arg *SYCLDeviceLibLoc = Args.getLastArg(OPT_sycl_device_library_location_EQ);
if (SYCLDeviceLibLoc && !Triple.isSPIRAOT()) {
std::string SYCLDeviceLibLocParam = SYCLDeviceLibLoc->getValue();
std::string AssertDeviceLibLoc =
SYCLDeviceLibLocParam + "/libsycl-fallback-cassert.bc";
if (llvm::sys::fs::exists(AssertDeviceLibLoc)) {
SYCLDeviceLibLocParam = "--device-lib-dir=" + SYCLDeviceLibLocParam;
CmdArgs.push_back(Args.MakeArgString(StringRef(SYCLDeviceLibLocParam)));
}
}
getTripleBasedSYCLPostLinkOpts(Args, CmdArgs, Triple);
StringRef SYCLPostLinkOptions;
if (Arg *A = Args.getLastArg(OPT_sycl_post_link_options_EQ))
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/ComputeModuleRuntimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "llvm/ADT/SetVector.h"
#include "llvm/SYCLLowerIR/ModuleSplitter.h"
#include "llvm/SYCLLowerIR/SYCLDeviceLibReqMask.h"
#include "llvm/Support/PropertySetIO.h"
#include <string>
namespace llvm {
Expand All @@ -36,6 +37,9 @@ PropSetRegTy computeModuleProperties(const Module &M,
const EntryPointSet &EntryPoints,
const GlobalBinImageProps &GlobProps);

PropSetRegTy computeSYCLDeviceLibProperties(const Module &M,
std::string &SYCLDeviceLibName);

std::string computeModuleSymbolTable(const Module &M,
const EntryPointSet &EntryPoints);

Expand Down
6 changes: 5 additions & 1 deletion llvm/include/llvm/SYCLLowerIR/SYCLDeviceLibReqMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#pragma once

#include <cstdint>
#include <string>
#include <vector>

namespace llvm {

Expand All @@ -39,5 +41,7 @@ enum class DeviceLibExt : std::uint32_t {
};

uint32_t getSYCLDeviceLibReqMask(const Module &M);

void getSYCLDeviceLibReqNames(unsigned int ReqMask,
std::vector<std::string> &ReqNames);
unsigned int getSYCLDeviceLibMeta(std::string &DeviceLibFn);
} // namespace llvm
1 change: 1 addition & 0 deletions llvm/include/llvm/Support/PropertySetIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class PropertySetRegistry {
static constexpr char SYCL_SPEC_CONSTANTS_DEFAULT_VALUES[] =
"SYCL/specialization constants default values";
static constexpr char SYCL_DEVICELIB_REQ_MASK[] = "SYCL/devicelib req mask";
static constexpr char SYCL_DEVICELIB_METADATA[] = "SYCL/devicelib metadata";
static constexpr char SYCL_KERNEL_PARAM_OPT_INFO[] = "SYCL/kernel param opt";
static constexpr char SYCL_PROGRAM_METADATA[] = "SYCL/program metadata";
static constexpr char SYCL_MISC_PROP[] = "SYCL/misc properties";
Expand Down
33 changes: 27 additions & 6 deletions llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,37 @@ std::optional<T> getKernelSingleEltMetadata(const Function &Func,
return std::nullopt;
}

PropSetRegTy computeSYCLDeviceLibProperties(const Module &M,
std::string &SYCLDeviceLibName) {
PropSetRegTy PropSet;

{
auto SYCLDeviceLibMeta = getSYCLDeviceLibMeta(SYCLDeviceLibName);
std::map<StringRef, unsigned int> RMEntry = {
{"DeviceLibMetaData", SYCLDeviceLibMeta}};
PropSet.add(PropSetRegTy::SYCL_DEVICELIB_METADATA, RMEntry);
}

{
for (const auto &F : M.functions()) {
if (!F.getName().starts_with("__devicelib_") || F.isDeclaration())
continue;
if (F.getCallingConv() == CallingConv::SPIR_FUNC) {
PropSet.add(PropSetRegTy::SYCL_EXPORTED_SYMBOLS, F.getName(),
/*PropVal=*/true);
}
}
}

return PropSet;
}

PropSetRegTy computeModuleProperties(const Module &M,
const EntryPointSet &EntryPoints,
const GlobalBinImageProps &GlobProps) {

PropSetRegTy PropSet;
{
uint32_t MRMask = getSYCLDeviceLibReqMask(M);
std::map<StringRef, uint32_t> RMEntry = {{"DeviceLibReqMask", MRMask}};
PropSet.add(PropSetRegTy::SYCL_DEVICELIB_REQ_MASK, RMEntry);
}

{
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS,
computeDeviceRequirements(M, EntryPoints).asMap());
Expand Down Expand Up @@ -461,7 +482,7 @@ PropSetRegTy computeModuleProperties(const Module &M,
}

PropSet.add(PropSetRegTy::SYCL_VIRTUAL_FUNCTIONS,
"uses-virtual-functions-set", AllSets);
"uses-virtual-functions-set", AllSets);
}
}

Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/SYCLLowerIR/ModuleSplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,9 @@ splitSYCLModule(std::unique_ptr<Module> M, ModuleSplitterSettings Settings) {
}

bool canBeImportedFunction(const Function &F) {

if (F.getName().starts_with("__devicelib_") && F.isDeclaration())
return true;
// It may be theoretically possible to determine what is importable
// based solely on function F, but the "SYCL/imported symbols"
// property list MUST NOT have any imported symbols that are not supplied
Expand Down
74 changes: 74 additions & 0 deletions llvm/lib/SYCLLowerIR/SYCLDeviceLibReqMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,28 @@ uint32_t getDeviceLibBits(const std::string &FuncName) {

} // namespace

static std::unordered_map<DeviceLibExt, std::vector<const char *>>
SYCLDeviceLibFn = {
{DeviceLibExt::cl_intel_devicelib_assert,
{"libsycl-fallback-cassert.bc"}},
{DeviceLibExt::cl_intel_devicelib_math, {"libsycl-fallback-cmath.bc"}},
{DeviceLibExt::cl_intel_devicelib_math_fp64,
{"libsycl-fallback-cmath-fp64.bc"}},
{DeviceLibExt::cl_intel_devicelib_complex,
{"libsycl-fallback-complex.bc"}},
{DeviceLibExt::cl_intel_devicelib_complex_fp64,
{"libsycl-fallback-complex-fp64.bc"}},
{DeviceLibExt::cl_intel_devicelib_cstring,
{"libsycl-fallback-cstring.bc"}},
{DeviceLibExt::cl_intel_devicelib_imf, {"libsycl-fallback-imf.bc"}},
{DeviceLibExt::cl_intel_devicelib_imf_fp64,
{"libsycl-fallback-imf-fp64.bc"}},
{DeviceLibExt::cl_intel_devicelib_imf_bf16,
{"libsycl-fallback-imf-bf16.bc"}},
{DeviceLibExt::cl_intel_devicelib_bfloat16,
{"libsycl-fallback-bfloat16.bc", "libsycl-native-bfloat16.bc"}},
};

// For each device image module, we go through all functions which meets
// 1. The function name has prefix "__devicelib_"
// 2. The function is declaration which means it doesn't have function body
Expand All @@ -775,3 +797,55 @@ uint32_t llvm::getSYCLDeviceLibReqMask(const Module &M) {
}
return ReqMask;
}

void llvm::getSYCLDeviceLibReqNames(unsigned int ReqMask,
std::vector<std::string> &ReqNames) {
DeviceLibExt DeviceLibExts[] = {DeviceLibExt::cl_intel_devicelib_assert,
DeviceLibExt::cl_intel_devicelib_math,
DeviceLibExt::cl_intel_devicelib_math_fp64,
DeviceLibExt::cl_intel_devicelib_complex,
DeviceLibExt::cl_intel_devicelib_complex_fp64,
DeviceLibExt::cl_intel_devicelib_cstring,
DeviceLibExt::cl_intel_devicelib_imf,
DeviceLibExt::cl_intel_devicelib_imf_fp64,
DeviceLibExt::cl_intel_devicelib_imf_bf16,
DeviceLibExt::cl_intel_devicelib_bfloat16};

unsigned int Temp;
for (auto Ext : DeviceLibExts) {
Temp =
0x1 << (static_cast<size_t>(Ext) -
static_cast<size_t>(DeviceLibExt::cl_intel_devicelib_assert));
if (Temp & ReqMask) {
for (auto Fn : SYCLDeviceLibFn[Ext])
ReqNames.push_back(std::string(Fn));
}
}
}

unsigned int llvm::getSYCLDeviceLibMeta(std::string &DeviceLibFn) {
DeviceLibExt DeviceLibExts[] = {DeviceLibExt::cl_intel_devicelib_assert,
DeviceLibExt::cl_intel_devicelib_math,
DeviceLibExt::cl_intel_devicelib_math_fp64,
DeviceLibExt::cl_intel_devicelib_complex,
DeviceLibExt::cl_intel_devicelib_complex_fp64,
DeviceLibExt::cl_intel_devicelib_cstring,
DeviceLibExt::cl_intel_devicelib_imf,
DeviceLibExt::cl_intel_devicelib_imf_fp64,
DeviceLibExt::cl_intel_devicelib_imf_bf16,
DeviceLibExt::cl_intel_devicelib_bfloat16};

unsigned int DeviceLibMeta = 0;
for (auto Ext : DeviceLibExts) {
for (auto Fn : SYCLDeviceLibFn[Ext]) {
if (DeviceLibFn == Fn) {
DeviceLibMeta = static_cast<unsigned int>(Ext);
if (DeviceLibFn == "libsycl-native-bfloat16.bc")
DeviceLibMeta |= 0x80000000;
break;
}
}
}

return DeviceLibMeta;
}
1 change: 1 addition & 0 deletions llvm/lib/Support/PropertySetIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void PropertyValue::copy(const PropertyValue &P) {

constexpr char PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS[];
constexpr char PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK[];
constexpr char PropertySetRegistry::SYCL_DEVICELIB_METADATA[];
constexpr char PropertySetRegistry::SYCL_SPEC_CONSTANTS_DEFAULT_VALUES[];
constexpr char PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO[];
constexpr char PropertySetRegistry::SYCL_PROGRAM_METADATA[];
Expand Down
Loading
Loading