Skip to content

Commit a7e0f86

Browse files
[SYCL] Emit kernel names for SYCLBIN (#18970)
This commit adds a new property to the property set when producing SYCLBIN files. This new property lists all kernels inside the corresponding binaries. --------- Signed-off-by: Larsen, Steffen <[email protected]> Co-authored-by: Marcos Maronas <[email protected]>
1 parent 3b13547 commit a7e0f86

File tree

10 files changed

+151
-8
lines changed

10 files changed

+151
-8
lines changed

clang/test/Driver/sycl-post-link-options.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@
2121
// RUN: --sycl-post-link-options="-O2 -device-globals -O0" \
2222
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_POSTLINK_JIT_NEW %s
2323
// OPTIONS_POSTLINK_JIT_NEW: sycl-post-link{{.*}} -spec-const=native -properties -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-exported-symbols -emit-imported-symbols -split-esimd -lower-esimd -O2 -device-globals -O0
24+
//
25+
// Run clang-linker-wrapper test for generating SYCLBIN files.
26+
//
27+
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
28+
// RUN: -syclbin=executable -sycl-device-libraries=%t.devicelib.o \
29+
// RUN: --sycl-post-link-options="-O2 -device-globals -O0" \
30+
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck --check-prefix OPTIONS_POSTLINK_JIT_NEW_SYCLBIN %s
31+
// OPTIONS_POSTLINK_JIT_NEW_SYCLBIN: sycl-post-link{{.*}} -spec-const=native -properties -split=auto -emit-only-kernels-as-entry-points -emit-param-info -symbols -emit-kernel-names -emit-exported-symbols -emit-imported-symbols -split-esimd -lower-esimd -O2 -device-globals -O0

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ getTripleBasedSYCLPostLinkOpts(const ArgList &Args,
694694
OPT_no_sycl_device_code_split_esimd, SplitEsimdByDefault);
695695
if (!Args.hasArg(OPT_sycl_thin_lto))
696696
PostLinkArgs.push_back("-symbols");
697+
// Emit kernel names if we are producing SYCLBIN.
698+
if (Args.hasArg(OPT_syclbin_EQ))
699+
PostLinkArgs.push_back("-emit-kernel-names");
697700
// Specialization constant info generation is mandatory -
698701
// add options unconditionally
699702
PostLinkArgs.push_back("-emit-exported-symbols");

llvm/include/llvm/SYCLPostLink/ComputeModuleRuntimeInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace sycl {
2424
struct GlobalBinImageProps {
2525
bool EmitKernelParamInfo;
2626
bool EmitProgramMetadata;
27+
bool EmitKernelNames;
2728
bool EmitExportedSymbols;
2829
bool EmitImportedSymbols;
2930
bool EmitDeviceGlobalPropSet;

llvm/include/llvm/Support/PropertySetIO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class PropertySetRegistry {
217217
static constexpr char SYCL_PROGRAM_METADATA[] = "SYCL/program metadata";
218218
static constexpr char SYCL_MISC_PROP[] = "SYCL/misc properties";
219219
static constexpr char SYCL_ASSERT_USED[] = "SYCL/assert used";
220+
static constexpr char SYCL_KERNEL_NAMES[] = "SYCL/kernel names";
220221
static constexpr char SYCL_EXPORTED_SYMBOLS[] = "SYCL/exported symbols";
221222
static constexpr char SYCL_IMPORTED_SYMBOLS[] = "SYCL/imported symbols";
222223
static constexpr char SYCL_DEVICE_GLOBALS[] = "SYCL/device globals";

llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ PropSetRegTy computeModuleProperties(const Module &M,
271271
}
272272
}
273273
}
274+
if (GlobProps.EmitKernelNames) {
275+
for (const auto *F : EntryPoints) {
276+
if (F->getCallingConv() == CallingConv::SPIR_KERNEL) {
277+
PropSet.add(PropSetRegTy::SYCL_KERNEL_NAMES, F->getName(),
278+
/*PropVal=*/true);
279+
}
280+
}
281+
}
274282

275283
if (GlobProps.EmitImportedSymbols) {
276284
// record imported functions in the property set

llvm/lib/Support/PropertySetIO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ constexpr char PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO[];
201201
constexpr char PropertySetRegistry::SYCL_PROGRAM_METADATA[];
202202
constexpr char PropertySetRegistry::SYCL_MISC_PROP[];
203203
constexpr char PropertySetRegistry::SYCL_ASSERT_USED[];
204+
constexpr char PropertySetRegistry::SYCL_KERNEL_NAMES[];
204205
constexpr char PropertySetRegistry::SYCL_EXPORTED_SYMBOLS[];
205206
constexpr char PropertySetRegistry::SYCL_IMPORTED_SYMBOLS[];
206207
constexpr char PropertySetRegistry::SYCL_DEVICE_GLOBALS[];
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
; This test checks that the post-link tool generates list of kernel names.
2+
;
3+
; Global scope
4+
; RUN: sycl-post-link -properties -symbols -emit-kernel-names -S < %s -o %t.global.files.table
5+
; RUN: FileCheck %s -input-file=%t.global.files_0.prop --implicit-check-not="SpirFunc" --check-prefix=CHECK-GLOBAL-PROP
6+
;
7+
; Per-module split
8+
; RUN: sycl-post-link -properties -symbols -split=source -emit-kernel-names -S < %s -o %t.per_module.files.table
9+
; RUN: FileCheck %s -input-file=%t.per_module.files_0.prop -implicit-check-not="SpirFunc" --check-prefix=CHECK-PERMODULE-0-PROP
10+
; RUN: FileCheck %s -input-file=%t.per_module.files_1.prop -implicit-check-not="SpirFunc" --check-prefix=CHECK-PERMODULE-1-PROP
11+
; RUN: FileCheck %s -input-file=%t.per_module.files_2.prop -implicit-check-not="SpirFunc" --check-prefix=CHECK-KERNELLESS-PROP
12+
;
13+
; Per-kernel split
14+
; RUN: sycl-post-link -properties -symbols -split=kernel -emit-kernel-names -S < %s -o %t.per_kernel.files.table
15+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_0.prop --implicit-check-not="SpirFunc" --check-prefix=CHECK-PERKERNEL-0-PROP
16+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_1.prop --implicit-check-not="SpirFunc" --check-prefix=CHECK-PERKERNEL-1-PROP
17+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_2.prop --implicit-check-not="SpirFunc" --check-prefix=CHECK-PERKERNEL-2-PROP
18+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_3.prop --implicit-check-not="SpirFunc" --check-prefix=CHECK-KERNELLESS-PROP
19+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_4.prop --implicit-check-not="SpirFunc" --check-prefix=CHECK-KERNELLESS-PROP
20+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_5.prop --implicit-check-not="SpirFunc" --check-prefix=CHECK-KERNELLESS-PROP
21+
22+
target triple = "spir64-unknown-unknown"
23+
24+
define dso_local spir_kernel void @SpirKernel1(float %arg1) #2 {
25+
entry:
26+
ret void
27+
}
28+
29+
define dso_local spir_kernel void @SpirKernel2(float %arg1) #1 {
30+
entry:
31+
ret void
32+
}
33+
34+
define dso_local spir_kernel void @SpirKernel3(float %arg1) #2 {
35+
entry:
36+
ret void
37+
}
38+
39+
define dso_local spir_func void @SpirFunc1(float %arg1) #0 {
40+
entry:
41+
ret void
42+
}
43+
44+
define dso_local spir_func void @SpirFunc2(i32 %arg1, i32 %arg2) #1 {
45+
entry:
46+
ret void
47+
}
48+
49+
define dso_local spir_func void @SpirFunc3(float %arg1) #0 {
50+
entry:
51+
ret void
52+
}
53+
54+
define dso_local spir_func void @SpirFunc4(float %arg1) {
55+
entry:
56+
ret void
57+
}
58+
59+
attributes #0 = { "sycl-module-id"="a.cpp" }
60+
attributes #1 = { "sycl-module-id"="b.cpp" }
61+
attributes #2 = { "sycl-module-id"="c.cpp" }
62+
63+
; Global scope
64+
; CHECK-GLOBAL-PROP: [SYCL/kernel names]
65+
; CHECK-GLOBAL-PROP-NEXT: SpirKernel1
66+
; CHECK-GLOBAL-PROP-NEXT: SpirKernel2
67+
; CHECK-GLOBAL-PROP-NEXT: SpirKernel3
68+
69+
; Per-module split
70+
; CHECK-PERMODULE-0-PROP: [SYCL/kernel names]
71+
; CHECK-PERMODULE-0-PROP-NEXT: SpirKernel1
72+
; CHECK-PERMODULE-0-PROP-NEXT: SpirKernel3
73+
; CHECK-PERMODULE-0-PROP-NOT: SpirKernel2
74+
75+
; CHECK-PERMODULE-1-PROP: [SYCL/kernel names]
76+
; CHECK-PERMODULE-1-PROP-NEXT: SpirKernel2
77+
; CHECK-PERMODULE-1-PROP-NOT: SpirKernel1
78+
; CHECK-PERMODULE-1-PROP-NOT: SpirKernel3
79+
80+
; Per-kernel split
81+
; CHECK-PERKERNEL-0-PROP: [SYCL/kernel names]
82+
; CHECK-PERKERNEL-0-PROP-NEXT: SpirKernel3
83+
; CHECK-PERKERNEL-0-PROP-NOT: SpirKernel1
84+
; CHECK-PERKERNEL-0-PROP-NOT: SpirKernel2
85+
86+
; CHECK-PERKERNEL-1-PROP: [SYCL/kernel names]
87+
; CHECK-PERKERNEL-1-PROP-NEXT: SpirKernel2
88+
; CHECK-PERKERNEL-1-PROP-NOT: SpirKernel1
89+
; CHECK-PERKERNEL-1-PROP-NOT: SpirKernel3
90+
91+
; CHECK-PERKERNEL-2-PROP: [SYCL/kernel names]
92+
; CHECK-PERKERNEL-2-PROP-NEXT: SpirKernel1
93+
; CHECK-PERKERNEL-2-PROP-NOT: SpirKernel2
94+
; CHECK-PERKERNEL-2-PROP-NOT: SpirKernel3
95+
96+
; Kernel-less generated modules should have no kernel names
97+
; CHECK-KERNELLESS-PROP-NOT: [SYCL/kernel names]
98+
; CHECK-KERNELLESS-PROP-NOT: SpirKernel1
99+
; CHECK-KERNELLESS-PROP-NOT: SpirKernel2
100+
; CHECK-KERNELLESS-PROP-NOT: SpirKernel3

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ cl::opt<bool> EmitProgramMetadata{"emit-program-metadata",
219219
cl::desc("emit SYCL program metadata"),
220220
cl::cat(PostLinkCat)};
221221

222+
cl::opt<bool> EmitKernelNames{
223+
"emit-kernel-names", cl::desc("emit kernel names"), cl::cat(PostLinkCat)};
224+
222225
cl::opt<bool> EmitExportedSymbols{"emit-exported-symbols",
223226
cl::desc("emit exported symbols"),
224227
cl::cat(PostLinkCat)};
@@ -402,8 +405,8 @@ void saveModule(std::vector<std::unique_ptr<util::SimpleTable>> &OutTables,
402405
auto CopyTriple = BaseTriple;
403406
if (DoPropGen) {
404407
GlobalBinImageProps Props = {EmitKernelParamInfo, EmitProgramMetadata,
405-
EmitExportedSymbols, EmitImportedSymbols,
406-
DeviceGlobals};
408+
EmitKernelNames, EmitExportedSymbols,
409+
EmitImportedSymbols, DeviceGlobals};
407410
CopyTriple.Prop =
408411
saveModuleProperties(MD, Props, I, Suffix, OutputFile.Target);
409412
}
@@ -811,15 +814,16 @@ int main(int argc, char **argv) {
811814
bool DoSpecConst = SpecConstLower.getNumOccurrences() > 0;
812815
bool DoParamInfo = EmitKernelParamInfo.getNumOccurrences() > 0;
813816
bool DoProgMetadata = EmitProgramMetadata.getNumOccurrences() > 0;
817+
bool DoKernelNames = EmitKernelNames.getNumOccurrences() > 0;
814818
bool DoExportedSyms = EmitExportedSymbols.getNumOccurrences() > 0;
815819
bool DoImportedSyms = EmitImportedSymbols.getNumOccurrences() > 0;
816820
bool DoDeviceGlobals = DeviceGlobals.getNumOccurrences() > 0;
817821
bool DoGenerateDeviceImageWithDefaulValues =
818822
GenerateDeviceImageWithDefaultSpecConsts.getNumOccurrences() > 0;
819823

820824
if (!DoSplit && !DoSpecConst && !DoSymGen && !DoPropGen && !DoParamInfo &&
821-
!DoProgMetadata && !DoSplitEsimd && !DoExportedSyms && !DoImportedSyms &&
822-
!DoDeviceGlobals && !DoLowerEsimd) {
825+
!DoProgMetadata && !DoSplitEsimd && !DoKernelNames && !DoExportedSyms &&
826+
!DoImportedSyms && !DoDeviceGlobals && !DoLowerEsimd) {
823827
errs() << "no actions specified; try --help for usage info\n";
824828
return 1;
825829
}
@@ -853,6 +857,11 @@ int main(int argc, char **argv) {
853857
<< " -" << IROutputOnly.ArgStr << "\n";
854858
return 1;
855859
}
860+
if (IROutputOnly && DoKernelNames) {
861+
errs() << "error: -" << EmitKernelNames.ArgStr << " can't be used with"
862+
<< " -" << IROutputOnly.ArgStr << "\n";
863+
return 1;
864+
}
856865
if (IROutputOnly && DoExportedSyms) {
857866
errs() << "error: -" << EmitExportedSymbols.ArgStr << " can't be used with"
858867
<< " -" << IROutputOnly.ArgStr << "\n";

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,12 @@ jit_compiler::performPostLink(ModuleUPtr Module,
734734
[](Function *F) { return F->getName(); });
735735

736736
// TODO: Determine what is requested.
737-
GlobalBinImageProps PropReq{
738-
/*EmitKernelParamInfo=*/true, /*EmitProgramMetadata=*/true,
739-
/*EmitExportedSymbols=*/true, /*EmitImportedSymbols=*/true,
740-
/*DeviceGlobals=*/true};
737+
GlobalBinImageProps PropReq{/*EmitKernelParamInfo=*/true,
738+
/*EmitProgramMetadata=*/true,
739+
/*EmitKernelNames=*/true,
740+
/*EmitExportedSymbols=*/true,
741+
/*EmitImportedSymbols=*/true,
742+
/*DeviceGlobals=*/true};
741743
PropertySetRegistry Properties =
742744
computeModuleProperties(MDesc.getModule(), MDesc.entries(), PropReq,
743745
AllowDeviceImageDependencies);

sycl/doc/design/PropertySets.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ __Value type:__ 32 bit integer. ("1")
139139
__Value:__ 1 if the kernel uses assertions and 0 or missing otherwise.
140140

141141

142+
### [SYCL/kernel names]
143+
144+
__Key:__ Kernel name.
145+
146+
__Value type:__ 32 bit integer. ("1")
147+
148+
__Value:__ 1 if the name identifies a kernel inside the binary and 0 or
149+
missing otherwise.
150+
151+
142152
### [SYCL/exported symbols]
143153

144154
__Key:__ Symbol name.

0 commit comments

Comments
 (0)