Add the -msimt option, and ensure that it matches "--param offload-gpu-mode",
if set.

Also, disable vectorization in SIMT mode, and make just enough changes to the
libraries to get the build to succeed. The code is not actually compiled for
SIMT yet, of course.

gcc/ChangeLog:

        * config/gcn/gcn.opt (msimt): New option.
        * config/gcn/gcn.cc (gcn_parse_amdgpu_hsa_kernel_attribute): Diagnose
        disagreement between -msimt and --param=offload-gpu-mode.
        (gcn_vector_mode_supported_p): Return false in SIMT mode.
        (gcn_vectorize_preferred_simd_mode): Return word_mode in SIMT mode.
        * config/gcn/gcn.h (TARGET_CPU_CPP_BUILTINS): Define __SIMT__ in SIMT
        mode.
        * config/gcn/mkoffload.cc (main): Detect
        --param=offload-gpu-mode=simt* in COLLECT_GCC_OPTIONS, and pass
        -msimt to both the offload compiler and the linker.
        * config/gcn/t-gcn-hsa (MULTILIB_OPTIONS): Add msimt.
        (MULTILIB_DIRNAMES): Add simt.

libgcc/ChangeLog:

        * config/gcn/amdgcn_veclib.h: Do not define anything when __SIMT__ is
        defined.
        * config/gcn/lib2-vec_divmod-di.c: Likewise.
        * config/gcn/lib2-vec_divmod-hi.c: Likewise.
        * config/gcn/lib2-vec_divmod-qi.c: Likewise.
        * config/gcn/lib2-vec_divmod.c: Likewise.
---
 gcc/config/gcn/gcn.cc                  | 34 ++++++++++++++++++++++++++
 gcc/config/gcn/gcn.h                   |  2 ++
 gcc/config/gcn/gcn.opt                 |  4 +++
 gcc/config/gcn/mkoffload.cc            | 13 ++++++++++
 gcc/config/gcn/t-gcn-hsa               |  4 +--
 libgcc/config/gcn/amdgcn_veclib.h      |  4 +++
 libgcc/config/gcn/lib2-vec_divmod-di.c |  4 +++
 libgcc/config/gcn/lib2-vec_divmod-hi.c |  4 +++
 libgcc/config/gcn/lib2-vec_divmod-qi.c |  4 +++
 libgcc/config/gcn/lib2-vec_divmod.c    |  4 +++
 10 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index 3b54e2f091e..02d902c8c93 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -346,6 +346,34 @@ gcn_parse_amdgpu_hsa_kernel_attribute (struct 
gcn_kernel_args *args,
     {
       error ("too many arguments passed in sgpr registers");
     }
+
+  /* Ensure that the SIMD vs SIMT modes are in agreement.
+     Ideally, this would sit in gcn_option_override, but that runs before
+     LTO stream-in loads the values from the host compiler.   */
+  static bool gpu_mode_warned = false;
+  if (flag_openmp && !gpu_mode_warned)
+    switch (param_offload_gpu_mode)
+      {
+      case OFFLOAD_GPU_MODE_AUTO:
+      case OFFLOAD_GPU_MODE_SIMD:
+       if (flag_simt_mode)
+         {
+           gpu_mode_warned = 1;
+           error ("%<--param=offload-gpu-mode=auto|simd%> is incompatible "
+                  "with %<-msimt%>");
+         }
+       break;
+      case OFFLOAD_GPU_MODE_SIMT_DIRECTED:
+      case OFFLOAD_GPU_MODE_SIMT:
+       if (!flag_simt_mode)
+         {
+           gpu_mode_warned = 1;
+           error ("%<--param=offload-gpu-mode=simt-directed|simt%> is "
+                  "incompatible with %<-no-msimt%>");
+         }
+       break;
+      }
+
   return err;
 }
 
@@ -5308,6 +5336,9 @@ gcn_vectorize_vec_perm_const (machine_mode vmode, 
machine_mode op_mode,
 static bool
 gcn_vector_mode_supported_p (machine_mode mode)
 {
+  if (flag_simt_mode)
+    return false;
+
   return (mode == V64QImode || mode == V64HImode
          || mode == V64SImode || mode == V64DImode
          || mode == V64SFmode || mode == V64DFmode
@@ -5341,6 +5372,9 @@ gcn_vector_mode_supported_p (machine_mode mode)
 static machine_mode
 gcn_vectorize_preferred_simd_mode (scalar_mode mode)
 {
+  if (flag_simt_mode)
+    return word_mode;
+
   bool v32;
   if (gcn_preferred_vectorization_factor == 32)
     v32 = true;
diff --git a/gcc/config/gcn/gcn.h b/gcc/config/gcn/gcn.h
index 8582542e041..162a0434999 100644
--- a/gcc/config/gcn/gcn.h
+++ b/gcc/config/gcn/gcn.h
@@ -51,6 +51,8 @@ extern const struct gcn_device_def {
        builtin_define ("__RDNA3__");                                          \
       else                                                                     
\
        gcc_unreachable ();                                                    \
+      if (flag_simt_mode)                                                      
\
+        builtin_define ("__SIMT__");                                           
\
       char *name = (char *)xmalloc (strlen (gcn_devices[gcn_arch].name) + 5);  
\
       sprintf (name, "__%s__", gcn_devices[gcn_arch].name);                    
\
       char *p;                                                                 
\
diff --git a/gcc/config/gcn/gcn.opt b/gcc/config/gcn/gcn.opt
index acc61e4847b..b00adfbc2e1 100644
--- a/gcc/config/gcn/gcn.opt
+++ b/gcc/config/gcn/gcn.opt
@@ -119,3 +119,7 @@ Target Var(fake_exceptions) Init(0) Undocumented
 ; 'sorry, unimplemented: exception handling not supported' is skipped, code
 ; generation proceeds, and instead, exception handling constructs 'abort' at
 ; run time.  (..., or don't, if they're in dead code.)
+
+msimt
+Target Var(flag_simt_mode) Init(0) Undocumented
+Switch from SIMD mode to SIMT mode.
diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 65bd81b9ba4..f6b61cf4ea7 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -1060,6 +1060,7 @@ main (int argc, char **argv)
   bool fopenacc = false;
   bool fPIC = false;
   bool fpic = false;
+  bool simt = false;
   for (int i = 1; i < argc; i++)
     {
 #define STR "-foffload-abi="
@@ -1131,6 +1132,13 @@ main (int argc, char **argv)
        }
     }
 
+  /* Add -msimt when in SIMT mode, but that option doesn't get passed directly
+     to mkoffload, so let's check the environment.  */
+  const char *collect_gcc_options = getenv ("COLLECT_GCC_OPTIONS");
+  if (collect_gcc_options
+      && strstr (collect_gcc_options, "--param=offload-gpu-mode=simt"))
+    simt = true;
+
   check_for_missing_lib (elf_arch, default_arch);
 
   if (!(fopenacc ^ fopenmp))
@@ -1212,6 +1220,8 @@ main (int argc, char **argv)
   /* The host code may contain exception handling constructs.
      Handle these as good as we can.  */
   obstack_ptr_grow (&cc_argv_obstack, "-mfake-exceptions");
+  if (simt)
+    obstack_ptr_grow (&cc_argv_obstack, "-msimt");
 
   for (int ix = 1; ix != argc; ix++)
     {
@@ -1344,6 +1354,9 @@ main (int argc, char **argv)
                 || startswith (argv[i], "-march"))
          obstack_ptr_grow (&ld_argv_obstack, argv[i]);
 
+      if (simt)
+       obstack_ptr_grow (&ld_argv_obstack, "-msimt");
+
       obstack_ptr_grow (&cc_argv_obstack, "-dumpdir");
       obstack_ptr_grow (&cc_argv_obstack, "");
       obstack_ptr_grow (&cc_argv_obstack, "-dumpbase");
diff --git a/gcc/config/gcn/t-gcn-hsa b/gcc/config/gcn/t-gcn-hsa
index eaa54794aa9..e0ee5a081ea 100644
--- a/gcc/config/gcn/t-gcn-hsa
+++ b/gcc/config/gcn/t-gcn-hsa
@@ -42,8 +42,8 @@ empty :=
 space := $(empty) $(empty)
 comma := ,
 multilib_list := $(subst $(comma),$(space),$(TM_MULTILIB_CONFIG)) 
-MULTILIB_OPTIONS = $(subst $(space),/,$(addprefix march=,$(multilib_list)))
-MULTILIB_DIRNAMES = $(multilib_list)
+MULTILIB_OPTIONS = $(subst $(space),/,$(addprefix march=,$(multilib_list))) 
msimt
+MULTILIB_DIRNAMES = $(multilib_list) simt
 
 gcn-tree.o: $(srcdir)/config/gcn/gcn-tree.cc
        $(COMPILE) $<
diff --git a/libgcc/config/gcn/amdgcn_veclib.h 
b/libgcc/config/gcn/amdgcn_veclib.h
index 6d9e25b09ce..3f9bec2d47d 100644
--- a/libgcc/config/gcn/amdgcn_veclib.h
+++ b/libgcc/config/gcn/amdgcn_veclib.h
@@ -23,6 +23,8 @@
    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef __SIMT__
+
 typedef union {
   v2sf t_v2sf;
   v4sf t_v4sf;
@@ -321,3 +323,5 @@ FUN##v##COUNT##SUFFIX (v##COUNT##TYPE __arg1, 
v##COUNT##TYPE __arg2) \
   DEF_VARIANT (FUN, SUFFIX, OTYPE, TYPE, 16) \
   DEF_VARIANT (FUN, SUFFIX, OTYPE, TYPE, 32) \
   DEF_VARIANT (FUN, SUFFIX, OTYPE, TYPE, 64)
+
+#endif
diff --git a/libgcc/config/gcn/lib2-vec_divmod-di.c 
b/libgcc/config/gcn/lib2-vec_divmod-di.c
index 67bc2bc7955..accb2a02222 100644
--- a/libgcc/config/gcn/lib2-vec_divmod-di.c
+++ b/libgcc/config/gcn/lib2-vec_divmod-di.c
@@ -20,6 +20,8 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifndef __SIMT__
+
 #include "lib2-gcn.h"
 
 /* 64-bit V64SI divide and modulo as used in gcn.
@@ -116,3 +118,5 @@ DEF_VARIANTS_B (__divmod, di4, uti, di)
 DEF_VARIANTS (__udiv, di3, udi)
 DEF_VARIANTS (__umod, di3, udi)
 DEF_VARIANTS_B (__udivmod, di4, uti, udi)
+
+#endif
diff --git a/libgcc/config/gcn/lib2-vec_divmod-hi.c 
b/libgcc/config/gcn/lib2-vec_divmod-hi.c
index 0fe0822a3fd..b1ab7fc41cb 100644
--- a/libgcc/config/gcn/lib2-vec_divmod-hi.c
+++ b/libgcc/config/gcn/lib2-vec_divmod-hi.c
@@ -20,6 +20,8 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifndef __SIMT__
+
 #include "lib2-gcn.h"
 
 /* 16-bit V64HI divide and modulo as used in gcn.
@@ -116,3 +118,5 @@ DEF_VARIANTS_B (__divmod, hi4, udi, hi)
 DEF_VARIANTS (__udiv, hi3, uhi)
 DEF_VARIANTS (__umod, hi3, uhi)
 DEF_VARIANTS_B (__udivmod, hi4, udi, uhi)
+
+#endif
diff --git a/libgcc/config/gcn/lib2-vec_divmod-qi.c 
b/libgcc/config/gcn/lib2-vec_divmod-qi.c
index cefbbd0b116..95edeaa8f6f 100644
--- a/libgcc/config/gcn/lib2-vec_divmod-qi.c
+++ b/libgcc/config/gcn/lib2-vec_divmod-qi.c
@@ -20,6 +20,8 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifndef __SIMT__
+
 #include "lib2-gcn.h"
 
 /* 8-bit V64QI divide and modulo as used in gcn.
@@ -116,3 +118,5 @@ DEF_VARIANTS_B (__divmod, qi4, udi, qi)
 DEF_VARIANTS (__udiv, qi3, uqi)
 DEF_VARIANTS (__umod, qi3, uqi)
 DEF_VARIANTS_B (__udivmod, qi4, udi, uqi)
+
+#endif
diff --git a/libgcc/config/gcn/lib2-vec_divmod.c 
b/libgcc/config/gcn/lib2-vec_divmod.c
index 28ccb1f5e18..7978d84467f 100644
--- a/libgcc/config/gcn/lib2-vec_divmod.c
+++ b/libgcc/config/gcn/lib2-vec_divmod.c
@@ -20,6 +20,8 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifndef __SIMT__
+
 #include "lib2-gcn.h"
 
 /* 32-bit V64SI divide and modulo as used in gcn.
@@ -116,3 +118,5 @@ DEF_VARIANTS_B (__divmod, si4, udi, si)
 DEF_VARIANTS (__udiv, si3, usi)
 DEF_VARIANTS (__umod, si3, usi)
 DEF_VARIANTS_B (__udivmod, si4, udi, usi)
+
+#endif
-- 
2.54.0

Reply via email to