From df24a26e2f13dcc721f1c576fe9341b996892ed2 Mon Sep 17 00:00:00 2001 From: Jefferson Le Quellec Date: Tue, 5 Nov 2024 16:08:18 +0100 Subject: [PATCH 1/5] Update the sycl triple parsing for AMD --- clang/lib/Driver/Driver.cpp | 6 ++++-- clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp | 21 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 71068f40d1337..13b87fc6831a5 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -816,8 +816,10 @@ static bool isValidSYCLTriple(llvm::Triple T) { T.getOS() == llvm::Triple::CUDA && !T.hasEnvironment()) return true; - // AMDGCN is valid for SYCL - if (T.isAMDGCN()) + // 'amdgcn-amd-amdhsa' is the valid SYCL triple for AMD GPUs. + if (T.getArch() == llvm::Triple::amdgcn && + T.getVendor() == llvm::Triple::AMD && T.getOS() == llvm::Triple::AMDHSA && + !T.hasEnvironment()) return true; // Check for invalid SYCL device triple values. diff --git a/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp b/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp index e6c8530c53130..e5d6bc066de62 100644 --- a/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp +++ b/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp @@ -136,6 +136,27 @@ // RUN: FileCheck %s --check-prefix=BAD_AMD_INPUT // BAD_AMD_INPUT: error: SYCL target is invalid: 'amd_gpu_bad' +// Check the SYCL triple for AMD GPUs. +// RUN: %clangxx -fsycl -fsycl-targets=amdgcn-amd-amdhsa -### \ +// RUN: -Xsycl-target-backend --offload-arch=gfx908 \ +// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc %s 2>&1 | \ +// RUN: FileCheck %s --check-prefixes=AMD-TRIPLE +// AMD-TRIPLE: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" + +// Check if SYCL triples with 'Environment' component are rejected for AMD GPUs. +// RUN: not %clangxx -c -fsycl -fsycl-targets=amdgcn-amd-amdhsa-sycl -### %s 2>&1 | \ + // RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE_ENV +// RUN: not %clang_cl -c -fsycl -fsycl-targets=amdgcn-amd-amdhsa-sycl -### %s 2>&1 | \ +// RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE_ENV +// BAD_TARGET_TRIPLE_ENV: error: SYCL target is invalid: 'amdgcn-amd-amdhsa-sycl' + +// Check for invalid SYCL triple for NVidia GPUs. +// RUN: not %clangxx -c -fsycl -fsycl-targets=amdgcn -### %s 2>&1 | \ +// RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE +// RUN: not %clang_cl -c -fsycl -fsycl-targets=amdgcn-amd -### %s 2>&1 | \ +// RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE +// BAD_TARGET_TRIPLE: error: SYCL target is invalid: 'amdgcn{{.*}}' + /// Test for proper creation of fat object // RUN: %clangxx -fsycl -nogpulib -fsycl-targets=amd_gpu_gfx700 \ // RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc \ From 599454dd0d3aeccbfc2f5f4bc4fb264d44444530 Mon Sep 17 00:00:00 2001 From: Jefferson Le Quellec Date: Wed, 6 Nov 2024 11:19:19 +0100 Subject: [PATCH 2/5] Fix typo in test description --- clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp b/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp index e5d6bc066de62..45659af90a38a 100644 --- a/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp +++ b/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp @@ -150,7 +150,7 @@ // RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE_ENV // BAD_TARGET_TRIPLE_ENV: error: SYCL target is invalid: 'amdgcn-amd-amdhsa-sycl' -// Check for invalid SYCL triple for NVidia GPUs. +// Check for invalid SYCL triple for AMD GPUs. // RUN: not %clangxx -c -fsycl -fsycl-targets=amdgcn -### %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE // RUN: not %clang_cl -c -fsycl -fsycl-targets=amdgcn-amd -### %s 2>&1 | \ From 0e3e6d234a94d7d54bba21ae7a7e43f500812b1d Mon Sep 17 00:00:00 2001 From: Jefferson Le Quellec Date: Wed, 6 Nov 2024 11:20:24 +0100 Subject: [PATCH 3/5] Fix sycl amd triple typo in test --- clang/test/Driver/sycl-offload-new-driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/test/Driver/sycl-offload-new-driver.c b/clang/test/Driver/sycl-offload-new-driver.c index fbadad2863360..b761f6c7559fb 100644 --- a/clang/test/Driver/sycl-offload-new-driver.c +++ b/clang/test/Driver/sycl-offload-new-driver.c @@ -163,12 +163,12 @@ // WRAPPER_OPTIONS_BACKEND_AOT-SAME: "--cpu-tool-arg=-backend-cpu-opt" /// Verify arch settings for nvptx and amdgcn targets -// RUN: %clangxx -fsycl -### -fsycl-targets=amdgcn-amd-gpu -fno-sycl-libspirv \ +// RUN: %clangxx -fsycl -### -fsycl-targets=amdgcn-amd-amdhsa -fno-sycl-libspirv \ // RUN: -nocudalib --offload-new-driver \ -// RUN: -Xsycl-target-backend=amdgcn-amd-gpu --offload-arch=gfx600 \ +// RUN: -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx600 \ // RUN: %s 2>&1 \ // RUN: | FileCheck -check-prefix AMD_ARCH %s -// AMD_ARCH: clang-offload-packager{{.*}} "--image=file={{.*}},triple=amdgcn-amd-gpu,arch=gfx600,kind=sycl,compile-opts=--offload-arch=gfx600" +// AMD_ARCH: clang-offload-packager{{.*}} "--image=file={{.*}},triple=amdgcn-amd-amdhsa,arch=gfx600,kind=sycl,compile-opts=--offload-arch=gfx600" // RUN: %clangxx -fsycl -### -fsycl-targets=nvptx64-nvidia-cuda \ // RUN: -fno-sycl-libspirv -nocudalib --offload-new-driver %s 2>&1 \ From 8f0acebd7f7d898c949bee8d4253c87a60a9d593 Mon Sep 17 00:00:00 2001 From: Jefferson Le Quellec Date: Tue, 3 Dec 2024 10:36:50 +0100 Subject: [PATCH 4/5] Update sycl user-manual with HIP target --- sycl/doc/UsersManual.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/doc/UsersManual.md b/sycl/doc/UsersManual.md index efdf03249616c..d23016e3e436e 100644 --- a/sycl/doc/UsersManual.md +++ b/sycl/doc/UsersManual.md @@ -40,6 +40,7 @@ and not recommended to use in production environment. spir64_fpga-unknown-unknown, spir64_gen-unknown-unknown Available in special build configuration: * nvptx64-nvidia-cuda - generate code ahead of time for CUDA target; + * amdgcn-amd-amdhsa - generate code ahead of time for HIP target; * native_cpu - allows to run SYCL applications with no need of an additional backend (note that this feature is WIP and experimental, and currently overrides all the other specified SYCL targets when enabled.) From 0e90b0c0004ce72dcb5b950f0c93b6b94ef219b1 Mon Sep 17 00:00:00 2001 From: Jefferson Le Quellec Date: Tue, 3 Dec 2024 16:03:55 +0100 Subject: [PATCH 5/5] Add missing 'nogpulib' to tests --- clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp b/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp index 45659af90a38a..4258f5b1f04cb 100644 --- a/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp +++ b/clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp @@ -137,21 +137,21 @@ // BAD_AMD_INPUT: error: SYCL target is invalid: 'amd_gpu_bad' // Check the SYCL triple for AMD GPUs. -// RUN: %clangxx -fsycl -fsycl-targets=amdgcn-amd-amdhsa -### \ +// RUN: %clangxx -fsycl -nogpulib -fsycl-targets=amdgcn-amd-amdhsa -### \ // RUN: -Xsycl-target-backend --offload-arch=gfx908 \ // RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc %s 2>&1 | \ // RUN: FileCheck %s --check-prefixes=AMD-TRIPLE // AMD-TRIPLE: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" // Check if SYCL triples with 'Environment' component are rejected for AMD GPUs. -// RUN: not %clangxx -c -fsycl -fsycl-targets=amdgcn-amd-amdhsa-sycl -### %s 2>&1 | \ +// RUN: not %clangxx -c -fsycl -nogpulib -fsycl-targets=amdgcn-amd-amdhsa-sycl -### %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE_ENV // RUN: not %clang_cl -c -fsycl -fsycl-targets=amdgcn-amd-amdhsa-sycl -### %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE_ENV // BAD_TARGET_TRIPLE_ENV: error: SYCL target is invalid: 'amdgcn-amd-amdhsa-sycl' // Check for invalid SYCL triple for AMD GPUs. -// RUN: not %clangxx -c -fsycl -fsycl-targets=amdgcn -### %s 2>&1 | \ +// RUN: not %clangxx -c -fsycl -nogpulib -fsycl-targets=amdgcn -### %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE // RUN: not %clang_cl -c -fsycl -fsycl-targets=amdgcn-amd -### %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE