https://gcc.gnu.org/g:fb6d68b6bffe6570c3c4033334367510b2d769f8
commit fb6d68b6bffe6570c3c4033334367510b2d769f8 Author: Andrew Stubbs <[email protected]> Date: Fri Sep 4 15:14:08 2026 +0000 Add --param offload-gpu-mode This new option will be used to enable a new experimental SIMT implementation for AMD GCN, alongside the existing SIMD implementation. I'm adding it as a "param" because I don't intend that users will need to know about it, but may want to try it during the experimental phase. If the experiment is successful the "auto" mode will be changed, and users will continue to not need to know about it. It's possible that some use cases will perform better with a different mode, so the option will remain usable, but will always be a low-level "tweakable". gcc/ChangeLog: * doc/params.texi: Document --param=offload-gpu-mode. * flag-types.h (enum offload_gpu_modes): New type. * omp-general.cc (omp_max_simt_vf): Do SIMT for amdgcn, optionally. * params.opt: Add --param=offload-gpu-mode and the enum. Diff: --- gcc/doc/params.texi | 24 ++++++++++++++++++++++++ gcc/flag-types.h | 9 +++++++++ gcc/omp-general.cc | 15 ++++++++++++++- gcc/params.opt | 19 +++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/gcc/doc/params.texi b/gcc/doc/params.texi index 31b04688cf77..800732e86995 100644 --- a/gcc/doc/params.texi +++ b/gcc/doc/params.texi @@ -1950,6 +1950,30 @@ bubbles. This is the current default. Zero means the scheduling description might not be available/accurate or perhaps not applicable at all, such as for modern out-of-order processors. +@item offload-gpu-mode +Controls how vector parallel code is generated for OpenMP and OpenACC offload +kernels. Different modes may suit different use cases, and may be implemented +to differing levels of completion. Not all GPUs support all the modes. +@option{--param=offload-gpu-mode=auto} selects the recommended mode for each +GPU architecture. +@option{--param=offload-gpu-mode=simd} uses the autovectorizer for all kernel +code (default on AMD GCN, not available for NVPTX). In general, SIMD mode may +produce tighter loops, but performs very badly if the vectorizer fails (due to +function calls, pattern mismatches, or complex logic). The vectorizer is +active for all GPU code, at @option{-O2} or above; the OpenMP and OpenACC +directives are treated as optimization hints. +@option{--param=offload-gpu-mode=simt-directed} (default on NVPTX, experimental +on AMD GCN) uses SIMT code-generation for loops with an OpenMP @samp{simd} +directive, or an OpenACC @samp{loop vector} directive. Code that does not use +these directives will not make use of the vector hardware at all. +@samp{omp_get_num_threads} reports the wavefront/warp count. +@option{--param=offload-gpu-mode=simt} (experimental) uses SIMT for all code +parallelized with OpenMP threads (OpenACC behavior is unchanged from +@option{simt-directed} mode). The OpenMP @samp{simd} directive may be a no-op. +@samp{omp_get_num_threads} reports the total number of work-items/threads +across all wavefronts/warps. This mode most-closely imitates the LLVM +behavior. + @end table @node Target-Specific Parameters diff --git a/gcc/flag-types.h b/gcc/flag-types.h index dd5a4433605c..9fdf22033a7e 100644 --- a/gcc/flag-types.h +++ b/gcc/flag-types.h @@ -591,6 +591,15 @@ enum omp_target_mode_kind OMP_TARGET_MODE_OMPACC = 1 }; +/* Modes for -param=offload-gpu-mode. */ +enum offload_gpu_modes +{ + OFFLOAD_GPU_MODE_AUTO, + OFFLOAD_GPU_MODE_SIMD, + OFFLOAD_GPU_MODE_SIMT_DIRECTED, + OFFLOAD_GPU_MODE_SIMT +}; + #endif #endif /* ! GCC_FLAG_TYPES_H */ diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 5dd594ac2112..e10b6e23061a 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1062,7 +1062,20 @@ omp_max_simt_vf (void) if (ENABLE_OFFLOADING) for (const char *c = getenv ("OFFLOAD_TARGET_NAMES"); c;) { - if (startswith (c, "nvptx")) + if (startswith (c, "amdgcn")) + { + switch (param_offload_gpu_mode) + { + case OFFLOAD_GPU_MODE_SIMT: /* For now. */ + case OFFLOAD_GPU_MODE_SIMT_DIRECTED: + return 64; + case OFFLOAD_GPU_MODE_AUTO: + case OFFLOAD_GPU_MODE_SIMD: + return 0; + } + gcc_unreachable (); + } + else if (startswith (c, "nvptx")) return 32; else if ((c = strchr (c, ':'))) c++; diff --git a/gcc/params.opt b/gcc/params.opt index b35ca688cdf1..40418a294e15 100644 --- a/gcc/params.opt +++ b/gcc/params.opt @@ -882,6 +882,25 @@ The minimum probability of reaching a source block for interblock speculative sc Common Joined UInteger Var(param_min_vect_loop_bound) Param Optimization If -ftree-vectorize is used, the minimal loop bound of a loop to be considered for vectorization. +Enum +Name(offload_gpu_modes) Type(enum offload_gpu_modes) + +EnumValue +Enum(offload_gpu_modes) String(auto) Value(OFFLOAD_GPU_MODE_AUTO) + +EnumValue +Enum(offload_gpu_modes) String(simd) Value(OFFLOAD_GPU_MODE_SIMD) + +EnumValue +Enum(offload_gpu_modes) String(simt-directed) Value(OFFLOAD_GPU_MODE_SIMT_DIRECTED) + +EnumValue +Enum(offload_gpu_modes) String(simt) Value(OFFLOAD_GPU_MODE_SIMT) + +-param=offload-gpu-mode= +Common Joined Enum(offload_gpu_modes) Var(param_offload_gpu_mode) Init(OFFLOAD_GPU_MODE_AUTO) Param Optimization +--param=offload-gpu-mode=[auto|simd|simt-directed|simt] Specify what vector parallelization mode to use for GPU offload kernels. + -param=openacc-kernels= Common Joined Enum(openacc_kernels) Var(param_openacc_kernels) Init(OPENACC_KERNELS_PARLOOPS) Param --param=openacc-kernels=[decompose|parloops] Specify mode of OpenACC 'kernels' constructs handling.
