Skip to content

Commit bdabd61

Browse files
Artem Gindinsonigcbot
authored andcommitted
Ignore unneeded kernel MD entries during partial recompilation
Whenever we enter a partial recompilation scenario, the successfully built kernels are erased from the original SPV-friendly IR module. As it stands, however, no metadata clean-up is performed for the unneeded kernels, and we head straight into the unification phase with these dangling MD entries still held by the original `!opencl.kernels` MD node. As it's turned out, the very first occurence of such a dangling node can pollute the `ModuleMetaData::FuncMD` map with a null key, which ends up breaking the subsequent SPV-IR -> IGC metadata serialization routines. This commit guards `ModuleMetaData::FuncMD` against dangling entries from the initial compilation attempt: the LLVM function's validity is now checked _before_ `operator[]` gets invoked on the map. This is more of an initial w/a - instead, we should consider running a full cleanup within the compute interface (or its retry manager utility), getting rid of obsolete metadata entries before re-attempting the compilation.
1 parent 4417de5 commit bdabd61

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

IGC/AdaptorOCL/dllInterfaceCompute.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,10 @@ bool TranslateBuildSPMD(
15561556
oclContext.m_retryManager.kernelSet.find(pFunc->getName().str()) == oclContext.m_retryManager.kernelSet.end())
15571557
{
15581558
pFunc->eraseFromParent();
1559+
// TODO: Consider running a proper cleanup of
1560+
// !opencl.kernels metadata entries here instead of
1561+
// deferring 'null' entries to the "retried"
1562+
// unification phase.
15591563
}
15601564
}
15611565
}

IGC/Compiler/SPIRMetaDataTranslation.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,15 @@ bool SPIRMetaDataTranslation::runOnModule(Module& M)
147147
{
148148
IGCMD::FunctionInfoMetaDataHandle fHandle = IGCMD::FunctionInfoMetaDataHandle(IGCMD::FunctionInfoMetaData::get());
149149
SPIRMD::KernelMetaDataHandle spirKernel = *ki;
150+
// TODO: Null metadata entries are only expected in the event of a
151+
// partial recompilation. Once the retry manager learns to clean
152+
// up such metadata entries for unneeded kernels, we should simply
153+
// assert on the function's validity instead.
154+
if (spirKernel->getFunction() == nullptr)
155+
continue;
150156
IGC::FunctionMetaData& funcMD = modMD->FuncMD[spirKernel->getFunction()];
151157
fHandle->setType(FunctionTypeMD::KernelFunction);
152158

153-
if(spirKernel->getFunction() == nullptr)
154-
continue;
155-
156159
// Handling Thread Group Size
157160
SPIRMD::WorkGroupDimensionsMetaDataHandle reqdWorkGroupSize = spirKernel->getRequiredWorkGroupSize();
158161
if (reqdWorkGroupSize->hasValue())
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt --serialize-igc-metadata -igc-spir-metadata-translation -S < %s | FileCheck %s
10+
; ------------------------------------------------
11+
; SPIRMetaDataTranslation
12+
; ------------------------------------------------
13+
14+
; Check that during SPIRMetaData's propagation into IGCMetaData, 'null'
15+
; kernels are ignored by the translation/serialization routines.
16+
17+
; TODO: Such null entries are typically encountered in partial recompilation
18+
; scenarios as leftovers from the initial compilation. Were the metadata
19+
; cleanup handled by retry manager routines, this test would no longer be
20+
; needed.
21+
22+
declare spir_kernel void @test_spir(i64 addrspace(1)*)
23+
24+
; CHECK: {!"FuncMDMap[0]", void (i64 addrspace(1)*)* @test_spir}
25+
; CHECK-NOT: {!"FuncMDMap[{{0-9}}]",
26+
27+
!opencl.kernels = !{!0, !1, !12}
28+
!opencl.compiler.options = !{!19}
29+
30+
; COM: The following kernel metadata sequence should be omitted by the pass
31+
!0 = distinct !{null, !13, !14, !15, !16, !17, !18}
32+
; COM: End null kernel sequence
33+
!1 = !{void (i64 addrspace(1)*)* @test_spir, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11}
34+
!2 = !{!"kernel_arg_addr_space", i32 1}
35+
!3 = !{!"kernel_arg_access_qual", !"none"}
36+
!4 = !{!"kernel_arg_type", !"long*"}
37+
!5 = !{!"kernel_arg_type_qual", !"volatile"}
38+
!6 = !{!"kernel_arg_base_type", !"long*"}
39+
!7 = !{!"kernel_arg_name", !"dst"}
40+
!8 = !{!"reqd_work_group_size", i32 1, i32 1, i32 16}
41+
!9 = !{!"work_group_size_hint", i32 1, i32 1, i32 4}
42+
!10 = !{!"vec_type_hint", <4 x float> undef, i32 0}
43+
!11 = !{!"intel_reqd_sub_group_size", i32 16}
44+
; COM: The following kernel metadata sequence should be omitted by the pass
45+
!12 = distinct !{null, !13, !14, !15, !16, !17, !18}
46+
!13 = !{!"kernel_arg_addr_space", i32 0}
47+
!14 = !{!"kernel_arg_access_qual", !"none"}
48+
!15 = !{!"kernel_arg_type", !"void*"}
49+
!16 = !{!"kernel_arg_type_qual", !""}
50+
!17 = !{!"kernel_arg_base_type", !"void*"}
51+
!18 = !{!"kernel_arg_name", !"null_arg"}
52+
; COM: End null kernel sequence
53+
!19 = !{!"-cl-std=CL2.0", !"-cl-opt-disable", !"-g", !"-denorms-are-zero", !"-fp32-correctly-rounded-divide-sqrt", !"-mad-enable", !"-no-signed-zeros", !"-unsafe-math-optimizations", !"-finite-math-only", !"-fast-relaxed-math", !"-relaxed-builtins", !"-match-sincospi"}

0 commit comments

Comments
 (0)