Skip to content

Commit 561dcb2

Browse files
authored
[Clang] Permit -Xarch_ to be used with --offload-arch (#131884)
Summary: The `--offload-arch` option is very complicated, but roughly behaves as the `-march` option for several compilations at once. This creates problems when we try to combine multiple separate architectures into one, as happens with SYCL, OpenMP, and HIP w/ SPIR-V. The existing solution used by OpenMP is the `-Xopenmp-target` option, this lets you select which `--offload-arch` options go to which toolchain. This patch permits `-Xarch_` to be used in the same way. There are concerns about whether or not this falls into the `-Xarch_` umbrella because it changes the driver behaviour, but I think this is the easiest way to handle this problem. The existing solution seems to be prefixing things and adding more magic handling into `--offload-arch`. Like SYCL is doing `nvidia_gpu_sm_89` instead of just `-Xarch_nvptx64 --offload-arch=sm_89`. The only reason this is more complicated than just doing `-Xarch_sm_89 -march=...` is because we need to know to create multiple jobs for each architecture.
1 parent 369be31 commit 561dcb2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clang/include/clang/Driver/Options.td

+1-2
Original file line numberDiff line numberDiff line change
@@ -1129,13 +1129,12 @@ def fno_convergent_functions : Flag<["-"], "fno-convergent-functions">,
11291129
// Common offloading options
11301130
let Group = offload_Group in {
11311131
def offload_arch_EQ : Joined<["--"], "offload-arch=">,
1132-
Visibility<[ClangOption, FlangOption]>, Flags<[NoXarchOption]>,
1132+
Visibility<[ClangOption, FlangOption]>,
11331133
HelpText<"Specify an offloading device architecture for CUDA, HIP, or OpenMP. (e.g. sm_35). "
11341134
"If 'native' is used the compiler will detect locally installed architectures. "
11351135
"For HIP offloading, the device architecture can be followed by target ID features "
11361136
"delimited by a colon (e.g. gfx908:xnack+:sramecc-). May be specified more than once.">;
11371137
def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">,
1138-
Flags<[NoXarchOption]>,
11391138
Visibility<[ClangOption, FlangOption]>,
11401139
HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, gfx906) from the list of devices to compile for. "
11411140
"'all' resets the list to its default value.">;

clang/test/Driver/offload-Xarch.c

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
// RUN: --target=x86_64-unknown-linux-gnu -Xopenmp-target=nvptx64-nvidia-cuda --offload-arch=sm_52,sm_60 -nogpuinc \
1515
// RUN: -Xopenmp-target=amdgcn-amd-amdhsa --offload-arch=gfx90a,gfx1030 -ccc-print-bindings -### %s 2>&1 \
1616
// RUN: | FileCheck -check-prefix=OPENMP %s
17+
// RUN: %clang -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda,amdgcn-amd-amdhsa -nogpulib \
18+
// RUN: --target=x86_64-unknown-linux-gnu -Xarch_nvptx64 --offload-arch=sm_52,sm_60 -nogpuinc \
19+
// RUN: -Xarch_amdgcn --offload-arch=gfx90a,gfx1030 -ccc-print-bindings -### %s 2>&1 \
20+
// RUN: | FileCheck -check-prefix=OPENMP %s
1721

1822
// OPENMP: # "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
1923
// OPENMP: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[GFX1030_BC:.+]]"

0 commit comments

Comments
 (0)