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.
---
 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 e69be2d2923..e7ca0638d35 100644
--- a/gcc/doc/params.texi
+++ b/gcc/doc/params.texi
@@ -1967,6 +1967,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 df983d9d947..3395a28a5c6 100644
--- a/gcc/flag-types.h
+++ b/gcc/flag-types.h
@@ -593,6 +593,15 @@ enum omp_ompt_level
   OMP_OMPT_LEVEL_EXTENDED = 2
 };
 
+/* 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 564fe858cdd..4f03459a49a 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1042,7 +1042,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 0c6a3e51457..cb38eedb6b5 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -890,6 +890,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.
-- 
2.54.0

Reply via email to