Skip to content

Commit ca955e5

Browse files
authored
[DRIVER][SYCL] Update the SYCL triple parsing for AMD (#15990)
## Description This PR improves the SYCL target triple parsing for AMD GPUs by enforcing that the triple must be fully specified and explicit.
1 parent 33b50db commit ca955e5

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,10 @@ static bool isValidSYCLTriple(llvm::Triple T) {
823823
T.getOS() == llvm::Triple::CUDA && !T.hasEnvironment())
824824
return true;
825825

826-
// AMDGCN is valid for SYCL
827-
if (T.isAMDGCN())
826+
// 'amdgcn-amd-amdhsa' is the valid SYCL triple for AMD GPUs.
827+
if (T.getArch() == llvm::Triple::amdgcn &&
828+
T.getVendor() == llvm::Triple::AMD && T.getOS() == llvm::Triple::AMDHSA &&
829+
!T.hasEnvironment())
828830
return true;
829831

830832
// Check for invalid SYCL device triple values.

clang/test/Driver/sycl-offload-new-driver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@
163163
// WRAPPER_OPTIONS_BACKEND_AOT-SAME: "--cpu-tool-arg=-backend-cpu-opt"
164164

165165
/// Verify arch settings for nvptx and amdgcn targets
166-
// RUN: %clangxx -fsycl -### -fsycl-targets=amdgcn-amd-gpu -fno-sycl-libspirv \
166+
// RUN: %clangxx -fsycl -### -fsycl-targets=amdgcn-amd-amdhsa -fno-sycl-libspirv \
167167
// RUN: -nocudalib --offload-new-driver \
168-
// RUN: -Xsycl-target-backend=amdgcn-amd-gpu --offload-arch=gfx600 \
168+
// RUN: -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx600 \
169169
// RUN: %s 2>&1 \
170170
// RUN: | FileCheck -check-prefix AMD_ARCH %s
171-
// AMD_ARCH: clang-offload-packager{{.*}} "--image=file={{.*}},triple=amdgcn-amd-gpu,arch=gfx600,kind=sycl,compile-opts=--offload-arch=gfx600"
171+
// AMD_ARCH: clang-offload-packager{{.*}} "--image=file={{.*}},triple=amdgcn-amd-amdhsa,arch=gfx600,kind=sycl,compile-opts=--offload-arch=gfx600"
172172

173173
// RUN: %clangxx -fsycl -### -fsycl-targets=nvptx64-nvidia-cuda \
174174
// RUN: -fno-sycl-libspirv -nocudalib --offload-new-driver %s 2>&1 \

clang/test/Driver/sycl-oneapi-gpu-amdgpu.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@
136136
// RUN: FileCheck %s --check-prefix=BAD_AMD_INPUT
137137
// BAD_AMD_INPUT: error: SYCL target is invalid: 'amd_gpu_bad'
138138

139+
// Check the SYCL triple for AMD GPUs.
140+
// RUN: %clangxx -fsycl -nogpulib -fsycl-targets=amdgcn-amd-amdhsa -### \
141+
// RUN: -Xsycl-target-backend --offload-arch=gfx908 \
142+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc %s 2>&1 | \
143+
// RUN: FileCheck %s --check-prefixes=AMD-TRIPLE
144+
// AMD-TRIPLE: clang{{.*}} "-triple" "amdgcn-amd-amdhsa"
145+
146+
// Check if SYCL triples with 'Environment' component are rejected for AMD GPUs.
147+
// RUN: not %clangxx -c -fsycl -nogpulib -fsycl-targets=amdgcn-amd-amdhsa-sycl -### %s 2>&1 | \
148+
// RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE_ENV
149+
// RUN: not %clang_cl -c -fsycl -fsycl-targets=amdgcn-amd-amdhsa-sycl -### %s 2>&1 | \
150+
// RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE_ENV
151+
// BAD_TARGET_TRIPLE_ENV: error: SYCL target is invalid: 'amdgcn-amd-amdhsa-sycl'
152+
153+
// Check for invalid SYCL triple for AMD GPUs.
154+
// RUN: not %clangxx -c -fsycl -nogpulib -fsycl-targets=amdgcn -### %s 2>&1 | \
155+
// RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE
156+
// RUN: not %clang_cl -c -fsycl -fsycl-targets=amdgcn-amd -### %s 2>&1 | \
157+
// RUN: FileCheck %s --check-prefix=BAD_TARGET_TRIPLE
158+
// BAD_TARGET_TRIPLE: error: SYCL target is invalid: 'amdgcn{{.*}}'
159+
139160
/// Test for proper creation of fat object
140161
// RUN: %clangxx -fsycl -nogpulib -fsycl-targets=amd_gpu_gfx700 \
141162
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc \

sycl/doc/UsersManual.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ and not recommended to use in production environment.
4040
spir64_fpga-unknown-unknown, spir64_gen-unknown-unknown
4141
Available in special build configuration:
4242
* nvptx64-nvidia-cuda - generate code ahead of time for CUDA target;
43+
* amdgcn-amd-amdhsa - generate code ahead of time for HIP target;
4344
* native_cpu - allows to run SYCL applications with no need of an
4445
additional backend (note that this feature is WIP and experimental, and
4546
currently overrides all the other specified SYCL targets when enabled.)

0 commit comments

Comments
 (0)