Skip to content

Commit 3543b2d

Browse files
committed
remove sycl devicelib required binary property usage
Signed-off-by: jinge90 <[email protected]>
1 parent 157fbda commit 3543b2d

File tree

15 files changed

+109
-399
lines changed

15 files changed

+109
-399
lines changed

llvm/include/llvm/SYCLLowerIR/ComputeModuleRuntimeInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ using EntryPointSet = SetVector<Function *>;
3434

3535
PropSetRegTy computeModuleProperties(const Module &M,
3636
const EntryPointSet &EntryPoints,
37-
const GlobalBinImageProps &GlobProps,
38-
const StringRef &DeviceLibSPVLoc);
37+
const GlobalBinImageProps &GlobProps);
3938

4039
std::string computeModuleSymbolTable(const Module &M,
4140
const EntryPointSet &EntryPoints);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===----- SYCLRequiredDeviceLibs.h - get SYCL devicelib required Info ----===//
1+
//===----- SYCLDeviceLibReqMask.h - get SYCL devicelib required Info -----=-==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -16,8 +16,6 @@
1616

1717
#pragma once
1818

19-
#include "llvm/ADT/SetVector.h"
20-
#include "llvm/ADT/StringRef.h"
2119
#include <cstdint>
2220

2321
namespace llvm {
@@ -40,27 +38,6 @@ enum class DeviceLibExt : std::uint32_t {
4038
cl_intel_devicelib_bfloat16,
4139
};
4240

43-
enum class DeviceLibIsNative : std::uint32_t { Yes, No, Ignore };
44-
45-
struct SYCLDeviceLibSPVMeta {
46-
DeviceLibExt SPVExt;
47-
const char *SPVFileName;
48-
DeviceLibIsNative IsNative;
49-
};
50-
51-
struct SYCLDeviceLibSPVBinary {
52-
typedef uint8_t value_type;
53-
value_type *SPVRawBytes;
54-
size_t SPVBytesNum;
55-
SYCLDeviceLibSPVBinary(value_type *RawB, size_t BNum) {
56-
SPVRawBytes = RawB;
57-
SPVBytesNum = BNum;
58-
}
59-
value_type *data() const { return SPVRawBytes; }
60-
size_t size() const { return SPVBytesNum; }
61-
};
62-
63-
void getRequiredSYCLDeviceLibs(const Module &M,
64-
SmallVector<SYCLDeviceLibSPVMeta, 16> &ReqLibs);
41+
uint32_t getSYCLDeviceLibReqMask(const Module &M);
6542

6643
} // namespace llvm

llvm/include/llvm/Support/PropertySetIO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class PropertySetRegistry {
199199
"SYCL/specialization constants";
200200
static constexpr char SYCL_SPEC_CONSTANTS_DEFAULT_VALUES[] =
201201
"SYCL/specialization constants default values";
202-
static constexpr char SYCL_DEVICELIB_REQ_BINS[] = "SYCL/devicelib req bins";
202+
static constexpr char SYCL_DEVICELIB_REQ_MASK[] = "SYCL/devicelib req mask";
203203
static constexpr char SYCL_KERNEL_PARAM_OPT_INFO[] = "SYCL/kernel param opt";
204204
static constexpr char SYCL_PROGRAM_METADATA[] = "SYCL/program metadata";
205205
static constexpr char SYCL_MISC_PROP[] = "SYCL/misc properties";

llvm/lib/SYCLLowerIR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ add_llvm_component_library(LLVMSYCLLowerIR
6161
SYCLAddOptLevelAttribute.cpp
6262
SYCLConditionalCallOnDevice.cpp
6363
SYCLCreateNVVMAnnotations.cpp
64-
SYCLRequiredDeviceLibs.cpp
64+
SYCLDeviceLibReqMask.cpp
6565
SYCLDeviceRequirements.cpp
6666
SYCLKernelParamOptInfo.cpp
6767
SYCLJointMatrixTransform.cpp

llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
#include "llvm/SYCLLowerIR/DeviceGlobals.h"
1818
#include "llvm/SYCLLowerIR/HostPipes.h"
1919
#include "llvm/SYCLLowerIR/ModuleSplitter.h"
20+
#include "llvm/SYCLLowerIR/SYCLDeviceLibReqMask.h"
2021
#include "llvm/SYCLLowerIR/SYCLKernelParamOptInfo.h"
21-
#include "llvm/SYCLLowerIR/SYCLRequiredDeviceLibs.h"
2222
#include "llvm/SYCLLowerIR/SYCLUtils.h"
2323
#include "llvm/SYCLLowerIR/SpecConstants.h"
24-
#include "llvm/Support/FileSystem.h"
25-
#include "llvm/Support/MemoryBuffer.h"
2624
#include <queue>
2725
#include <unordered_set>
28-
2926
#ifndef NDEBUG
3027
constexpr int DebugModuleProps = 0;
3128
#endif
@@ -155,59 +152,14 @@ std::optional<T> getKernelSingleEltMetadata(const Function &Func,
155152

156153
PropSetRegTy computeModuleProperties(const Module &M,
157154
const EntryPointSet &EntryPoints,
158-
const GlobalBinImageProps &GlobProps,
159-
const StringRef &DeviceLibSPVLoc) {
155+
const GlobalBinImageProps &GlobProps) {
160156

161157
PropSetRegTy PropSet;
162-
// If sycl-post-link doesn't specify a valid fallback spv path, the param
163-
// 'DeviceLibSPVLoc' is set to an empty string.
164-
if (!DeviceLibSPVLoc.empty()) {
165-
SmallVector<llvm::SYCLDeviceLibSPVMeta, 16> RequiredLibs;
166-
llvm::getRequiredSYCLDeviceLibs(M, RequiredLibs);
167-
for (auto ExtMeta : RequiredLibs) {
168-
std::string SPVPath =
169-
DeviceLibSPVLoc.str() + "/" + std::string(ExtMeta.SPVFileName);
170-
if (!llvm::sys::fs::exists(SPVPath))
171-
continue;
172-
173-
auto SPVMB = llvm::MemoryBuffer::getFile(SPVPath);
174-
if (!SPVMB)
175-
continue;
176-
177-
size_t SPVSize = (*SPVMB)->getBufferSize();
178-
// std::aligned_alloc is not available in some pre-ci Windows machine.
179-
#if defined(_WIN32) || defined(_WIN64)
180-
uint8_t *SPVBuffer = reinterpret_cast<uint8_t *>(
181-
_aligned_malloc(SPVSize + sizeof(uint32_t) * 2, alignof(uint32_t)));
182-
#else
183-
uint8_t *SPVBuffer = reinterpret_cast<uint8_t *>(std::aligned_alloc(
184-
alignof(uint32_t), SPVSize + sizeof(uint32_t) * 2));
185-
#endif
186-
187-
if (!SPVBuffer)
188-
continue;
189-
190-
// The data embedded consists of 3 parts, overall layout is following:
191-
// |--devicelib ext(4 byte)--|--IsNative Flag(4 byte)--|--spv raw data--|
192-
*(reinterpret_cast<uint32_t *>(SPVBuffer)) =
193-
static_cast<uint32_t>(ExtMeta.SPVExt);
194-
195-
*(reinterpret_cast<uint32_t *>(SPVBuffer + sizeof(uint32_t))) =
196-
static_cast<uint32_t>(ExtMeta.IsNative);
197-
std::memcpy(SPVBuffer + sizeof(uint32_t) * 2, (*SPVMB)->getBufferStart(),
198-
SPVSize);
199-
llvm::SYCLDeviceLibSPVBinary SPVBinaryObj(SPVBuffer,
200-
SPVSize + sizeof(uint32_t) * 2);
201-
PropSet.add(PropSetRegTy::SYCL_DEVICELIB_REQ_BINS, ExtMeta.SPVFileName,
202-
SPVBinaryObj);
203-
#if defined(_WIN32) || defined(_WIN64)
204-
_aligned_free(SPVBuffer);
205-
#else
206-
std::free(SPVBuffer);
207-
#endif
208-
}
158+
{
159+
uint32_t MRMask = getSYCLDeviceLibReqMask(M);
160+
std::map<StringRef, uint32_t> RMEntry = {{"DeviceLibReqMask", MRMask}};
161+
PropSet.add(PropSetRegTy::SYCL_DEVICELIB_REQ_MASK, RMEntry);
209162
}
210-
211163
{
212164
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS,
213165
computeDeviceRequirements(M, EntryPoints).asMap());
@@ -501,7 +453,7 @@ PropSetRegTy computeModuleProperties(const Module &M,
501453
}
502454

503455
PropSet.add(PropSetRegTy::SYCL_VIRTUAL_FUNCTIONS,
504-
"uses-virtual-functions-set", AllSets);
456+
"uses-virtual-functions-set", AllSets);
505457
}
506458
}
507459

llvm/lib/SYCLLowerIR/SYCLRequiredDeviceLibs.cpp renamed to llvm/lib/SYCLLowerIR/SYCLDeviceLibReqMask.cpp

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==---- SYCLRequiredDeviceLibs.cpp - get SYCL devicelib required Info -----==//
1+
//==----- SYCLDeviceLibReqMask.cpp - get SYCL devicelib required Info ------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -14,8 +14,7 @@
1414
// SYCL runtime later.
1515
//===----------------------------------------------------------------------===//
1616

17-
#include "llvm/SYCLLowerIR/SYCLRequiredDeviceLibs.h"
18-
#include "llvm/ADT/SmallSet.h"
17+
#include "llvm/SYCLLowerIR/SYCLDeviceLibReqMask.h"
1918
#include "llvm/IR/Module.h"
2019
#include "llvm/TargetParser/Triple.h"
2120

@@ -733,73 +732,46 @@ SYCLDeviceLibFuncMap SDLMap = {
733732
DeviceLibExt::cl_intel_devicelib_bfloat16},
734733
};
735734

736-
} // namespace
737-
738-
// One devicelib extension may correspond to multiple spv files, following
739-
// map stores corresponding index values in SPVMetaList for an extension.
740-
static std::unordered_map<DeviceLibExt, std::vector<size_t>>
741-
DeviceLibSPVExtMap = {{DeviceLibExt::cl_intel_devicelib_assert, {0}},
742-
{DeviceLibExt::cl_intel_devicelib_math, {1}},
743-
{DeviceLibExt::cl_intel_devicelib_math_fp64, {2}},
744-
{DeviceLibExt::cl_intel_devicelib_complex, {3}},
745-
{DeviceLibExt::cl_intel_devicelib_complex_fp64, {4}},
746-
{DeviceLibExt::cl_intel_devicelib_cstring, {5}},
747-
{DeviceLibExt::cl_intel_devicelib_imf, {6}},
748-
{DeviceLibExt::cl_intel_devicelib_imf_fp64, {7}},
749-
{DeviceLibExt::cl_intel_devicelib_imf_bf16, {8}},
750-
{DeviceLibExt::cl_intel_devicelib_bfloat16, {9, 10}}};
735+
// Each fallback device library corresponds to one bit in "require mask" which
736+
// is an unsigned int32. getDeviceLibBit checks which fallback device library
737+
// is required for FuncName and returns the corresponding bit. The corresponding
738+
// mask for each fallback device library is:
739+
// cl_intel_devicelib_assert: 0x1
740+
// cl_intel_devicelib_math: 0x2
741+
// cl_intel_devicelib_math_fp64: 0x4
742+
// cl_intel_devicelib_complex: 0x8
743+
// cl_intel_devicelib_complex_fp64: 0x10
744+
// cl_intel_devicelib_cstring : 0x20
745+
// cl_intel_devicelib_imf: 0x40
746+
// cl_intel_devicelib_imf_fp64: 0x80
747+
// cl_intel_devicelib_imf_bf16: 0x100
748+
// cl_intel_devicelib_bfloat16: 0x200
749+
uint32_t getDeviceLibBits(const std::string &FuncName) {
750+
auto DeviceLibFuncIter = SDLMap.find(FuncName);
751+
return ((DeviceLibFuncIter == SDLMap.end())
752+
? 0
753+
: 0x1 << (static_cast<uint32_t>(DeviceLibFuncIter->second) -
754+
static_cast<uint32_t>(
755+
DeviceLibExt::cl_intel_devicelib_assert)));
756+
}
751757

752-
static SYCLDeviceLibSPVMeta SPVMetaList[] = {
753-
{DeviceLibExt::cl_intel_devicelib_assert, "libsycl-fallback-cassert.spv",
754-
DeviceLibIsNative::Ignore},
755-
{DeviceLibExt::cl_intel_devicelib_math, "libsycl-fallback-cmath.spv",
756-
DeviceLibIsNative::Ignore},
757-
{DeviceLibExt::cl_intel_devicelib_math_fp64,
758-
"libsycl-fallback-cmath-fp64.spv", DeviceLibIsNative::Ignore},
759-
{DeviceLibExt::cl_intel_devicelib_complex, "libsycl-fallback-complex.spv",
760-
DeviceLibIsNative::Ignore},
761-
{DeviceLibExt::cl_intel_devicelib_complex_fp64,
762-
"libsycl-fallback-complex-fp64.spv", DeviceLibIsNative::Ignore},
763-
{DeviceLibExt::cl_intel_devicelib_cstring, "libsycl-fallback-cstring.spv",
764-
DeviceLibIsNative::Ignore},
765-
{DeviceLibExt::cl_intel_devicelib_imf, "libsycl-fallback-imf.spv",
766-
DeviceLibIsNative::Ignore},
767-
{DeviceLibExt::cl_intel_devicelib_imf_fp64, "libsycl-fallback-imf-fp64.spv",
768-
DeviceLibIsNative::Ignore},
769-
{DeviceLibExt::cl_intel_devicelib_imf_bf16, "libsycl-fallback-imf-bf16.spv",
770-
DeviceLibIsNative::Ignore},
771-
{DeviceLibExt::cl_intel_devicelib_bfloat16, "libsycl-fallback-bfloat16.spv",
772-
DeviceLibIsNative::No},
773-
{DeviceLibExt::cl_intel_devicelib_bfloat16, "libsycl-native-bfloat16.spv",
774-
DeviceLibIsNative::Yes}};
758+
} // namespace
775759

776-
namespace llvm {
777760
// For each device image module, we go through all functions which meets
778761
// 1. The function name has prefix "__devicelib_"
779762
// 2. The function is declaration which means it doesn't have function body
780763
// And we don't expect non-spirv functions with "__devicelib_" prefix.
781-
void getRequiredSYCLDeviceLibs(
782-
const Module &M,
783-
llvm::SmallVector<SYCLDeviceLibSPVMeta, 16> &ReqDeviceLibs) {
764+
uint32_t llvm::getSYCLDeviceLibReqMask(const Module &M) {
784765
// Device libraries will be enabled only for spir-v module.
785766
if (!Triple(M.getTargetTriple()).isSPIROrSPIRV())
786-
return;
787-
788-
SmallSet<DeviceLibExt, 16> DeviceLibUsed;
767+
return 0;
768+
uint32_t ReqMask = 0;
789769
for (const Function &SF : M) {
790770
if (SF.getName().starts_with(DEVICELIB_FUNC_PREFIX) && SF.isDeclaration()) {
791771
assert(SF.getCallingConv() == CallingConv::SPIR_FUNC);
792-
auto DeviceLibFuncIter = SDLMap.find(SF.getName().str());
793-
if (DeviceLibFuncIter == SDLMap.end())
794-
continue;
795-
if (DeviceLibUsed.contains(DeviceLibFuncIter->second))
796-
continue;
797-
798-
DeviceLibUsed.insert(DeviceLibFuncIter->second);
799-
for (size_t idx : DeviceLibSPVExtMap[DeviceLibFuncIter->second]) {
800-
ReqDeviceLibs.push_back(SPVMetaList[idx]);
801-
}
772+
uint32_t DeviceLibBits = getDeviceLibBits(SF.getName().str());
773+
ReqMask |= DeviceLibBits;
802774
}
803775
}
776+
return ReqMask;
804777
}
805-
} // namespace llvm

llvm/lib/Support/PropertySetIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void PropertyValue::copy(const PropertyValue &P) {
195195
}
196196

197197
constexpr char PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS[];
198-
constexpr char PropertySetRegistry::SYCL_DEVICELIB_REQ_BINS[];
198+
constexpr char PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK[];
199199
constexpr char PropertySetRegistry::SYCL_SPEC_CONSTANTS_DEFAULT_VALUES[];
200200
constexpr char PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO[];
201201
constexpr char PropertySetRegistry::SYCL_PROGRAM_METADATA[];
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: sycl-post-link -properties -split=auto < %s -o %t.files.table
2+
; RUN: FileCheck %s -input-file=%t.files_0.prop
3+
4+
; CHECK:[SYCL/devicelib req mask]
5+
; CHECK: DeviceLibReqMask=1|64
6+
7+
source_filename = "main.cpp"
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spirv64-unknown-unknown"
10+
11+
declare spir_func i32 @__devicelib_imf_umulhi(i32 noundef %0, i32 noundef %1)
12+
13+
; Function Attrs: convergent mustprogress noinline norecurse optnone
14+
define weak_odr dso_local spir_kernel void @kernel() #0 {
15+
entry:
16+
%0 = call i32 @__devicelib_imf_umulhi(i32 0, i32 0)
17+
ret void
18+
}
19+
20+
attributes #0 = { "sycl-module-id"="main.cpp" }

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ cl::opt<std::string> OutputDir{
104104
"Directory where files listed in the result file table will be output"),
105105
cl::value_desc("dirname"), cl::cat(PostLinkCat)};
106106

107-
cl::opt<std::string> DeviceLibSPVDir{
108-
"device-lib-spv-dir",
109-
cl::desc("Directory where sycl fallback spirv device libraries reside"),
110-
cl::value_desc("dirname"), cl::cat(PostLinkCat)};
111-
112107
struct TargetFilenamePair {
113108
std::string Target;
114109
std::string Filename;
@@ -312,12 +307,8 @@ std::string saveModuleIR(Module &M, int I, StringRef Suff) {
312307
std::string saveModuleProperties(module_split::ModuleDesc &MD,
313308
const GlobalBinImageProps &GlobProps, int I,
314309
StringRef Suff, StringRef Target = "") {
315-
316-
StringRef SPVDir = "";
317-
if (DeviceLibSPVDir.getNumOccurrences() > 0)
318-
SPVDir = DeviceLibSPVDir;
319310
auto PropSet =
320-
computeModuleProperties(MD.getModule(), MD.entries(), GlobProps, SPVDir);
311+
computeModuleProperties(MD.getModule(), MD.entries(), GlobProps);
321312

322313
std::string NewSuff = Suff.str();
323314
if (!Target.empty()) {

sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ Expected<RTCBundleInfo> jit_compiler::performPostLink(
425425
/*EmitExportedSymbols=*/true, /*EmitImportedSymbols=*/true,
426426
/*DeviceGlobals=*/false};
427427
PropertySetRegistry Properties =
428-
computeModuleProperties(MDesc.getModule(), MDesc.entries(), PropReq, "");
428+
computeModuleProperties(MDesc.getModule(), MDesc.entries(), PropReq);
429429
// TODO: Manually add `compile_target` property as in
430430
// `saveModuleProperties`?
431431
const auto &PropertySets = Properties.getPropSets();

0 commit comments

Comments
 (0)