Skip to content

Commit ea6a3a3

Browse files
authored
[SYCL][Driver] Add deprecated warning for backend GRF options on PVC (#12029)
With the `-ftarget-register-alloc-mode` option, the user doesn't need to pass IGC flags to the compiler to set the GRF mode. On PVC, emit a warning in the most common case to suggest the user use the new option. This doesn't catch every case because the `-device` syntax is complicated, but it can help in the most common use case. --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 06b0db6 commit ea6a3a3

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ def err_drv_fsycl_wrong_optimization_options : Error<
399399
def warn_drv_fsycl_add_default_spec_consts_image_flag_in_non_AOT : Warning<
400400
"-fsycl-add-default-spec-consts-image flag has an effect only in Ahead of Time Compilation mode (AOT).">,
401401
InGroup<SyclTarget>;
402+
def warn_drv_ftarget_register_alloc_mode_pvc : Warning<
403+
"using '%0' to set GRF mode on PVC hardware is deprecated; use '-ftarget-register-alloc-mode=pvc:%1'">,
404+
InGroup<Deprecated>;
402405
def err_drv_multiple_target_with_forced_target : Error<
403406
"multiple target usage with '%0' is not supported with '%1'">;
404407
def err_drv_failed_to_deduce_target_from_arch : Error<

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,15 @@ void SYCL::fpga::BackendCompiler::ConstructJob(
781781
C.addCommand(std::move(Cmd));
782782
}
783783

784+
static llvm::StringMap<StringRef> GRFModeFlagMap{
785+
{"auto", "-ze-intel-enable-auto-large-GRF-mode"},
786+
{"small", "-ze-intel-128-GRF-per-thread"},
787+
{"large", "-ze-opt-large-register-file"}};
788+
784789
StringRef SYCL::gen::getGenGRFFlag(StringRef GRFMode) {
785-
return llvm::StringSwitch<StringRef>(GRFMode)
786-
.Case("auto", "-ze-intel-enable-auto-large-GRF-mode")
787-
.Case("small", "-ze-intel-128-GRF-per-thread")
788-
.Case("large", "-ze-opt-large-register-file")
789-
.Default("");
790+
if (!GRFModeFlagMap.contains(GRFMode))
791+
return "";
792+
return GRFModeFlagMap[GRFMode];
790793
}
791794

792795
void SYCL::gen::BackendCompiler::ConstructJob(Compilation &C,
@@ -1100,6 +1103,26 @@ void SYCLToolChain::TranslateGPUTargetOpt(const llvm::opt::ArgList &Args,
11001103
}
11011104
}
11021105

1106+
static void WarnForDeprecatedBackendOpts(const Driver &D,
1107+
const llvm::Triple &Triple,
1108+
StringRef Device, StringRef ArgString,
1109+
const llvm::opt::Arg *A) {
1110+
// Suggest users passing GRF backend opts on PVC to use
1111+
// -ftarget-register-alloc-mode and
1112+
1113+
if (!ArgString.contains("-device pvc") && !Device.contains("pvc"))
1114+
return;
1115+
// Make sure to only warn for once for gen targets as the translate
1116+
// options tree is called twice but only the second time has the
1117+
// device set.
1118+
if (Triple.isSPIR() && Triple.getSubArch() == llvm::Triple::SPIRSubArch_gen &&
1119+
!A->isClaimed())
1120+
return;
1121+
for (const auto &[Mode, Flag] : GRFModeFlagMap)
1122+
if (ArgString.contains(Flag))
1123+
D.Diag(diag::warn_drv_ftarget_register_alloc_mode_pvc) << Flag << Mode;
1124+
}
1125+
11031126
// Expects a specific type of option (e.g. -Xsycl-target-backend) and will
11041127
// extract the arguments.
11051128
void SYCLToolChain::TranslateTargetOpt(const llvm::opt::ArgList &Args,
@@ -1143,7 +1166,8 @@ void SYCLToolChain::TranslateTargetOpt(const llvm::opt::ArgList &Args,
11431166
} else
11441167
// Triple found, add the next argument in line.
11451168
ArgString = A->getValue(1);
1146-
1169+
WarnForDeprecatedBackendOpts(getDriver(), getTriple(), Device, ArgString,
1170+
A);
11471171
parseTargetOpts(ArgString, Args, CmdArgs);
11481172
A->claim();
11491173
}
@@ -1313,12 +1337,15 @@ void SYCLToolChain::TranslateBackendTargetArgs(
13131337
if (A->getOption().matches(options::OPT_Xs)) {
13141338
// Take the arg and create an option out of it.
13151339
CmdArgs.push_back(Args.MakeArgString(Twine("-") + A->getValue()));
1340+
WarnForDeprecatedBackendOpts(getDriver(), Triple, Device, A->getValue(),
1341+
A);
13161342
A->claim();
13171343
continue;
13181344
}
13191345
if (A->getOption().matches(options::OPT_Xs_separate)) {
13201346
StringRef ArgString(A->getValue());
13211347
parseTargetOpts(ArgString, Args, CmdArgs);
1348+
WarnForDeprecatedBackendOpts(getDriver(), Triple, Device, ArgString, A);
13221349
A->claim();
13231350
continue;
13241351
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Test warning SYCL -ftarget-register-alloc-mode for pvc
2+
3+
// RUN: %clang -fsycl -Xs "-device pvc -ze-opt-large-register-file" -### %s 2>&1 | FileCheck -check-prefix=LARGE %s
4+
// RUN: %clang -fsycl -Xs "-device pvc -ze-intel-128-GRF-per-thread" -### %s 2>&1 | FileCheck -check-prefix=SMALL %s
5+
// RUN: %clang -fsycl -Xs "-ze-intel-enable-auto-large-GRF-mode -device pvc" -### %s 2>&1 | FileCheck -check-prefix=AUTO %s
6+
7+
// RUN: %clang -fsycl -fsycl-targets=intel_gpu_pvc -Xs "-ze-opt-large-register-file" -### %s 2>&1 | FileCheck -check-prefix=LARGE %s
8+
9+
// RUN: %clang -fsycl -fsycl-targets=intel_gpu_pvc -Xs"-ze-opt-large-register-file" -### %s 2>&1 | FileCheck -check-prefix=LARGE %s
10+
11+
// RUN: %clang -fsycl -Xsycl-target-backend=spir64 "-device pvc -ze-intel-128-GRF-per-thread" -### %s 2>&1 | FileCheck -check-prefix=SMALL %s
12+
13+
// RUN: %clang -fsycl -fsycl-targets=intel_gpu_pvc -Xsycl-target-backend "-ze-opt-large-register-file" -### %s 2>&1 | FileCheck -check-prefix=LARGE %s
14+
15+
// RUN: %clang -fsycl -fsycl-targets=spir64_gen -Xs "-ze-opt-large-register-file -device pvc" -### %s 2>&1 | FileCheck -check-prefix=LARGE %s
16+
17+
// RUN: %clang -fsycl -fsycl-targets=spir64,spir64_gen -Xsycl-target-backend=spir64 "-ze-opt-large-register-file -device pvc" \
18+
// RUN: -Xsycl-target-backend=spir64_gen "-ze-intel-enable-auto-large-GRF-mode -device pvc" -### %s 2>&1 | FileCheck -check-prefixes=LARGE,AUTO %s
19+
20+
// LARGE: warning: using '-ze-opt-large-register-file' to set GRF mode on PVC hardware is deprecated; use '-ftarget-register-alloc-mode=pvc:large'
21+
// SMALL: warning: using '-ze-intel-128-GRF-per-thread' to set GRF mode on PVC hardware is deprecated; use '-ftarget-register-alloc-mode=pvc:small'
22+
// AUTO: warning: using '-ze-intel-enable-auto-large-GRF-mode' to set GRF mode on PVC hardware is deprecated; use '-ftarget-register-alloc-mode=pvc:auto'

0 commit comments

Comments
 (0)