From 0636c8852f56137b07e6c5627d15d8d9b258b3eb Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Fri, 12 Jul 2024 11:26:15 -0700 Subject: [PATCH 1/2] [Driver][SYCL] Handle invalid characters from device in temp files When using command lines such as -fsycl -fsycl-targets=spir64_gen --offload-new-driver -Xsycl-target-backend "-device *" there is a temporary file that is generated that contains the arch value. Eliminate any possible invalid characters from being used with this temporary file. --- clang/lib/Driver/Driver.cpp | 5 +++-- .../Driver/sycl-windows-device-filename.cpp | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 clang/test/Driver/sycl-windows-device-filename.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 6adfe28a57106..9c84865905922 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -9484,9 +9484,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, StringRef OffloadingPrefix) const { std::string BoundArch = OrigBoundArch.str(); if (is_style_windows(llvm::sys::path::Style::native)) { - // BoundArch may contains ':', which is invalid in file names on Windows, - // therefore replace it with '%'. + // BoundArch may contain ':' or '*', which is invalid in file names on + // Windows, therefore replace it with '@'. std::replace(BoundArch.begin(), BoundArch.end(), ':', '@'); + std::replace(BoundArch.begin(), BoundArch.end(), '*', '@'); } llvm::PrettyStackTraceString CrashInfo("Computing output path"); diff --git a/clang/test/Driver/sycl-windows-device-filename.cpp b/clang/test/Driver/sycl-windows-device-filename.cpp new file mode 100644 index 0000000000000..d179853c94fba --- /dev/null +++ b/clang/test/Driver/sycl-windows-device-filename.cpp @@ -0,0 +1,20 @@ +// Test valid file names from -device values for GPU +// REQUIRES: system-windows + +// RUN: %clang -### --target=x86_64-pc-windows-msvc -fsycl \ +// RUN: -fsycl-targets=spir64_gen --offload-new-driver \ +// RUN: -Xsycl-target-backend "-device arch1:arch2" %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CHECK_COLON + +// CHECK_COLON: sycl-windows-device-filename-arch1@arch2 +// CHECK_COLON: arch=arch1:arch2 +// CHECK_COLON-NOT: sycl-windows-device-filename-arch1:arch2 + +// RUN: %clang -### --target=x86_64-pc-windows-msvc -fsycl \ +// RUN: -fsycl-targets=spir64_gen --offload-new-driver \ +// RUN: -Xsycl-target-backend "-device *" %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CHECK_STAR + +// CHECK_STAR: sycl-windows-device-filename-@ +// CHECK_STAR: arch=* +// CHECK_STAR-NOT: sycl-windows-device-filename-* From 7eb00956e6a4cbd96a692e77a027aa3c25d62079 Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Wed, 24 Jul 2024 17:05:27 -0700 Subject: [PATCH 2/2] Add additional conversion for commas --- clang/lib/Driver/Driver.cpp | 3 +++ clang/test/Driver/sycl-offload-new-driver.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index f707a54e7c786..78da466894c52 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -9413,6 +9413,9 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, std::replace(BoundArch.begin(), BoundArch.end(), ':', '@'); std::replace(BoundArch.begin(), BoundArch.end(), '*', '@'); } + // BoundArch may contain ',', which may create strings that interfere with + // the StringMap for the clang-offload-packager input values. + std::replace(BoundArch.begin(), BoundArch.end(), ',', '@'); llvm::PrettyStackTraceString CrashInfo("Computing output path"); // Output to a user requested destination? diff --git a/clang/test/Driver/sycl-offload-new-driver.c b/clang/test/Driver/sycl-offload-new-driver.c index 25af834e35970..46b2c71ea8f76 100644 --- a/clang/test/Driver/sycl-offload-new-driver.c +++ b/clang/test/Driver/sycl-offload-new-driver.c @@ -175,3 +175,10 @@ // RUN: | FileCheck -check-prefix NVPTX_DEF_ARCH %s // NVPTX_DEF_ARCH: clang-offload-packager{{.*}} "--image=file={{.*}},triple=nvptx64-nvidia-cuda,arch=sm_50,kind=sycl" +/// Verify the filename being passed to the packager does not contain commas +/// that are used in -device settings. +// RUN: %clangxx -fsycl -### -fsycl-targets=spir64_gen --offload-new-driver \ +// RUN: -Xsycl-target-backend=spir64_gen "-device pvc,bdw" %s 2>&1 \ +// RUN: | FileCheck -check-prefix COMMA_FILE %s +// COMMA_FILE: clang-offload-packager{{.*}} "--image=file={{.*}}pvc@bdw{{.*}},triple=spir64_gen-unknown-unknown,arch=pvc,bdw,kind=sycl" +