Skip to content

Commit 761a5f2

Browse files
authored
[Driver][SYCL] Do not pass along implied PVC specific values for AOT (#13794)
When compiling for AOT GPU, we passed along default device settings for PVC regardless of intended device. Update this behavior to only pass along the PVC specific options to ocloc when the matching device (i.e. -device pvc) is also supplied. The device can be specific with the typical device value (pvc) or via the -fsycl-targets=intel_gpu_pvc option setting or -device values that match with PVC that match a given version or HEX value. The default values will continue to be passed along for JIT.
1 parent cca924c commit 761a5f2

File tree

3 files changed

+129
-18
lines changed

3 files changed

+129
-18
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,83 @@ void SYCL::fpga::BackendCompiler::ConstructJob(
865865
C.addCommand(std::move(Cmd));
866866
}
867867

868+
struct OclocInfo {
869+
const char *DeviceName;
870+
const char *PackageName;
871+
const char *Version;
872+
SmallVector<int, 8> HexValues;
873+
};
874+
875+
// The PVCDevices data structure is organized by device name, with the
876+
// corresponding ocloc split release, version and possible Hex representations
877+
// of various PVC devices. This information is gathered from the following:
878+
// https://github.com/intel/compute-runtime/blob/master/shared/source/dll/devices/devices_base.inl
879+
// https://github.com/intel/compute-runtime/blob/master/shared/source/dll/devices/devices_additional.inl
880+
static OclocInfo PVCDevices[] = {
881+
{"pvc-sdv", "gen12+", "12.60.1", {}},
882+
{"pvc",
883+
"gen12+",
884+
"12.60.7",
885+
{0x0BD0, 0x0BD5, 0x0BD6, 0x0BD7, 0x0BD8, 0x0BD9, 0x0BDA, 0x0BDB}}};
886+
887+
// Determine if any of the given arguments contain any PVC based values for
888+
// the -device option.
889+
static bool hasPVCDevice(const ArgStringList &CmdArgs) {
890+
bool DeviceSeen = false;
891+
StringRef DeviceArg;
892+
for (StringRef Arg : CmdArgs) {
893+
// -device <arg> comes in as a single arg, split up all potential space
894+
// separated values.
895+
SmallVector<StringRef> SplitArgs;
896+
Arg.split(SplitArgs, ' ');
897+
for (StringRef SplitArg : SplitArgs) {
898+
if (DeviceSeen) {
899+
DeviceArg = SplitArg;
900+
break;
901+
}
902+
if (SplitArg.equals("-device"))
903+
DeviceSeen = true;
904+
}
905+
if (DeviceSeen)
906+
break;
907+
}
908+
if (DeviceArg.empty())
909+
return false;
910+
911+
// Go through all of the arguments to '-device' and determine if any of these
912+
// are pvc based. We only match literal values and will not find a match
913+
// when ranges or wildcards are used.
914+
// Here we parse the targets, tokenizing via ','
915+
SmallVector<StringRef> SplitArgs;
916+
DeviceArg.split(SplitArgs, ",");
917+
for (const auto &SingleArg : SplitArgs) {
918+
StringRef OclocTarget;
919+
// Handle shortened versions.
920+
bool CheckShortVersion = true;
921+
for (auto Char : SingleArg.str()) {
922+
if (!std::isdigit(Char) && Char != '.') {
923+
CheckShortVersion = false;
924+
break;
925+
}
926+
}
927+
// Check for device, version or hex (literal values)
928+
for (unsigned int I = 0; I < std::size(PVCDevices); I++) {
929+
if (SingleArg.equals_insensitive(PVCDevices[I].DeviceName) ||
930+
SingleArg.equals_insensitive(PVCDevices[I].Version))
931+
return true;
932+
for (int HexVal : PVCDevices[I].HexValues) {
933+
int Value = 0;
934+
if (!SingleArg.getAsInteger(0, Value) && Value == HexVal)
935+
return true;
936+
}
937+
if (CheckShortVersion &&
938+
StringRef(PVCDevices[I].Version).starts_with(SingleArg))
939+
return true;
940+
}
941+
}
942+
return false;
943+
}
944+
868945
static llvm::StringMap<StringRef> GRFModeFlagMap{
869946
{"auto", "-ze-intel-enable-auto-large-GRF-mode"},
870947
{"small", "-ze-intel-128-GRF-per-thread"},
@@ -902,7 +979,7 @@ void SYCL::gen::BackendCompiler::ConstructJob(Compilation &C,
902979
static_cast<const toolchains::SYCLToolChain &>(getToolChain());
903980
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
904981
TC.AddImpliedTargetArgs(getToolChain().getTriple(), Args, CmdArgs, JA,
905-
*HostTC);
982+
*HostTC, Device);
906983
TC.TranslateBackendTargetArgs(getToolChain().getTriple(), Args, CmdArgs,
907984
Device);
908985
TC.TranslateLinkerTargetArgs(getToolChain().getTriple(), Args, CmdArgs);
@@ -1358,7 +1435,8 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
13581435
const llvm::opt::ArgList &Args,
13591436
llvm::opt::ArgStringList &CmdArgs,
13601437
const JobAction &JA,
1361-
const ToolChain &HostTC) const {
1438+
const ToolChain &HostTC,
1439+
StringRef Device) const {
13621440
// Current implied args are for debug information and disabling of
13631441
// optimizations. They are passed along to the respective areas as follows:
13641442
// FPGA: -g -cl-opt-disable
@@ -1371,6 +1449,8 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
13711449
// string
13721450
llvm::SmallVector<std::pair<StringRef, StringRef>, 16> PerDeviceArgs;
13731451
bool IsGen = Triple.getSubArch() == llvm::Triple::SPIRSubArch_gen;
1452+
bool IsJIT =
1453+
Triple.isSPIROrSPIRV() && Triple.getSubArch() == llvm::Triple::NoSubArch;
13741454
if (Arg *A = Args.getLastArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
13751455
if (!A->getOption().matches(options::OPT_g0))
13761456
BeArgs.push_back("-g");
@@ -1401,8 +1481,7 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
14011481
// option to honor the user's specification.
14021482
PerDeviceArgs.push_back(
14031483
{DeviceName, Args.MakeArgString(BackendOptName)});
1404-
} else if (Triple.isSPIROrSPIRV() &&
1405-
Triple.getSubArch() == llvm::Triple::NoSubArch) {
1484+
} else if (IsJIT) {
14061485
// For JIT, pass -ftarget-register-alloc-mode=Device:BackendOpt to
14071486
// clang-offload-wrapper to be processed by the runtime.
14081487
BeArgs.push_back(Args.MakeArgString(RegAllocModeOptName + DeviceName +
@@ -1415,15 +1494,21 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
14151494
ProcessElement(Elem);
14161495
} else if (!HostTC.getTriple().isWindowsMSVCEnvironment()) {
14171496
// If -ftarget-register-alloc-mode is not specified, the default is
1418-
// pvc:default on Windows and and pvc:auto otherwise.
1419-
StringRef DeviceName = "pvc";
1420-
StringRef BackendOptName = SYCL::gen::getGenGRFFlag("auto");
1421-
if (IsGen)
1422-
PerDeviceArgs.push_back({DeviceName, Args.MakeArgString(BackendOptName)});
1423-
else if (Triple.isSPIROrSPIRV() &&
1424-
Triple.getSubArch() == llvm::Triple::NoSubArch) {
1425-
BeArgs.push_back(Args.MakeArgString(RegAllocModeOptName + DeviceName +
1426-
":" + BackendOptName));
1497+
// pvc:default on Windows and and pvc:auto otherwise when -device pvc is
1498+
// provided by the user.
1499+
ArgStringList TargArgs;
1500+
Args.AddAllArgValues(TargArgs, options::OPT_Xs, options::OPT_Xs_separate);
1501+
Args.AddAllArgValues(TargArgs, options::OPT_Xsycl_backend);
1502+
// Check for any -device settings.
1503+
if (IsJIT || Device == "pvc" || hasPVCDevice(TargArgs)) {
1504+
StringRef DeviceName = "pvc";
1505+
StringRef BackendOptName = SYCL::gen::getGenGRFFlag("auto");
1506+
if (IsGen)
1507+
PerDeviceArgs.push_back(
1508+
{DeviceName, Args.MakeArgString(BackendOptName)});
1509+
else if (IsJIT)
1510+
BeArgs.push_back(Args.MakeArgString(RegAllocModeOptName + DeviceName +
1511+
":" + BackendOptName));
14271512
}
14281513
}
14291514
// only pass -vpfp-relaxed for aoc with -fintelfpga and -fp-model=fast
@@ -1468,11 +1553,9 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
14681553
if (Args.hasFlag(options::OPT_ftarget_export_symbols,
14691554
options::OPT_fno_target_export_symbols, false))
14701555
BeArgs.push_back("-library-compilation");
1471-
} else if (Triple.getSubArch() == llvm::Triple::NoSubArch &&
1472-
Triple.isSPIROrSPIRV()) {
1556+
} else if (IsJIT)
14731557
// -ftarget-compile-fast JIT
14741558
Args.AddLastArg(BeArgs, options::OPT_ftarget_compile_fast);
1475-
}
14761559
if (IsGen) {
14771560
for (auto [DeviceName, BackendArgStr] : PerDeviceArgs) {
14781561
CmdArgs.push_back("-device_options");

clang/lib/Driver/ToolChains/SYCL.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain {
173173
void AddImpliedTargetArgs(const llvm::Triple &Triple,
174174
const llvm::opt::ArgList &Args,
175175
llvm::opt::ArgStringList &CmdArgs,
176-
const JobAction &JA, const ToolChain &HostTC) const;
176+
const JobAction &JA, const ToolChain &HostTC,
177+
StringRef Device = "") const;
177178
void TranslateBackendTargetArgs(const llvm::Triple &Triple,
178179
const llvm::opt::ArgList &Args,
179180
llvm::opt::ArgStringList &CmdArgs,

clang/test/Driver/sycl-ftarget-register-alloc-mode.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@
1717
// RUN: | FileCheck -check-prefix=DEFAULT_AOT %s
1818

1919
// RUN: %clang -### -fsycl \
20-
// RUN: -fsycl-targets=spir64_gen %s 2>&1 \
20+
// RUN: -fsycl-targets=spir64_gen -Xs "-device pvc" %s 2>&1 \
21+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s
22+
23+
// RUN: %clang -### -fsycl \
24+
// RUN: -fsycl-targets=spir64_gen -Xs "-device 0x0BD5" %s 2>&1 \
25+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s
26+
27+
// RUN: %clang -### -fsycl \
28+
// RUN: -fsycl-targets=spir64_gen -Xs "-device 12.60.7" %s 2>&1 \
29+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s
30+
31+
// RUN: %clang -### -fsycl \
32+
// RUN: -fsycl-targets=spir64_gen -Xs "-device pvc,mtl-s" %s 2>&1 \
2133
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s
2234

2335
// RUN: %clang -### -fsycl \
@@ -59,6 +71,21 @@
5971
// RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=dg2:superlarge %s 2>&1 \
6072
// RUN: | FileCheck -check-prefix=BAD_BOTH %s
6173

74+
// RUN: %clangxx -### -fsycl -fsycl-targets=spir64_gen -Xs "-device bdw" \
75+
// RUN: %s 2>&1 \
76+
// RUN: | FileCheck -check-prefix=NO_PVC %s
77+
78+
// RUN: %clangxx -### -fsycl -fsycl-targets=spir64_gen -Xs "-device *" \
79+
// RUN: %s 2>&1 \
80+
// RUN: | FileCheck -check-prefix=NO_PVC %s
81+
82+
// RUN: %clangxx -### -fsycl -fsycl-targets=spir64_gen -Xs "-device pvc:mtl-s" \
83+
// RUN: %s 2>&1 \
84+
// RUN: | FileCheck -check-prefix=NO_PVC %s
85+
86+
// NO_PVC-NOT: -device_options
87+
// NO_PVC-NOT: -ze-opt-large-register-file
88+
6289
// AUTO_AOT: ocloc{{.*}} "-output"
6390
// AUTO_AOT: -device_options
6491
// AUTO_AOT: pvc

0 commit comments

Comments
 (0)