aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/gcn/mkoffload.c
diff options
context:
space:
mode:
authorAndrew Stubbs <ams@codesourcery.com>2021-09-28 16:26:09 +0100
committerAndrew Stubbs <ams@codesourcery.com>2021-10-07 11:26:44 +0100
commit205dafb6edeca08419f4a5976be79bf7c86fd9a1 (patch)
tree4d9ba145807936c2a24d3c20b73874b4010cb256 /gcc/config/gcn/mkoffload.c
parent6ca03ca35a58ebf9792aa8a08adf00b6fd3e0015 (diff)
downloadgcc-205dafb6edeca08419f4a5976be79bf7c86fd9a1.zip
gcc-205dafb6edeca08419f4a5976be79bf7c86fd9a1.tar.gz
gcc-205dafb6edeca08419f4a5976be79bf7c86fd9a1.tar.bz2
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.
Diffstat (limited to 'gcc/config/gcn/mkoffload.c')
-rw-r--r--gcc/config/gcn/mkoffload.c112
1 files changed, 83 insertions, 29 deletions
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 732bdfd..a3b22d0 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");