Skip to content

Commit e38dcdc

Browse files
authored
[SYCL] Add compile target to device image properties (#14757)
Previously, when compiling with any `intel_gpu_*` target, the device image only had the generic `spir64_gen` as its value for the [`DeviceTargetSpec`](https://github.com/intel/llvm/blob/450683b6fa1d1be1b9391905f43073b7a9555aa1/sycl/include/sycl/detail/pi.h#L1143) in its device image, so there was no way to differentiate device images compiled for a specific GPU in the runtime. Now, a new property is added to the image specifying the specific `intel_gpu_*` value it is compiled for.
1 parent e69aa94 commit e38dcdc

File tree

2 files changed

+80
-48
lines changed

2 files changed

+80
-48
lines changed

llvm/test/tools/sycl-post-link/multiple-filtered-outputs.ll

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,46 @@
4141
; CHECK-ALL-EMPTY:
4242

4343
; PVC does not support sg8 (=1) or sg64 (=2)
44-
; CHECK-PVC: _0.sym
45-
; CHECK-PVC-NEXT: _3.sym
46-
; CHECK-PVC-NEXT: _4.sym
47-
; CHECK-PVC-NEXT: _5.sym
44+
; CHECK-PVC: _intel_gpu_pvc_0.prop|{{.*}}_0.sym
45+
; CHECK-PVC-NEXT: _intel_gpu_pvc_3.prop|{{.*}}_3.sym
46+
; CHECK-PVC-NEXT: _intel_gpu_pvc_4.prop|{{.*}}_4.sym
47+
; CHECK-PVC-NEXT: _intel_gpu_pvc_5.prop|{{.*}}_5.sym
4848
; CHECK-PVC-EMPTY:
4949

50+
; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_0.prop -check-prefix=CHECK-PVC-PROP
51+
; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_3.prop -check-prefix=CHECK-PVC-PROP
52+
; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_4.prop -check-prefix=CHECK-PVC-PROP
53+
; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_5.prop -check-prefix=CHECK-PVC-PROP
54+
; CHECK-PVC-PROP: compile_target=2|oBAAAAAAAAQauRXZs91ZwV3XwZ3Y
55+
5056
; TGLLP does not support fp64 (=0) or sg64 (=2)
51-
; CHECK-TGLLP: _1.sym
52-
; CHECK-TGLLP-NEXT: _3.sym
53-
; CHECK-TGLLP-NEXT: _4.sym
54-
; CHECK-TGLLP-NEXT: _5.sym
57+
; CHECK-TGLLP: _intel_gpu_tgllp_1.prop|{{.*}}_1.sym
58+
; CHECK-TGLLP-NEXT: _intel_gpu_tgllp_3.prop|{{.*}}_3.sym
59+
; CHECK-TGLLP-NEXT: _intel_gpu_tgllp_4.prop|{{.*}}_4.sym
60+
; CHECK-TGLLP-NEXT: _intel_gpu_tgllp_5.prop|{{.*}}_5.sym
5561
; CHECK-TGLLP-EMPTY:
5662

63+
; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_1.prop -check-prefix=CHECK-TGLLP-PROP
64+
; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_3.prop -check-prefix=CHECK-TGLLP-PROP
65+
; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_4.prop -check-prefix=CHECK-TGLLP-PROP
66+
; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_5.prop -check-prefix=CHECK-TGLLP-PROP
67+
; CHECK-TGLLP-PROP: compile_target=2|4BAAAAAAAAQauRXZs91ZwV3X0dGbsBH
68+
5769
; CFL does not support sg64 (=2)
58-
; CHECK-CFL: _0.sym
59-
; CHECK-CFL-NEXT: _1.sym
60-
; CHECK-CFL-NEXT: _3.sym
61-
; CHECK-CFL-NEXT: _4.sym
62-
; CHECK-CFL-NEXT: _5.sym
70+
; CHECK-CFL: _intel_gpu_cfl_0.prop|{{.*}}_0.sym
71+
; CHECK-CFL-NEXT: _intel_gpu_cfl_1.prop|{{.*}}_1.sym
72+
; CHECK-CFL-NEXT: _intel_gpu_cfl_3.prop|{{.*}}_3.sym
73+
; CHECK-CFL-NEXT: _intel_gpu_cfl_4.prop|{{.*}}_4.sym
74+
; CHECK-CFL-NEXT: _intel_gpu_cfl_5.prop|{{.*}}_5.sym
6375
; CHECK-CFL-EMPTY:
6476

77+
; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_0.prop -check-prefix=CHECK-CFL-PROP
78+
; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_1.prop -check-prefix=CHECK-CFL-PROP
79+
; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_3.prop -check-prefix=CHECK-CFL-PROP
80+
; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_4.prop -check-prefix=CHECK-CFL-PROP
81+
; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_5.prop -check-prefix=CHECK-CFL-PROP
82+
; CHECK-CFL-PROP: compile_target=2|oBAAAAAAAAQauRXZs91ZwV3XjZGb
83+
6584
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"
6685
target triple = "spir64-unknown-unknown"
6786

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

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ cl::opt<std::string> OutputDir{
104104
cl::value_desc("dirname"), cl::cat(PostLinkCat)};
105105

106106
struct TargetFilenamePair {
107-
std::optional<std::string> Target;
107+
std::string Target;
108108
std::string Filename;
109109
};
110110

@@ -305,13 +305,21 @@ std::string saveModuleIR(Module &M, int I, StringRef Suff) {
305305

306306
std::string saveModuleProperties(module_split::ModuleDesc &MD,
307307
const GlobalBinImageProps &GlobProps, int I,
308-
StringRef Suff) {
309-
const auto &PropSet = computeModuleProperties(
310-
MD.getModule(), MD.entries(), GlobProps, MD.Props.SpecConstsMet,
311-
MD.isSpecConstantDefault());
308+
StringRef Suff, StringRef Target = "") {
309+
auto PropSet = computeModuleProperties(MD.getModule(), MD.entries(),
310+
GlobProps, MD.Props.SpecConstsMet,
311+
MD.isSpecConstantDefault());
312+
313+
std::string NewSuff = Suff.str();
314+
if (!Target.empty()) {
315+
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS, "compile_target",
316+
Target);
317+
NewSuff += "_";
318+
NewSuff += Target;
319+
}
312320

313321
std::error_code EC;
314-
std::string SCFile = makeResultFileName(".prop", I, Suff);
322+
std::string SCFile = makeResultFileName(".prop", I, NewSuff);
315323
raw_fd_ostream SCOut(SCFile, EC);
316324
checkError(EC, "error opening file '" + SCFile + "'");
317325
PropSet.write(SCOut);
@@ -396,35 +404,46 @@ StringRef getModuleSuffix(const module_split::ModuleDesc &MD) {
396404
return MD.isESIMD() ? "_esimd" : "";
397405
}
398406

407+
bool isTargetCompatibleWithModule(const std::string &Target,
408+
module_split::ModuleDesc &IrMD);
409+
410+
void addTableRow(util::SimpleTable &Table,
411+
const IrPropSymFilenameTriple &RowData);
412+
413+
// @param OutTables List of tables (one for each target) to output results
399414
// @param MD Module descriptor to save
400415
// @param IRFilename filename of already available IR component. If not empty,
401416
// IR component saving is skipped, and this file name is recorded as such in
402417
// the result.
403-
// @return a triple of files where IR, Property and Symbols components of the
404-
// Module descriptor are written respectively.
405-
IrPropSymFilenameTriple saveModule(module_split::ModuleDesc &MD, int I,
406-
StringRef IRFilename = "") {
407-
IrPropSymFilenameTriple Res;
418+
void saveModule(std::vector<std::unique_ptr<util::SimpleTable>> &OutTables,
419+
module_split::ModuleDesc &MD, int I, StringRef IRFilename) {
420+
IrPropSymFilenameTriple BaseTriple;
408421
StringRef Suffix = getModuleSuffix(MD);
409-
410422
if (!IRFilename.empty()) {
411423
// don't save IR, just record the filename
412-
Res.Ir = IRFilename.str();
424+
BaseTriple.Ir = IRFilename.str();
413425
} else {
414426
MD.cleanup();
415-
Res.Ir = saveModuleIR(MD.getModule(), I, Suffix);
427+
BaseTriple.Ir = saveModuleIR(MD.getModule(), I, Suffix);
416428
}
417-
GlobalBinImageProps Props = {EmitKernelParamInfo, EmitProgramMetadata,
418-
EmitExportedSymbols, EmitImportedSymbols,
419-
DeviceGlobals};
420-
if (DoPropGen)
421-
Res.Prop = saveModuleProperties(MD, Props, I, Suffix);
422-
423429
if (DoSymGen) {
424430
// save the names of the entry points - the symbol table
425-
Res.Sym = saveModuleSymbolTable(MD, I, Suffix);
431+
BaseTriple.Sym = saveModuleSymbolTable(MD, I, Suffix);
432+
}
433+
434+
for (const auto &[Table, OutputFile] : zip_equal(OutTables, OutputFiles)) {
435+
if (!isTargetCompatibleWithModule(OutputFile.Target, MD))
436+
continue;
437+
auto CopyTriple = BaseTriple;
438+
if (DoPropGen) {
439+
GlobalBinImageProps Props = {EmitKernelParamInfo, EmitProgramMetadata,
440+
EmitExportedSymbols, EmitImportedSymbols,
441+
DeviceGlobals};
442+
CopyTriple.Prop =
443+
saveModuleProperties(MD, Props, I, Suffix, OutputFile.Target);
444+
}
445+
addTableRow(*Table, CopyTriple);
426446
}
427-
return Res;
428447
}
429448

430449
module_split::ModuleDesc link(module_split::ModuleDesc &&MD1,
@@ -680,25 +699,25 @@ handleESIMD(module_split::ModuleDesc &&MDesc, bool &Modified,
680699
// information comes from the device config file (DeviceConfigFile.td).
681700
// For example, the intel_gpu_tgllp target does not support fp64 - therefore,
682701
// a module using fp64 would *not* be compatible with intel_gpu_tgllp.
683-
bool isTargetCompatibleWithModule(const std::optional<std::string> &Target,
702+
bool isTargetCompatibleWithModule(const std::string &Target,
684703
module_split::ModuleDesc &IrMD) {
685704
// When the user does not specify a target,
686705
// (e.g. -o out.table compared to -o intel_gpu_pvc,out-pvc.table)
687-
// Target will have no value and we will not want to perform any filtering, so
706+
// Target will be empty and we will not want to perform any filtering, so
688707
// we return true here.
689-
if (!Target.has_value())
708+
if (Target.empty())
690709
return true;
691710

692711
// TODO: If a target not found in the device config file is passed,
693712
// to sycl-post-link, then we should probably throw an error. However,
694713
// since not all the information for all the targets is filled out
695714
// right now, we return true, having the affect that unrecognized
696715
// targets have no filtering applied to them.
697-
if (!is_contained(DeviceConfigFile::TargetTable, *Target))
716+
if (!is_contained(DeviceConfigFile::TargetTable, Target))
698717
return true;
699718

700719
const DeviceConfigFile::TargetInfo &TargetInfo =
701-
DeviceConfigFile::TargetTable[*Target];
720+
DeviceConfigFile::TargetTable[Target];
702721
const SYCLDeviceRequirements &ModuleReqs =
703722
IrMD.getOrComputeDeviceRequirements();
704723

@@ -856,21 +875,15 @@ processInputModule(std::unique_ptr<Module> M) {
856875
"have been made\n";
857876
}
858877
for (module_split::ModuleDesc &IrMD : MMs) {
859-
IrPropSymFilenameTriple T = saveModule(IrMD, ID, OutIRFileName);
860-
for (const auto &[Table, OutputFile] : zip_equal(Tables, OutputFiles))
861-
if (isTargetCompatibleWithModule(OutputFile.Target, IrMD))
862-
addTableRow(*Table, T);
878+
saveModule(Tables, IrMD, ID, OutIRFileName);
863879
}
864880

865881
++ID;
866882

867883
if (!MMsWithDefaultSpecConsts.empty()) {
868884
for (size_t i = 0; i != MMsWithDefaultSpecConsts.size(); ++i) {
869885
module_split::ModuleDesc &IrMD = MMsWithDefaultSpecConsts[i];
870-
IrPropSymFilenameTriple T = saveModule(IrMD, ID, OutIRFileName);
871-
for (const auto &[Table, OutputFile] : zip_equal(Tables, OutputFiles))
872-
if (isTargetCompatibleWithModule(OutputFile.Target, IrMD))
873-
addTableRow(*Table, T);
886+
saveModule(Tables, IrMD, ID, OutIRFileName);
874887
}
875888

876889
++ID;

0 commit comments

Comments
 (0)