Skip to content

Commit c56dc3d

Browse files
committed
[Driver][SYCL] Match up -device_options with -device for AOT GPU
The driver will add additional -ftarget-register-alloc-mode values to the spir64_gen AOT call to ocloc. These additional options are applied when a user specifies any of the accepted PVC values that can be handled by ocloc. These values can be 'pvc' or associated hex or version values. Match up the -device_options arg value with the -device arg that is passed on the command line. ocloc expects these to match in order to properly associate the option given after -device_options.
1 parent 4684463 commit c56dc3d

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ static OclocInfo PVCDevices[] = {
10331033

10341034
// Determine if any of the given arguments contain any PVC based values for
10351035
// the -device option.
1036-
static bool hasPVCDevice(const ArgStringList &CmdArgs) {
1036+
static bool hasPVCDevice(const ArgStringList &CmdArgs, std::string &DevArg) {
10371037
bool DeviceSeen = false;
10381038
StringRef DeviceArg;
10391039
for (StringRef Arg : CmdArgs) {
@@ -1074,16 +1074,22 @@ static bool hasPVCDevice(const ArgStringList &CmdArgs) {
10741074
// Check for device, version or hex (literal values)
10751075
for (unsigned int I = 0; I < std::size(PVCDevices); I++) {
10761076
if (SingleArg.equals_insensitive(PVCDevices[I].DeviceName) ||
1077-
SingleArg.equals_insensitive(PVCDevices[I].Version))
1077+
SingleArg.equals_insensitive(PVCDevices[I].Version)) {
1078+
DevArg = SingleArg.str();
10781079
return true;
1080+
}
10791081
for (int HexVal : PVCDevices[I].HexValues) {
10801082
int Value = 0;
1081-
if (!SingleArg.getAsInteger(0, Value) && Value == HexVal)
1083+
if (!SingleArg.getAsInteger(0, Value) && Value == HexVal) {
1084+
DevArg = SingleArg.str();
10821085
return true;
1086+
}
10831087
}
10841088
if (CheckShortVersion &&
1085-
StringRef(PVCDevices[I].Version).starts_with(SingleArg))
1089+
StringRef(PVCDevices[I].Version).starts_with(SingleArg)) {
1090+
DevArg = SingleArg.str();
10861091
return true;
1092+
}
10871093
}
10881094
}
10891095
return false;
@@ -1659,8 +1665,13 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
16591665
Args.AddAllArgValues(TargArgs, options::OPT_Xs, options::OPT_Xs_separate);
16601666
Args.AddAllArgValues(TargArgs, options::OPT_Xsycl_backend);
16611667
// Check for any -device settings.
1662-
if (IsJIT || Device == "pvc" || hasPVCDevice(TargArgs)) {
1668+
std::string DevArg("");
1669+
if (IsJIT || Device == "pvc" || hasPVCDevice(TargArgs, DevArg)) {
1670+
// The -device option passed in by the user may not be 'pvc'. Use the
1671+
// value provided by the user if it was specified.
16631672
StringRef DeviceName = "pvc";
1673+
if (!DevArg.empty())
1674+
DeviceName = DevArg;
16641675
StringRef BackendOptName = SYCL::gen::getGenGRFFlag("auto");
16651676
if (IsGen)
16661677
PerDeviceArgs.push_back(

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// RUN: %clang -### -fsycl --no-offload-new-driver \
44
// RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:auto %s 2>&1 \
5-
// RUN: | FileCheck -check-prefix=AUTO_AOT %s
5+
// RUN: | FileCheck -check-prefix=AUTO_AOT %s -DDEVICE=pvc
66

77
// RUN: %clang -### -fsycl --no-offload-new-driver \
88
// RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:large %s 2>&1 \
@@ -18,19 +18,19 @@
1818

1919
// RUN: %clang -### -fsycl --no-offload-new-driver \
2020
// 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
21+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc
2222

2323
// RUN: %clang -### -fsycl --no-offload-new-driver \
2424
// 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
25+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=0x0BD5
2626

2727
// RUN: %clang -### -fsycl --no-offload-new-driver \
2828
// 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
29+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=12.60.7
3030

3131
// RUN: %clang -### -fsycl --no-offload-new-driver \
3232
// RUN: -fsycl-targets=spir64_gen -Xs "-device pvc,mtl-s" %s 2>&1 \
33-
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s
33+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc
3434

3535
// RUN: %clang -### -fsycl --no-offload-new-driver \
3636
// RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:small,pvc:large %s 2>&1 \
@@ -88,7 +88,7 @@
8888

8989
// AUTO_AOT: ocloc{{.*}} "-output"
9090
// AUTO_AOT: -device_options
91-
// AUTO_AOT: pvc
91+
// AUTO_AOT: [[DEVICE]]
9292
// AUTO_AOT: "-ze-intel-enable-auto-large-GRF-mode"
9393

9494
// LARGE_AOT: ocloc{{.*}} "-output"

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// RUN: %clang -### -fsycl --offload-new-driver \
44
// RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:auto %s 2>&1 \
5-
// RUN: | FileCheck -check-prefix=AUTO_AOT %s
5+
// RUN: | FileCheck -check-prefix=AUTO_AOT %s -DDEVICE=pvc
66

77
// RUN: %clang -### -fsycl --offload-new-driver \
88
// RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:large %s 2>&1 \
@@ -18,19 +18,19 @@
1818

1919
// RUN: %clang -### -fsycl --offload-new-driver \
2020
// 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
21+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc
2222

2323
// RUN: %clang -### -fsycl --offload-new-driver \
2424
// 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
25+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=0x0BD5
2626

2727
// RUN: %clang -### -fsycl --offload-new-driver \
2828
// 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
29+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=12.60.7
3030

3131
// RUN: %clang -### -fsycl --offload-new-driver \
3232
// RUN: -fsycl-targets=spir64_gen -Xs "-device pvc,mtl-s" %s 2>&1 \
33-
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s
33+
// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc
3434

3535
// RUN: %clang -### -fsycl --offload-new-driver \
3636
// RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:small,pvc:large %s 2>&1 \
@@ -88,7 +88,7 @@
8888
// NO_PVC-NOT: -device_options
8989
// NO_PVC-NOT: -ze-opt-large-register-file
9090

91-
// AUTO_AOT: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spir64_gen-unknown-unknown,arch={{.*}},kind=sycl,compile-opts=-device_options pvc -ze-intel-enable-auto-large-GRF-mode{{.*}}"
91+
// AUTO_AOT: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spir64_gen-unknown-unknown,arch={{.*}},kind=sycl,compile-opts=-device_options [[DEVICE]] -ze-intel-enable-auto-large-GRF-mode{{.*}}"
9292

9393
// LARGE_AOT: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spir64_gen-unknown-unknown,arch=,kind=sycl,compile-opts=-device_options pvc -ze-opt-large-register-file"
9494

0 commit comments

Comments
 (0)