Skip to content

Commit 96ff32f

Browse files
mshelegoigcbot
authored andcommitted
Add options to control depressurizer thresholds
Remove all the thresholds calculations and specify them by options instead
1 parent 5a9a876 commit 96ff32f

File tree

11 files changed

+78
-237
lines changed

11 files changed

+78
-237
lines changed

IGC/Options/include/igc/Options/VCApiOptions.td

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22

3-
Copyright (C) 2021 Intel Corporation
3+
Copyright (C) 2021-2025 Intel Corporation
44

55
SPDX-License-Identifier: MIT
66

@@ -96,6 +96,15 @@ def : PlainFlag<"doubleGRF">,
9696
def : PlainFlag<"double-GRF">,
9797
Alias<exp_register_file_size_common>, AliasArgs<["256"]>,
9898
HelpText<"Alias for -ze-opt-large-register-file">;
99+
100+
def depressurizer_grf_threshold : PlainSeparate<"depressurizer-grf-threshold">,
101+
HelpText<"Threshold for GRF pressure reduction">;
102+
def : PlainJoined<"depressurizer-grf-threshold=">, Alias<depressurizer_grf_threshold>,
103+
HelpText<"Alias for -depressurizer-grf-threshold <value>">;
104+
def depressurizer_flag_grf_tolerance : PlainSeparate<"depressurizer-flag-grf-tolerance">,
105+
HelpText<"Threshold for disabling flag pressure reduction">;
106+
def : PlainJoined<"depressurizer-flag-grf-tolerance=">, Alias<depressurizer_flag_grf_tolerance>,
107+
HelpText<"Alias for -depressurizer-flag-grf-tolerance <value>">;
99108
}
100109
// }} VC API options
101110

IGC/VectorCompiler/igcdeps/src/TranslationInterface.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2020-2024 Intel Corporation
3+
Copyright (C) 2020-2025 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -313,6 +313,9 @@ static void adjustTransformationsAndOptimizations(vc::CompileOptions &Opts) {
313313
if (__IGC_OPAQUE_POINTERS_API_ENABLED ||
314314
IGC_IS_FLAG_ENABLED(EnableOpaquePointersBackend))
315315
Opts.EnableOpaquePointers = true;
316+
317+
Opts.DepressurizerGRFThreshold = IGC_GET_FLAG_VALUE(VCDepressurizerGRFThreshold);
318+
Opts.DepressurizerFlagGRFTolerance = IGC_GET_FLAG_VALUE(VCDepressurizerFlagGRFTolerance);
316319
}
317320

318321
static void adjustKernelMetrics(vc::CompileOptions &Opts) {

IGC/VectorCompiler/include/vc/Driver/Driver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2020-2024 Intel Corporation
3+
Copyright (C) 2020-2025 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -165,6 +165,9 @@ struct CompileOptions {
165165

166166
bool EnableOpaquePointers = false;
167167
bool CollectCostInfo = false;
168+
169+
unsigned DepressurizerGRFThreshold = 2560;
170+
unsigned DepressurizerFlagGRFTolerance = 3840;
168171
};
169172

170173
struct ExternalData {

IGC/VectorCompiler/include/vc/Support/BackendConfig.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2020-2023 Intel Corporation
3+
Copyright (C) 2020-2025 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -190,6 +190,9 @@ struct GenXBackendOptions {
190190

191191
bool EnableCostModel = false;
192192

193+
unsigned DepressurizerGRFThreshold = 2560;
194+
unsigned DepressurizerFlagGRFTolerance = 3840;
195+
193196
// Calling enforceLLVMOptions queries the state of LLVM options and
194197
// updates BackendOptions accordingly.
195198
// Note: current implementation allows backend options to be configured by
@@ -396,6 +399,13 @@ struct GenXBackendConfigResult {
396399
bool isCostModelEnabled() const { return Options.EnableCostModel; }
397400

398401
vc::BinaryKind getBinaryFormat() const { return Options.Binary; }
402+
403+
unsigned getDepressurizerGRFThreshold() const {
404+
return Options.DepressurizerGRFThreshold;
405+
}
406+
unsigned getDepressurizerFlagGRFTolerance() const {
407+
return Options.DepressurizerFlagGRFTolerance;
408+
}
399409
};
400410

401411
class GenXBackendConfig : public ImmutablePass, public GenXBackendConfigResult {

IGC/VectorCompiler/include/vc/Utils/GenX/GRFSize.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

IGC/VectorCompiler/lib/Driver/Driver.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2020-2024 Intel Corporation
3+
Copyright (C) 2020-2025 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -302,6 +302,9 @@ static GenXBackendOptions createBackendOptions(const vc::CompileOptions &Opts) {
302302

303303
BackendOpts.EnableCostModel = Opts.CollectCostInfo;
304304

305+
BackendOpts.DepressurizerGRFThreshold = Opts.DepressurizerGRFThreshold;
306+
BackendOpts.DepressurizerFlagGRFTolerance = Opts.DepressurizerFlagGRFTolerance;
307+
305308
return BackendOpts;
306309
}
307310

@@ -864,6 +867,21 @@ static Error fillApiOptions(const opt::ArgList &ApiOptions,
864867
Opts.StackMemSize = Result;
865868
}
866869

870+
if (opt::Arg *A = ApiOptions.getLastArg(OPT_depressurizer_grf_threshold)) {
871+
StringRef Val = A->getValue();
872+
unsigned Result;
873+
if (Val.getAsInteger(/*Radix=*/0, Result))
874+
return makeOptionError(*A, ApiOptions, /*IsInternal=*/false);
875+
Opts.DepressurizerGRFThreshold = Result;
876+
}
877+
if (opt::Arg *A = ApiOptions.getLastArg(OPT_depressurizer_flag_grf_tolerance)) {
878+
StringRef Val = A->getValue();
879+
unsigned Result;
880+
if (Val.getAsInteger(/*Radix=*/0, Result))
881+
return makeOptionError(*A, ApiOptions, /*IsInternal=*/false);
882+
Opts.DepressurizerFlagGRFTolerance = Result;
883+
}
884+
867885
return Error::success();
868886
}
869887

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ SPDX-License-Identifier: MIT
4040
#include "vc/Support/GenXDiagnostic.h"
4141
#include "vc/Support/ShaderDump.h"
4242
#include "vc/Utils/GenX/GlobalVariable.h"
43-
#include "vc/Utils/GenX/GRFSize.h"
4443
#include "vc/Utils/GenX/Intrinsics.h"
4544
#include "vc/Utils/GenX/IntrinsicsWrapper.h"
4645
#include "vc/Utils/GenX/KernelInfo.h"
@@ -950,7 +949,19 @@ static void addKernelAttrsFromMetadata(VISAKernel &Kernel,
950949
Kernel.AddKernelAttribute("NBarrierCnt", sizeof(BarrierCnt), &BarrierCnt);
951950
}
952951

953-
int NumGRF = vc::getGRFSize(BC, Subtarget, KM);
952+
int NumGRF = -1;
953+
// Set by compile option.
954+
if (BC->isAutoLargeGRFMode())
955+
NumGRF = 0;
956+
if (BC->getGRFSize())
957+
NumGRF = BC->getGRFSize();
958+
// Set by kernel metadata.
959+
if (KM.getGRFSize()) {
960+
unsigned NumGRFPerKernel = *KM.getGRFSize();
961+
if (NumGRFPerKernel == 0 || Subtarget->isValidGRFSize(NumGRFPerKernel))
962+
NumGRF = NumGRFPerKernel;
963+
}
964+
954965
if (NumGRF != -1)
955966
Kernel.AddKernelAttribute("NumGRF", sizeof(NumGRF), &NumGRF);
956967
}

IGC/VectorCompiler/lib/GenXCodeGen/GenXDepressurizer.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,11 @@ SPDX-License-Identifier: MIT
109109
#include "GenXIntrinsics.h"
110110
#include "GenXLiveness.h"
111111
#include "GenXModule.h"
112-
#include "GenXTargetMachine.h"
113112
#include "GenXUtil.h"
114113

115-
#include "vc/Utils/GenX/GRFSize.h"
116-
117114
#include "llvm/ADT/SmallSet.h"
118115
#include "llvm/ADT/Statistic.h"
119116
#include "llvm/Analysis/LoopInfo.h"
120-
#include "llvm/CodeGen/TargetPassConfig.h"
121-
#include "llvm/InitializePasses.h"
122117
#include "llvm/IR/BasicBlock.h"
123118
#include "llvm/IR/Dominators.h"
124119
#include "llvm/IR/Function.h"
@@ -342,8 +337,6 @@ class GenXDepressurizer : public FGPassImplInterface,
342337
bool Modified = false;
343338
GenXGroupBaling *Baling = nullptr;
344339
const GenXBackendConfig *BC = nullptr;
345-
const GenXSubtarget *ST = nullptr;
346-
const vc::KernelMetadata *KM = nullptr;
347340
DominatorTree *DT = nullptr;
348341
LoopInfoBase<BasicBlock, Loop> *LI = nullptr;
349342
PseudoCFG *PCFG = nullptr;
@@ -395,11 +388,10 @@ using GenXDepressurizerWrapper = FunctionGroupWrapperPass<GenXDepressurizer>;
395388
}
396389
INITIALIZE_PASS_BEGIN(GenXDepressurizerWrapper, "GenXDepressurizerWrapper",
397390
"GenXDepressurizerWrapper", false, false)
398-
INITIALIZE_PASS_DEPENDENCY(GenXBackendConfig)
399-
INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
400391
INITIALIZE_PASS_DEPENDENCY(DominatorTreeGroupWrapperPassWrapper)
401392
INITIALIZE_PASS_DEPENDENCY(GenXLivenessWrapper)
402393
INITIALIZE_PASS_DEPENDENCY(GenXGroupBalingWrapper)
394+
INITIALIZE_PASS_DEPENDENCY(GenXBackendConfig)
403395
INITIALIZE_PASS_END(GenXDepressurizerWrapper, "GenXDepressurizerWrapper",
404396
"GenXDepressurizerWrapper", false, false)
405397

@@ -412,13 +404,11 @@ void GenXDepressurizer::getAnalysisUsage(AnalysisUsage &AU) {
412404
AU.addRequired<DominatorTreeGroupWrapperPass>();
413405
AU.addRequired<GenXGroupBaling>();
414406
AU.addRequired<GenXBackendConfig>();
415-
AU.addRequired<TargetPassConfig>();
416407
AU.addPreserved<DominatorTreeGroupWrapperPass>();
417408
AU.addPreserved<GenXModule>();
418409
AU.addPreserved<GenXLiveness>();
419410
AU.addPreserved<GenXGroupBaling>();
420411
AU.addPreserved<GenXBackendConfig>();
421-
AU.addPreserved<TargetPassConfig>();
422412
AU.addPreserved<FunctionGroupAnalysis>();
423413
AU.setPreservesCFG();
424414
}
@@ -435,20 +425,8 @@ bool GenXDepressurizer::runOnFunctionGroup(FunctionGroup &FG) {
435425
SunkCount = 0;
436426
Baling = &getAnalysis<GenXGroupBaling>();
437427
BC = &getAnalysis<GenXBackendConfig>();
438-
ST = &getAnalysis<TargetPassConfig>()
439-
.getTM<GenXTargetMachine>()
440-
.getGenXSubtarget();
441-
vc::KernelMetadata KM(FG.getHead());
442-
// Historically the general register pressure threshold was set to 2560 for
443-
// 128*32 byte GRF case, which means that only 48 registers are left for
444-
// allocation. The flag tolerance threshold was set to 3840, which means 120
445-
// registers. In case of different GRF size these thresholds should be
446-
// calculated accordingly.
447-
unsigned RegSize = ST->getGRFByteSize();
448-
int GRFSize = vc::getGRFSize(BC, ST, KM);
449-
unsigned NumRegs = (GRFSize > 0 ? GRFSize : 128);
450-
GRFThreshold = NumRegs > 48 ? (NumRegs - 48) * RegSize : 0;
451-
FlagGRFTolerance = 120 * RegSize;
428+
GRFThreshold = BC->getDepressurizerGRFThreshold();
429+
FlagGRFTolerance = BC->getDepressurizerFlagGRFTolerance();
452430
// Process functions in the function group in reverse order, so we know the
453431
// max pressure in a subroutine when we see a call to it.
454432
for (auto fgi = FG.rbegin(), fge = FG.rend(); fgi != fge; ++fgi) {
@@ -913,8 +891,7 @@ void GenXDepressurizer::attemptSinking(Instruction *InsertBefore,
913891
bool IsFlag = Liveness::isFlag(Inst);
914892
bool IsAddr = Liveness::isAddr(Inst);
915893
if (!IsFlag && !IsAddr &&
916-
Inst->getType()->getPrimitiveSizeInBits() <
917-
ST->getGRFByteSize() * genx::ByteBits) {
894+
Inst->getType()->getPrimitiveSizeInBits() < 32 * 8) {
918895
// don't bother with anything smaller than a GRF unless it is a flag
919896
continue;
920897
}

IGC/VectorCompiler/lib/Support/BackendConfig.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2020-2023 Intel Corporation
3+
Copyright (C) 2020-2025 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -151,6 +151,13 @@ static cl::opt<bool>
151151
cl::desc("Find, report and fixup clobbered GV load "
152152
"users before coalescing happened."));
153153

154+
static cl::opt<unsigned> DepressurizerGRFThresholdOpt(
155+
"depressurizer-grf-threshold", cl::Hidden,
156+
cl::desc("Threshold for GRF pressure reduction"));
157+
static cl::opt<unsigned> DepressurizerFlagGRFToleranceOpt(
158+
"depressurizer-flag-grf-tolerance", cl::Hidden,
159+
cl::desc("Threshold for disabling flag pressure reduction"));
160+
154161
//===----------------------------------------------------------------------===//
155162
//
156163
// Backend config related stuff.
@@ -198,6 +205,8 @@ void GenXBackendOptions::enforceLLVMOptions() {
198205
VCIgnoreLoopUnrollThresholdOnPragma);
199206
enforceOptionIfSpecified(InteropSubgroupSize, InteropSubgroupSizeOpt);
200207
enforceOptionIfSpecified(CheckGVClobbering, CheckGVClobberingOpt);
208+
enforceOptionIfSpecified(DepressurizerGRFThreshold, DepressurizerGRFThresholdOpt);
209+
enforceOptionIfSpecified(DepressurizerFlagGRFTolerance, DepressurizerFlagGRFToleranceOpt);
201210
}
202211

203212
static std::unique_ptr<MemoryBuffer>

0 commit comments

Comments
 (0)