From c56dc3d22cee6dccab6722c8152da17e962d9a62 Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Fri, 11 Oct 2024 17:11:52 -0700 Subject: [PATCH 1/2] [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. --- clang/lib/Driver/ToolChains/SYCL.cpp | 21 ++++++++++++++----- ...-ftarget-register-alloc-mode-old-model.cpp | 12 +++++------ .../sycl-ftarget-register-alloc-mode.cpp | 12 +++++------ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index c12685e52ff95..e6cf6ae0306e8 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -1033,7 +1033,7 @@ static OclocInfo PVCDevices[] = { // Determine if any of the given arguments contain any PVC based values for // the -device option. -static bool hasPVCDevice(const ArgStringList &CmdArgs) { +static bool hasPVCDevice(const ArgStringList &CmdArgs, std::string &DevArg) { bool DeviceSeen = false; StringRef DeviceArg; for (StringRef Arg : CmdArgs) { @@ -1074,16 +1074,22 @@ static bool hasPVCDevice(const ArgStringList &CmdArgs) { // Check for device, version or hex (literal values) for (unsigned int I = 0; I < std::size(PVCDevices); I++) { if (SingleArg.equals_insensitive(PVCDevices[I].DeviceName) || - SingleArg.equals_insensitive(PVCDevices[I].Version)) + SingleArg.equals_insensitive(PVCDevices[I].Version)) { + DevArg = SingleArg.str(); return true; + } for (int HexVal : PVCDevices[I].HexValues) { int Value = 0; - if (!SingleArg.getAsInteger(0, Value) && Value == HexVal) + if (!SingleArg.getAsInteger(0, Value) && Value == HexVal) { + DevArg = SingleArg.str(); return true; + } } if (CheckShortVersion && - StringRef(PVCDevices[I].Version).starts_with(SingleArg)) + StringRef(PVCDevices[I].Version).starts_with(SingleArg)) { + DevArg = SingleArg.str(); return true; + } } } return false; @@ -1659,8 +1665,13 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple, Args.AddAllArgValues(TargArgs, options::OPT_Xs, options::OPT_Xs_separate); Args.AddAllArgValues(TargArgs, options::OPT_Xsycl_backend); // Check for any -device settings. - if (IsJIT || Device == "pvc" || hasPVCDevice(TargArgs)) { + std::string DevArg(""); + if (IsJIT || Device == "pvc" || hasPVCDevice(TargArgs, DevArg)) { + // The -device option passed in by the user may not be 'pvc'. Use the + // value provided by the user if it was specified. StringRef DeviceName = "pvc"; + if (!DevArg.empty()) + DeviceName = DevArg; StringRef BackendOptName = SYCL::gen::getGenGRFFlag("auto"); if (IsGen) PerDeviceArgs.push_back( diff --git a/clang/test/Driver/sycl-ftarget-register-alloc-mode-old-model.cpp b/clang/test/Driver/sycl-ftarget-register-alloc-mode-old-model.cpp index 18be71d45dd9a..6b9591a85546b 100644 --- a/clang/test/Driver/sycl-ftarget-register-alloc-mode-old-model.cpp +++ b/clang/test/Driver/sycl-ftarget-register-alloc-mode-old-model.cpp @@ -2,7 +2,7 @@ // RUN: %clang -### -fsycl --no-offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:auto %s 2>&1 \ -// RUN: | FileCheck -check-prefix=AUTO_AOT %s +// RUN: | FileCheck -check-prefix=AUTO_AOT %s -DDEVICE=pvc // RUN: %clang -### -fsycl --no-offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:large %s 2>&1 \ @@ -18,19 +18,19 @@ // RUN: %clang -### -fsycl --no-offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device pvc" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc // RUN: %clang -### -fsycl --no-offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device 0x0BD5" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=0x0BD5 // RUN: %clang -### -fsycl --no-offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device 12.60.7" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=12.60.7 // RUN: %clang -### -fsycl --no-offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device pvc,mtl-s" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc // RUN: %clang -### -fsycl --no-offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:small,pvc:large %s 2>&1 \ @@ -88,7 +88,7 @@ // AUTO_AOT: ocloc{{.*}} "-output" // AUTO_AOT: -device_options -// AUTO_AOT: pvc +// AUTO_AOT: [[DEVICE]] // AUTO_AOT: "-ze-intel-enable-auto-large-GRF-mode" // LARGE_AOT: ocloc{{.*}} "-output" diff --git a/clang/test/Driver/sycl-ftarget-register-alloc-mode.cpp b/clang/test/Driver/sycl-ftarget-register-alloc-mode.cpp index 22e548ee27dfb..60b245522f796 100644 --- a/clang/test/Driver/sycl-ftarget-register-alloc-mode.cpp +++ b/clang/test/Driver/sycl-ftarget-register-alloc-mode.cpp @@ -2,7 +2,7 @@ // RUN: %clang -### -fsycl --offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:auto %s 2>&1 \ -// RUN: | FileCheck -check-prefix=AUTO_AOT %s +// RUN: | FileCheck -check-prefix=AUTO_AOT %s -DDEVICE=pvc // RUN: %clang -### -fsycl --offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:large %s 2>&1 \ @@ -18,19 +18,19 @@ // RUN: %clang -### -fsycl --offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device pvc" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc // RUN: %clang -### -fsycl --offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device 0x0BD5" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=0x0BD5 // RUN: %clang -### -fsycl --offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device 12.60.7" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=12.60.7 // RUN: %clang -### -fsycl --offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -Xs "-device pvc,mtl-s" %s 2>&1 \ -// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s +// RUN: | FileCheck %if system-windows %{ -check-prefix=DEFAULT_AOT %} %else %{ -check-prefix=AUTO_AOT %} %s -DDEVICE=pvc // RUN: %clang -### -fsycl --offload-new-driver \ // RUN: -fsycl-targets=spir64_gen -ftarget-register-alloc-mode=pvc:small,pvc:large %s 2>&1 \ @@ -88,7 +88,7 @@ // NO_PVC-NOT: -device_options // NO_PVC-NOT: -ze-opt-large-register-file -// 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{{.*}}" +// 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{{.*}}" // 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" From ce0b32fba079c0017c08e7ec9b6f83a9adf90500 Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Mon, 14 Oct 2024 12:13:13 -0700 Subject: [PATCH 2/2] Update var init --- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index e6cf6ae0306e8..0d287892aaf64 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -1665,7 +1665,7 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple, Args.AddAllArgValues(TargArgs, options::OPT_Xs, options::OPT_Xs_separate); Args.AddAllArgValues(TargArgs, options::OPT_Xsycl_backend); // Check for any -device settings. - std::string DevArg(""); + std::string DevArg; if (IsJIT || Device == "pvc" || hasPVCDevice(TargArgs, DevArg)) { // The -device option passed in by the user may not be 'pvc'. Use the // value provided by the user if it was specified.