@@ -339,6 +339,10 @@ void GenXOCLRuntimeInfo::KernelInfo::setPrintStrings(
339
339
});
340
340
}
341
341
342
+ GenXOCLRuntimeInfo::KernelInfo::KernelInfo (const GenXSubtarget &ST)
343
+ : Name{" Intel_Symbol_Table_Void_Program" }, GRFSizeInBytes{
344
+ ST.getGRFByteSize ()} {}
345
+
342
346
GenXOCLRuntimeInfo::KernelInfo::KernelInfo (const FunctionGroup &FG,
343
347
const GenXSubtarget &ST,
344
348
const GenXBackendConfig &BC) {
@@ -413,18 +417,20 @@ void constructSymbols(InputIter First, InputIter Last, OutputIter Out) {
413
417
}
414
418
415
419
static GenXOCLRuntimeInfo::SymbolSeq constructFunctionSymbols (
416
- genx::BinaryDataAccumulator<const Function *> &GenBinary) {
420
+ genx::BinaryDataAccumulator<const Function *> &GenBinary, bool HasKernel ) {
417
421
GenXOCLRuntimeInfo::SymbolSeq Symbols;
418
422
Symbols.reserve (GenBinary.getNumSections ());
419
- auto &KernelSection = GenBinary.front ();
420
- Symbols.emplace_back (vISA::GenSymType::S_KERNEL, KernelSection.Info .Offset ,
421
- KernelSection.Info .getSize (),
422
- KernelSection.Key ->getName ().str ());
423
+ if (HasKernel) {
424
+ auto &KernelSection = GenBinary.front ();
425
+ Symbols.emplace_back (vISA::GenSymType::S_KERNEL, KernelSection.Info .Offset ,
426
+ KernelSection.Info .getSize (),
427
+ KernelSection.Key ->getName ().str ());
428
+ }
423
429
424
- // Skipping first section with the kernel.
425
- constructSymbols<vISA::GenSymType::S_FUNC>(std::next (GenBinary. begin ()),
426
- GenBinary.end (),
427
- std::back_inserter (Symbols));
430
+ // Skipping first section if binary has a kernel.
431
+ constructSymbols<vISA::GenSymType::S_FUNC>(
432
+ HasKernel ? std::next (GenBinary. begin ()) : GenBinary.begin (),
433
+ GenBinary. end (), std::back_inserter (Symbols));
428
434
429
435
return Symbols;
430
436
}
@@ -452,13 +458,12 @@ appendFuncBinary(genx::BinaryDataAccumulator<const Function *> &GenBinary,
452
458
// Returns the success status of the loading.
453
459
static bool
454
460
loadGenBinaryFromFile (genx::BinaryDataAccumulator<const Function *> &GenBinary,
455
- const Function &Kernel, const Function &F,
456
- vc::ShaderOverrider const &Loader,
461
+ const Function &F, vc::ShaderOverrider const &Loader,
457
462
vc::ShaderOverrider::Extensions Ext) {
458
463
void *GenBin = nullptr ;
459
464
int GenBinSize = 0 ;
460
465
461
- if (!Loader.override (GenBin, GenBinSize, Kernel. getName (), F.getName (), Ext))
466
+ if (!Loader.override (GenBin, GenBinSize, F.getName (), Ext))
462
467
return false ;
463
468
464
469
if (!GenBin || !GenBinSize) {
@@ -477,29 +482,24 @@ loadGenBinaryFromFile(genx::BinaryDataAccumulator<const Function *> &GenBinary,
477
482
// Returns the success status of the overriding.
478
483
static bool
479
484
tryOverrideBinary (genx::BinaryDataAccumulator<const Function *> &GenBinary,
480
- const Function &Kernel, const Function &F,
481
- vc::ShaderOverrider const &Loader) {
485
+ const Function &F, vc::ShaderOverrider const &Loader) {
482
486
using Extensions = vc::ShaderOverrider::Extensions;
483
487
484
488
// Attempts to override .asm
485
- if (loadGenBinaryFromFile (GenBinary, Kernel, F, Loader, Extensions::ASM))
489
+ if (loadGenBinaryFromFile (GenBinary, F, Loader, Extensions::ASM))
486
490
return true ;
487
491
488
492
// If it has failed then attempts to override .dat file
489
- return loadGenBinaryFromFile (GenBinary, Kernel, F, Loader, Extensions::DAT);
493
+ return loadGenBinaryFromFile (GenBinary, F, Loader, Extensions::DAT);
490
494
}
491
495
492
- // Either loads binaries from VISABuilder or overrides from files.
493
- // \p Kernel should always be kernel function, meanwhile if \p F is actually a
494
- // kernel means we are loading kernel, and if \p F is a function means we are
495
- // loading function.
496
- static void
497
- loadBinaries (genx::BinaryDataAccumulator<const Function *> &GenBinary,
498
- VISABuilder &VB, const Function &Kernel, const Function &F,
499
- GenXBackendConfig const &BC) {
496
+ // Either loads binary from VISABuilder or overrides from file.
497
+ static void loadBinary (genx::BinaryDataAccumulator<const Function *> &GenBinary,
498
+ VISABuilder &VB, const Function &F,
499
+ GenXBackendConfig const &BC) {
500
500
// Attempt to override
501
501
if (BC.hasShaderOverrider () &&
502
- tryOverrideBinary (GenBinary, Kernel, F, BC.getShaderOverrider ()))
502
+ tryOverrideBinary (GenBinary, F, BC.getShaderOverrider ()))
503
503
return ;
504
504
505
505
// If there is no overriding or attemp fails, then gets binary from compilation
@@ -537,23 +537,11 @@ std::vector<const Function *> collectCalledFunctions(const FunctionGroup &FG,
537
537
// Constructs gen binary for provided function group \p FG.
538
538
static genx::BinaryDataAccumulator<const Function *>
539
539
getGenBinary (const FunctionGroup &FG, VISABuilder &VB,
540
- GenXBackendConfig const &BC,
541
- std::set<const Function *> &ProcessedCalls) {
540
+ GenXBackendConfig const &BC) {
542
541
Function const *Kernel = FG.getHead ();
543
542
genx::BinaryDataAccumulator<const Function *> GenBinary;
544
543
// load kernel
545
- loadBinaries (GenBinary, VB, *Kernel, *Kernel, BC);
546
-
547
- const auto IndirectFunctions = collectCalledFunctions (
548
- FG, [](const Function *F) { return genx::isReferencedIndirectly (F); });
549
- for (const Function *F : IndirectFunctions) {
550
- if (ProcessedCalls.count (F) != 0 )
551
- continue ;
552
- ProcessedCalls.insert (F);
553
- // load functions
554
- loadBinaries (GenBinary, VB, *Kernel, *F, BC);
555
- }
556
-
544
+ loadBinary (GenBinary, VB, *Kernel, BC);
557
545
return std::move (GenBinary);
558
546
}
559
547
@@ -656,7 +644,6 @@ class RuntimeInfoCollector final {
656
644
const GenXSubtarget &ST;
657
645
const Module &M;
658
646
const GenXDebugInfo &DBG;
659
- std::set<const llvm::Function *> ProcessedCalls;
660
647
661
648
public:
662
649
using KernelStorageTy = GenXOCLRuntimeInfo::KernelStorageTy;
@@ -673,7 +660,9 @@ class RuntimeInfoCollector final {
673
660
CompiledModuleT run ();
674
661
675
662
private:
676
- CompiledKernel collectFunctionGroupInfo (const FunctionGroup &FG);
663
+ CompiledKernel collectFunctionGroupInfo (const FunctionGroup &FG) const ;
664
+ CompiledKernel collectFunctionSubgroupsInfo (
665
+ const std::vector<FunctionGroup *> &Subgroups) const ;
677
666
};
678
667
679
668
} // namespace
@@ -684,12 +673,20 @@ RuntimeInfoCollector::CompiledModuleT RuntimeInfoCollector::run() {
684
673
[this ](const FunctionGroup *FG) {
685
674
return collectFunctionGroupInfo (*FG);
686
675
});
676
+ std::vector<FunctionGroup *> IndirectlyReferencedFuncs;
677
+ std::copy_if (FGA.subgroup_begin (), FGA.subgroup_end (),
678
+ std::back_inserter (IndirectlyReferencedFuncs),
679
+ [](const FunctionGroup *FG) {
680
+ return genx::isReferencedIndirectly (FG->getHead ());
681
+ });
682
+ if (!IndirectlyReferencedFuncs.empty ())
683
+ Kernels.push_back (collectFunctionSubgroupsInfo (IndirectlyReferencedFuncs));
687
684
return {getModuleInfo (M), std::move (Kernels),
688
685
M.getDataLayout ().getPointerSize ()};
689
686
}
690
687
691
688
RuntimeInfoCollector::CompiledKernel
692
- RuntimeInfoCollector::collectFunctionGroupInfo (const FunctionGroup &FG) {
689
+ RuntimeInfoCollector::collectFunctionGroupInfo (const FunctionGroup &FG) const {
693
690
using KernelInfo = GenXOCLRuntimeInfo::KernelInfo;
694
691
using GTPinInfo = GenXOCLRuntimeInfo::GTPinInfo;
695
692
using CompiledKernel = GenXOCLRuntimeInfo::CompiledKernel;
@@ -722,7 +719,7 @@ RuntimeInfoCollector::collectFunctionGroupInfo(const FunctionGroup &FG) {
722
719
}
723
720
724
721
genx::BinaryDataAccumulator<const Function *> GenBinary =
725
- getGenBinary (FG, VB, BC, ProcessedCalls );
722
+ getGenBinary (FG, VB, BC);
726
723
727
724
const auto & Dbg = DBG.getModuleDebug ();
728
725
auto DbgIt = Dbg.find (KernelFunction);
@@ -737,20 +734,42 @@ RuntimeInfoCollector::collectFunctionGroupInfo(const FunctionGroup &FG) {
737
734
CISA_CALL (VK->GetGenRelocEntryBuffer (Info.LegacyFuncRelocations .Buffer ,
738
735
Info.LegacyFuncRelocations .Size ,
739
736
Info.LegacyFuncRelocations .Entries ));
740
- Info.Func .Symbols = constructFunctionSymbols (GenBinary);
737
+ Info.Func .Symbols = constructFunctionSymbols (GenBinary, /* HasKernel= */ true );
741
738
742
739
void *GTPinBuffer = nullptr ;
743
740
unsigned GTPinBufferSize = 0 ;
744
741
CISA_CALL (VK->GetGTPinBuffer (GTPinBuffer, GTPinBufferSize));
745
742
746
743
auto *GTPinBytes = static_cast <char *>(GTPinBuffer);
747
- GTPinInfo gtpin{{ GTPinBytes, GTPinBytes + GTPinBufferSize} };
744
+ GTPinInfo gtpin{GTPinBytes, GTPinBytes + GTPinBufferSize};
748
745
749
746
Info.Func .Data .Buffer = std::move (GenBinary).emitConsolidatedData ();
750
747
return CompiledKernel{std::move (Info), *JitInfo, std::move (gtpin),
751
748
std::move (DebugData)};
752
749
}
753
750
751
+ RuntimeInfoCollector::CompiledKernel
752
+ RuntimeInfoCollector::collectFunctionSubgroupsInfo (
753
+ const std::vector<FunctionGroup *> &Subgroups) const {
754
+ using KernelInfo = GenXOCLRuntimeInfo::KernelInfo;
755
+ using CompiledKernel = GenXOCLRuntimeInfo::CompiledKernel;
756
+
757
+ IGC_ASSERT (!Subgroups.empty ());
758
+ KernelInfo Info{ST};
759
+
760
+ genx::BinaryDataAccumulator<const Function *> GenBinary;
761
+ for (auto *FG : Subgroups) {
762
+ auto *Func = FG->getHead ();
763
+ IGC_ASSERT (genx::fg::isSubGroupHead (*Func));
764
+ loadBinary (GenBinary, VB, *Func, BC);
765
+ }
766
+ Info.Func .Symbols = constructFunctionSymbols (GenBinary, /* HasKernel*/ false );
767
+ Info.Func .Data .Buffer = GenBinary.emitConsolidatedData ();
768
+
769
+ return CompiledKernel{std::move (Info), FINALIZER_INFO{}, /* GtpinInfo*/ {},
770
+ /* DebugInfo*/ {}};
771
+ }
772
+
754
773
void GenXOCLRuntimeInfo::getAnalysisUsage (AnalysisUsage &AU) const {
755
774
AU.addRequired <FunctionGroupAnalysis>();
756
775
AU.addRequired <GenXBackendConfig>();
0 commit comments