public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8489] gcn/mkoffload.cc: Fix SRAM_ECC and XNACK handling [PR111966]
@ 2024-01-29 10:11 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2024-01-29 10:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ef5ccdbbc60c230a483898afbf0c053a9f8bb176

commit r14-8489-gef5ccdbbc60c230a483898afbf0c053a9f8bb176
Author: Tobias Burnus <tburnus@baylibre.com>
Date:   Mon Jan 29 11:10:33 2024 +0100

    gcn/mkoffload.cc: Fix SRAM_ECC and XNACK handling [PR111966]
    
    Some more '-g' fixes as the .mkoffload.dbg.o debug file's has elf flags
    which did not match those generated for the compilation, leading to linker
    errors.  For .mkoffload.dbg.o, the elf flags are generated by mkoffload
    itself - while for the other .o files, that's done by the compiler via
    setting default and mainly via the ASM_SPEC.
    
    This is a follow up to r14-8332-g13127dac106724 which fixed an issue
    caused by the default arch.  In this patch, it is mainly for gfx1100
    and gfx1030 which always failed.  It also affects gfx906 and possibly
    gfx900 but only when using the -mxnack/-msram-ecc flags explicitly.
    
    What happens on the compiler side is mainly determined by gcn-hsa.h's
    and otherwise by some default setting. In particular for xnack and
    sram_ecc, there is:
    
    For gfx1100 and gfx1030, neither xnack nor sram_ecc is set (only
    '+wavefrontsize64').
    
    For fiji, gfx900, gfx906 and gfx908 there is always -mattr=-xnack and
    for all but gfx908 also -msram-ecc=no - independent of what has been
    passed to the compiler. However, on the elf flags, the result differs:
    For fiji, due to the HSACOv3, it is always set to 0 via
    copy_early_debug_info; for gfx900, gfx906 and gfx908, xnack is OFF.
    For sram-ecc, it is 'unset' for gfx900, 'any' for gfx906 and for
    gfx908 it is 'any' unless overridden.
    
    For gfx90a, the -msram-ecc= and -mxnack= are passed on, or if not present,
    ...=any is passed on.  Note that this "any" is different from argument
    nor present at elf flag level:
    For XNACK: unset/unsupported is 0, any = 0x100, off = 0x200, on = 0x300.
    For SRAMECC: unset/unsupported is 0, any = 0x400, off = 0x800, on = 0xc00.
    
    The obstack_ptr_grow changes are more to avoid confusion than having an
    actual effect as they would overwise be filtered out via the ASM_SPEC.
    
    gcc/ChangeLog:
    
            PR other/111966
            * config/gcn/mkoffload.cc (SET_XNACK_UNSET, TEST_SRAM_ECC_UNSET): New.
            (SET_SRAM_ECC_UNSUPPORTED): Renamed to ...
            (SET_SRAM_ECC_UNSET): ... this.
            (copy_early_debug_info): Remove gfx900 special case, now handled as
            part of the generic handling.
            (main): Update SRAM_ECC and XNACK for the -march as done in gcn-hsa.h.
    
    Signed-off-by: Tobias Burnus <tburnus@baylibre.com>

Diff:
---
 gcc/config/gcn/mkoffload.cc | 50 +++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 0d0e7bac9b2c..fe443abba217 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -80,6 +80,8 @@
 				  | EF_AMDGPU_FEATURE_XNACK_ANY_V4)
 #define SET_XNACK_OFF(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_XNACK_V4) \
 				  | EF_AMDGPU_FEATURE_XNACK_OFF_V4)
+#define SET_XNACK_UNSET(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_XNACK_V4) \
+				    | EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4)
 #define TEST_XNACK_ANY(VAR) ((VAR & EF_AMDGPU_FEATURE_XNACK_V4) \
 			     == EF_AMDGPU_FEATURE_XNACK_ANY_V4)
 #define TEST_XNACK_ON(VAR) ((VAR & EF_AMDGPU_FEATURE_XNACK_V4) \
@@ -94,13 +96,14 @@
 				     | 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 SET_SRAM_ECC_UNSUPPORTED(VAR) \
+#define SET_SRAM_ECC_UNSET(VAR) \
   VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \
 	 | EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_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)
+#define TEST_SRAM_ECC_UNSET(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) == 0)
 
 #ifndef R_AMDGPU_NONE
 #define R_AMDGPU_NONE		0
@@ -125,7 +128,7 @@ static struct obstack files_to_cleanup;
 
 enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX900;  // Default GPU architecture.
-uint32_t elf_flags = EF_AMDGPU_FEATURE_SRAMECC_ANY_V4;
+uint32_t elf_flags = EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4;
 
 static int gcn_stack_size = 0;  /* Zero means use default.  */
 
@@ -344,10 +347,6 @@ copy_early_debug_info (const char *infile, const char *outfile)
   /* Fiji devices use HSACOv3 regardless of the assembler.  */
   uint32_t elf_flags_actual = (elf_arch == EF_AMDGPU_MACH_AMDGCN_GFX803
 			       ? 0 : elf_flags);
-  /* GFX900 devices don't support the sramecc attribute even if
-     a buggy assembler thinks it does.  This must match gcn-hsa.h  */
-  if (elf_arch == EF_AMDGPU_MACH_AMDGCN_GFX900)
-    SET_SRAM_ECC_UNSUPPORTED (elf_flags_actual);
 
   /* Patch the correct elf architecture flag into the file.  */
   ehdr.e_ident[7] = ELFOSABI_AMDGPU_HSA;
@@ -1007,21 +1006,34 @@ main (int argc, char **argv)
       gcc_unreachable ();
     }
 
-  /* Disable XNACK mode on architectures where it doesn't work (well).
-     Set default to "any" otherwise.  */
+  /* This must match gcn-hsa.h's settings for NO_XNACK, NO_SRAM_ECC
+     and ASM_SPEC.  */
   switch (elf_arch)
     {
     case EF_AMDGPU_MACH_AMDGCN_GFX803:
+    case EF_AMDGPU_MACH_AMDGCN_GFX1030:
+    case EF_AMDGPU_MACH_AMDGCN_GFX1100:
+      SET_XNACK_UNSET (elf_flags);
+      SET_SRAM_ECC_UNSET (elf_flags);
+      break;
     case EF_AMDGPU_MACH_AMDGCN_GFX900:
+      SET_XNACK_OFF (elf_flags);
+      SET_SRAM_ECC_UNSET (elf_flags);
+      break;
     case EF_AMDGPU_MACH_AMDGCN_GFX906:
+      SET_XNACK_OFF (elf_flags);
+      SET_SRAM_ECC_ANY (elf_flags);
+      break;
     case EF_AMDGPU_MACH_AMDGCN_GFX908:
-    case EF_AMDGPU_MACH_AMDGCN_GFX1030:
-    case EF_AMDGPU_MACH_AMDGCN_GFX1100:
       SET_XNACK_OFF (elf_flags);
+      if (TEST_SRAM_ECC_UNSET (elf_flags))
+	SET_SRAM_ECC_ANY (elf_flags);
       break;
     case EF_AMDGPU_MACH_AMDGCN_GFX90a:
       if (TEST_XNACK_UNSET (elf_flags))
 	SET_XNACK_ANY (elf_flags);
+      if (TEST_SRAM_ECC_UNSET (elf_flags))
+	SET_SRAM_ECC_ANY (elf_flags);
       break;
     default:
       fatal_error (input_location, "unhandled architecture");
@@ -1145,14 +1157,16 @@ 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,
-			(TEST_XNACK_ON (elf_flags) ? "-mxnack=on"
-			 : TEST_XNACK_ANY (elf_flags) ? "-mxnack=any"
-			 : "-mxnack=off"));
-      obstack_ptr_grow (&ld_argv_obstack,
-			(TEST_SRAM_ECC_ON (elf_flags) ? "-msram-ecc=on"
-			 : TEST_SRAM_ECC_ANY (elf_flags) ? "-msram-ecc=any"
-			 : "-msram-ecc=off"));
+      if (!TEST_XNACK_UNSET (elf_flags))
+	obstack_ptr_grow (&ld_argv_obstack,
+			  (TEST_XNACK_ON (elf_flags) ? "-mxnack=on"
+			   : TEST_XNACK_ANY (elf_flags) ? "-mxnack=any"
+			   : "-mxnack=off"));
+      if (!TEST_SRAM_ECC_UNSET (elf_flags))
+	obstack_ptr_grow (&ld_argv_obstack,
+			  (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:[~2024-01-29 10:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 10:11 [gcc r14-8489] gcn/mkoffload.cc: Fix SRAM_ECC and XNACK handling [PR111966] Tobias Burnus

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).