public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4221] amdgcn: Implement -msram-ecc=any
@ 2021-10-07 10:32 Andrew Stubbs
  0 siblings, 0 replies; only message in thread
From: Andrew Stubbs @ 2021-10-07 10:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:205dafb6edeca08419f4a5976be79bf7c86fd9a1

commit r12-4221-g205dafb6edeca08419f4a5976be79bf7c86fd9a1
Author: Andrew Stubbs <ams@codesourcery.com>
Date:   Tue Sep 28 16:26:09 2021 +0100

    amdgcn: Implement -msram-ecc=any
    
    The option was already there, but just an alias for -msram-ecc=on.  Now that
    LLVM13 supports HSACOv4 and the new ELF flags I can implement the option
    properly.
    
    The "any" option is the default in order to ensure that library files work
    whichever way the user wants, which means we won't need multilibs to support
    the different SRAM ECC hardware configurations.
    
    gcc/ChangeLog:
    
            * config/gcn/gcn-hsa.h (SRAMOPT): Include the whole option string.
            Adjust for new -msram-ecc=any behaviour.
            (ASM_SPEC): Adjust -mxnack and -msram-ecc usage.
            * config/gcn/gcn.c (output_file_start): Implement -msram-ecc=any.
            * config/gcn/mkoffload.c (EF_AMDGPU_XNACK): Rename to ...
            (EF_AMDGPU_XNACK_V3): ... this.
            (EF_AMDGPU_SRAM_ECC): Rename to ...
            (EF_AMDGPU_SRAM_ECC_V3): ... this.
            (EF_AMDGPU_FEATURE_XNACK_V4): New.
            (EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4): New.
            (EF_AMDGPU_FEATURE_XNACK_ANY_V4): New.
            (EF_AMDGPU_FEATURE_XNACK_OFF_V4): New.
            (EF_AMDGPU_FEATURE_XNACK_ON_V4): New.
            (EF_AMDGPU_FEATURE_SRAMECC_V4): New.
            (EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4): New.
            (EF_AMDGPU_FEATURE_SRAMECC_ANY_V4): New.
            (EF_AMDGPU_FEATURE_SRAMECC_OFF_V4): New.
            (EF_AMDGPU_FEATURE_SRAMECC_ON_V4): New.
            (SET_XNACK_ON): New.
            (SET_XNACK_OFF): New.
            (TEST_XNACK): New.
            (SET_SRAM_ECC_ON): New.
            (SET_SRAM_ECC_ANY): New.
            (SET_SRAM_ECC_OFF): New.
            (TEST_SRAM_ECC_ANY): New.
            (TEST_SRAM_ECC_ON): New.
            (main): Implement HSACOv4 and -msram-ecc=any.

Diff:
---
 gcc/config/gcn/gcn-hsa.h   |  14 +++---
 gcc/config/gcn/gcn.c       |   8 +++-
 gcc/config/gcn/mkoffload.c | 112 +++++++++++++++++++++++++++++++++------------
 3 files changed, 96 insertions(+), 38 deletions(-)

diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h
index 60fd40a10b7..6a432d17d99 100644
--- a/gcc/config/gcn/gcn-hsa.h
+++ b/gcc/config/gcn/gcn-hsa.h
@@ -118,10 +118,12 @@ extern unsigned int gcn_local_sym_hash (const char *name);
 #endif
 
 #ifdef HAVE_GCN_ASM_V3_SYNTAX
-#define SRAMOPT "sram-ecc"
+#define SRAMOPT "!msram-ecc=off:-mattr=+sram-ecc;:-mattr=-sram-ecc"
 #endif
 #ifdef HAVE_GCN_ASM_V4_SYNTAX
-#define SRAMOPT "sramecc"
+/* In HSACOv4 no attribute setting means the binary supports "any" hardware
+   configuration.  The name of the attribute also changed.  */
+#define SRAMOPT "msram-ecc=on:-mattr=+sramecc;msram-ecc=off:-mattr=-sramecc"
 #endif
 #if !defined(SRAMOPT) && !defined(IN_LIBGCC2)
 #error "No assembler syntax configured"
@@ -143,11 +145,9 @@ extern unsigned int gcn_local_sym_hash (const char *name);
 #define ASM_SPEC  "-triple=amdgcn--amdhsa "  \
 		  "%:last_arg(%{march=*:-mcpu=%*}) " \
 		  HSACO3_SELECT_OPT \
-		  "-mattr=%{" X_FIJI X_900 X_906 X_908 \
-			    "mxnack:+xnack;:-xnack} " \
-		  /* FIXME: support "any" when we move to HSACOv4.  */ \
-		  "-mattr=%{" S_FIJI S_900 S_906 S_908 \
-			    "!msram-ecc=off:+" SRAMOPT ";:-" SRAMOPT "} " \
+		  "%{" X_FIJI X_900 X_906 X_908 \
+		     "mxnack:-mattr=+xnack;:-mattr=-xnack} " \
+		  "%{" S_FIJI S_900 S_906 S_908 SRAMOPT "} " \
 		  "-filetype=obj"
 #define LINK_SPEC "--pie --export-dynamic"
 #define LIB_SPEC  "-lc"
diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c
index 8517168ff0a..2e90f327c45 100644
--- a/gcc/config/gcn/gcn.c
+++ b/gcc/config/gcn/gcn.c
@@ -5265,9 +5265,13 @@ output_file_start (void)
   const char *sram_ecc = (flag_sram_ecc ? "+sram-ecc" : "");
 #endif
 #if HAVE_GCN_ASM_V4_SYNTAX
+  /* In HSACOv4 no attribute setting means the binary supports "any" hardware
+     configuration.  In GCC binaries, this is true for SRAM ECC, but not
+     XNACK.  */
   const char *xnack = (flag_xnack ? ":xnack+" : ":xnack-");
-  /* FIXME: support "any" when we move to HSACOv4.  */
-  const char *sram_ecc = (flag_sram_ecc ? ":sramecc+" : ":sramecc-");
+  const char *sram_ecc = (flag_sram_ecc == SRAM_ECC_ON ? ":sramecc+"
+			  : flag_sram_ecc == SRAM_ECC_OFF ? ":sramecc-"
+			  : "");
 #endif
   if (!use_xnack_attr)
     xnack = "";
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 732bdfd98e5..a3b22d059b9 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -54,8 +54,51 @@
 #undef  EF_AMDGPU_MACH_AMDGCN_GFX908
 #define EF_AMDGPU_MACH_AMDGCN_GFX908 0x30
 
-#define EF_AMDGPU_XNACK    0x100
-#define EF_AMDGPU_SRAM_ECC 0x200
+#define EF_AMDGPU_XNACK_V3    0x100
+#define EF_AMDGPU_SRAM_ECC_V3 0x200
+
+#define EF_AMDGPU_FEATURE_XNACK_V4	0x300  /* Mask.  */
+#define EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4	0x000
+#define EF_AMDGPU_FEATURE_XNACK_ANY_V4	0x100
+#define EF_AMDGPU_FEATURE_XNACK_OFF_V4	0x200
+#define EF_AMDGPU_FEATURE_XNACK_ON_V4	0x300
+
+#define EF_AMDGPU_FEATURE_SRAMECC_V4	0xc00  /* Mask.  */
+#define EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4	0x000
+#define EF_AMDGPU_FEATURE_SRAMECC_ANY_V4	0x400
+#define EF_AMDGPU_FEATURE_SRAMECC_OFF_V4	0x800
+#define EF_AMDGPU_FEATURE_SRAMECC_ON_V4		0xc00
+
+#ifdef HAVE_GCN_ASM_V3_SYNTAX
+#define SET_XNACK_ON(VAR) VAR |= EF_AMDGPU_XNACK_V3
+#define SET_XNACK_OFF(VAR) VAR &= ~EF_AMDGPU_XNACK_V3
+#define TEST_XNACK(VAR) (VAR & EF_AMDGPU_XNACK_V3)
+
+#define SET_SRAM_ECC_ON(VAR) VAR |= EF_AMDGPU_SRAM_ECC_V3
+#define SET_SRAM_ECC_ANY(VAR) SET_SRAM_ECC_ON (VAR)
+#define SET_SRAM_ECC_OFF(VAR) VAR &= ~EF_AMDGPU_SRAM_ECC_V3
+#define TEST_SRAM_ECC_ANY(VAR) 0 /* Not supported.  */
+#define TEST_SRAM_ECC_ON(VAR) (VAR & EF_AMDGPU_SRAM_ECC_V3)
+#endif
+#ifdef HAVE_GCN_ASM_V4_SYNTAX
+#define SET_XNACK_ON(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_XNACK_V4) \
+				 | EF_AMDGPU_FEATURE_XNACK_ON_V4)
+#define SET_XNACK_OFF(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_XNACK_V4) \
+				  | EF_AMDGPU_FEATURE_XNACK_OFF_V4)
+#define TEST_XNACK(VAR) ((VAR & EF_AMDGPU_FEATURE_XNACK_V4) \
+			 == EF_AMDGPU_FEATURE_XNACK_ON_V4)
+
+#define SET_SRAM_ECC_ON(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \
+				    | EF_AMDGPU_FEATURE_SRAMECC_ON_V4)
+#define SET_SRAM_ECC_ANY(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \
+				     | EF_AMDGPU_FEATURE_SRAMECC_ANY_V4)
+#define SET_SRAM_ECC_OFF(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \
+				     | EF_AMDGPU_FEATURE_SRAMECC_OFF_V4)
+#define TEST_SRAM_ECC_ANY(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) \
+				== EF_AMDGPU_FEATURE_SRAMECC_ANY_V4)
+#define TEST_SRAM_ECC_ON(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) \
+			       == EF_AMDGPU_FEATURE_SRAMECC_ON_V4)
+#endif
 
 #ifndef R_AMDGPU_NONE
 #define R_AMDGPU_NONE		0
@@ -80,7 +123,13 @@ static struct obstack files_to_cleanup;
 
 enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX803;  // Default GPU architecture.
-uint32_t elf_flags = 0;
+uint32_t elf_flags =
+#ifdef HAVE_GCN_ASM_V3_SYNTAX
+    0;
+#endif
+#ifdef HAVE_GCN_ASM_V4_SYNTAX
+    (EF_AMDGPU_FEATURE_XNACK_ANY_V4 | EF_AMDGPU_FEATURE_SRAMECC_ANY_V4);
+#endif
 
 /* Delete tempfiles.  */
 
@@ -851,23 +900,22 @@ main (int argc, char **argv)
       else if (strcmp (argv[i], "-fpic") == 0)
 	fpic = true;
       else if (strcmp (argv[i], "-mxnack") == 0)
-	elf_flags |= EF_AMDGPU_XNACK;
+	SET_XNACK_ON (elf_flags);
       else if (strcmp (argv[i], "-mno-xnack") == 0)
-	elf_flags &= ~EF_AMDGPU_XNACK;
+	SET_XNACK_OFF (elf_flags);
       else if (strcmp (argv[i], "-msram-ecc=on") == 0)
 	{
-	  elf_flags |= EF_AMDGPU_SRAM_ECC;
+	  SET_SRAM_ECC_ON (elf_flags);
 	  sram_seen = true;
 	}
       else if (strcmp (argv[i], "-msram-ecc=any") == 0)
 	{
-	  /* FIXME: change this when we move to HSACOv4.  */
-	  elf_flags |= EF_AMDGPU_SRAM_ECC;
+	  SET_SRAM_ECC_ANY (elf_flags);
 	  sram_seen = true;
 	}
       else if (strcmp (argv[i], "-msram-ecc=off") == 0)
 	{
-	  elf_flags &= ~EF_AMDGPU_SRAM_ECC;
+	  SET_SRAM_ECC_OFF (elf_flags);
 	  sram_seen = true;
 	}
       else if (strcmp (argv[i], "-save-temps") == 0)
@@ -890,23 +938,27 @@ main (int argc, char **argv)
   if (!(fopenacc ^ fopenmp))
     fatal_error (input_location, "either -fopenacc or -fopenmp must be set");
 
-  /* The SRAM-ECC feature defaults to "any" on GPUs where the feature is
-     available.  */
   if (!sram_seen)
-    switch (elf_arch)
-      {
-      case EF_AMDGPU_MACH_AMDGCN_GFX803:
-      case EF_AMDGPU_MACH_AMDGCN_GFX900:
-      case EF_AMDGPU_MACH_AMDGCN_GFX906:
+    {
+#ifdef HAVE_GCN_ASM_V3_SYNTAX
+      /* For HSACOv3, the SRAM-ECC feature defaults to "on" on GPUs where the
+	 feature is available.
+	 (HSACOv4 has elf_flags initialsed to "any" in all cases.)  */
+      switch (elf_arch)
+	{
+	case EF_AMDGPU_MACH_AMDGCN_GFX803:
+	case EF_AMDGPU_MACH_AMDGCN_GFX900:
+	case EF_AMDGPU_MACH_AMDGCN_GFX906:
 #ifndef HAVE_GCN_SRAM_ECC_GFX908
-      case EF_AMDGPU_MACH_AMDGCN_GFX908:
+	case EF_AMDGPU_MACH_AMDGCN_GFX908:
 #endif
-	break;
-      default:
-	/* FIXME: change this when we move to HSACOv4.  */
-	elf_flags |= EF_AMDGPU_SRAM_ECC;
-	break;
-      }
+	  break;
+	default:
+	  SET_SRAM_ECC_ON (elf_flags);
+	  break;
+	}
+#endif
+    }
 
   const char *abi;
   switch (offload_abi)
@@ -936,11 +988,12 @@ main (int argc, char **argv)
   if (fopenmp)
     obstack_ptr_grow (&cc_argv_obstack, "-mgomp");
   obstack_ptr_grow (&cc_argv_obstack,
-		    (elf_flags & EF_AMDGPU_XNACK
+		    (TEST_XNACK (elf_flags)
 		     ? "-mxnack" : "-mno-xnack"));
   obstack_ptr_grow (&cc_argv_obstack,
-		    (elf_flags & EF_AMDGPU_SRAM_ECC
-		     ? "-msram-ecc=on" : "-msram-ecc=off"));
+		    (TEST_SRAM_ECC_ON (elf_flags) ? "-msram-ecc=on"
+		     : TEST_SRAM_ECC_ANY (elf_flags) ? "-msram-ecc=any"
+		     : "-msram-ecc=off"));
 
   for (int ix = 1; ix != argc; ix++)
     {
@@ -1043,11 +1096,12 @@ main (int argc, char **argv)
       obstack_ptr_grow (&ld_argv_obstack, gcn_s2_name);
       obstack_ptr_grow (&ld_argv_obstack, "-lgomp");
       obstack_ptr_grow (&ld_argv_obstack,
-			(elf_flags & EF_AMDGPU_XNACK
+			(TEST_XNACK (elf_flags)
 			 ? "-mxnack" : "-mno-xnack"));
       obstack_ptr_grow (&ld_argv_obstack,
-			(elf_flags & EF_AMDGPU_SRAM_ECC
-			 ? "-msram-ecc=on" : "-msram-ecc=off"));
+			(TEST_SRAM_ECC_ON (elf_flags) ? "-msram-ecc=on"
+			 : TEST_SRAM_ECC_ANY (elf_flags) ? "-msram-ecc=any"
+			 : "-msram-ecc=off"));
       if (verbose)
 	obstack_ptr_grow (&ld_argv_obstack, "-v");


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-07 10:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-07 10:32 [gcc r12-4221] amdgcn: Implement -msram-ecc=any Andrew Stubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).