diff options
| author | Andrew Stubbs <ams@baylibre.com> | 2024-09-17 15:26:04 +0000 |
|---|---|---|
| committer | Andrew Stubbs <ams@baylibre.com> | 2024-10-22 11:07:05 +0000 |
| commit | a6b26e5ea09779bf276dff52a6692f3bb655d230 (patch) | |
| tree | 8c29c9e65648849baaf0015b06652dc0d2eae6f1 /libgomp | |
| parent | c33d8c55a79f08e4a14b4bc601b270268d3c4c89 (diff) | |
amdgcn: Refactor device settings into a def file
Almost all device-specific settings are now centralised into gcn-devices.def
for the compiler, mkoffload, and libgomp. No longer will we have to touch 10
files in multiple places just to add another device without any exotic
features. (New ISAs and devices with incompatible metadata will continue to
need a bit more.)
In order to remove the device-specific conditionals in the code a new value
HSACO_ATTR_UNSUPPORTED has been added, indicating that the assembler will
reject any setting of that option.
This incorporates some of Tobias's patch from March 2024.
Co-Authored-By: Tobias Burnus <tburnus@baylibre.com>
gcc/ChangeLog:
* config.gcc (amdgcn): Add gcn-device-macros.h to tm_file.
Add gcn-tables.opt to extra_options.
* config/gcn/gcn-hsa.h (NO_XNACK): Delete.
(NO_SRAM_ECC): Delete.
(SRAMOPT): Move definition to generated file gcn-device-macros.h.
(XNACKOPT): Likewise.
(ASM_SPEC): Redefine using generated values from gcn-device-macros.h.
* config/gcn/gcn-opts.h
(enum processor_type): Generate from gcn-devices.def.
(TARGET_VEGA10): Delete.
(TARGET_VEGA20): Delete.
(TARGET_GFX908): Delete.
(TARGET_GFX90a): Delete.
(TARGET_GFX90c): Delete.
(TARGET_GFX1030): Delete.
(TARGET_GFX1036): Delete.
(TARGET_GFX1100): Delete.
(TARGET_GFX1103): Delete.
(TARGET_XNACK): Redefine to allow for HSACO_ATTR_UNSUPPORTED.
(enum hsaco_attr_type): Add HSACO_ATTR_UNSUPPORTED.
(TARGET_TGSPLIT): New define.
* config/gcn/gcn.cc (gcn_devices): New constant table.
(gcn_option_override): Rework to use gcn_devices table.
(gcn_omp_device_kind_arch_isa): Likewise.
(output_file_start): Likewise.
(gcn_hsa_declare_function_name): Rework using TARGET_* macros.
* config/gcn/gcn.h (gcn_devices): Declare struct and table.
(TARGET_CPU_CPP_BUILTINS): Rework using gcn_devices.
* config/gcn/gcn.opt: Move enum data to generated file gcn-tables.opt.
Use new names for the default values.
* config/gcn/mkoffload.cc (EF_AMDGPU_MACH_AMDGCN_GFX900): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX906): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX908): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX90a): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX90c): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX1030): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX1036): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX1100): Delete.
(EF_AMDGPU_MACH_AMDGCN_GFX1103): Delete.
(enum elf_arch_code): Define using gcn-devices.def.
(get_arch): Rework using gcn-devices.def.
(main): Rework using gcn-devices.def
* config/gcn/t-gcn-hsa (gcn-tables.opt): Generate file.
(gcn-device-macros.h): Generate file.
* config/gcn/t-omp-device: Generate isa list from gcn-devices.def.
* config/gcn/gcn-devices.def: New file.
* config/gcn/gcn-tables.opt: New file.
* config/gcn/gcn-tables.opt.urls: New file.
* config/gcn/gen-gcn-device-macros.awk: New file.
* config/gcn/gen-opt-tables.awk: New file.
libgomp/ChangeLog:
* plugin/plugin-gcn.c (EF_AMDGPU_MACH): Generate from gcn-devices.def.
(gcn_gfx803_s): Delete.
(gcn_gfx900_s): Delete.
(gcn_gfx906_s): Delete.
(gcn_gfx908_s): Delete.
(gcn_gfx90a_s): Delete.
(gcn_gfx90c_s): Delete.
(gcn_gfx1030_s): Delete.
(gcn_gfx1036_s): Delete.
(gcn_gfx1100_s): Delete.
(gcn_gfx1103_s): Delete.
(gcn_isa_name_len): Delete.
(isa_hsa_name): Rename ...
(isa_name): ... to this, and rework using gcn-devices.def.
(isa_gcc_name): Delete.
(isa_code): Rework using gcn-devices.def.
(max_isa_vgprs): Rework using gcn-devices.def.
(isa_matches_agent): Update isa_name usage.
(GOMP_OFFLOAD_init_device): Improve diagnostic using the name.
Diffstat (limited to 'libgomp')
| -rw-r--r-- | libgomp/plugin/plugin-gcn.c | 142 |
1 files changed, 29 insertions, 113 deletions
diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index 1bd90dc381e..592a7b6daba 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -379,22 +379,15 @@ struct gcn_image_desc const unsigned global_variable_count; }; -/* This enum mirrors the corresponding LLVM enum's values for all ISAs that we - support. - See https://llvm.org/docs/AMDGPUUsage.html#amdgpu-ef-amdgpu-mach-table */ +/* Enum values corresponding to the the ELF architecture codes. + Only 'special' values are actually referenced in this file, but having them + all may aid debugging. */ typedef enum { EF_AMDGPU_MACH_UNSUPPORTED = -1, - EF_AMDGPU_MACH_AMDGCN_GFX803 = 0x02a, - EF_AMDGPU_MACH_AMDGCN_GFX900 = 0x02c, - EF_AMDGPU_MACH_AMDGCN_GFX906 = 0x02f, - EF_AMDGPU_MACH_AMDGCN_GFX908 = 0x030, - EF_AMDGPU_MACH_AMDGCN_GFX90a = 0x03f, - EF_AMDGPU_MACH_AMDGCN_GFX90c = 0x032, - EF_AMDGPU_MACH_AMDGCN_GFX1030 = 0x036, - EF_AMDGPU_MACH_AMDGCN_GFX1036 = 0x045, - EF_AMDGPU_MACH_AMDGCN_GFX1100 = 0x041, - EF_AMDGPU_MACH_AMDGCN_GFX1103 = 0x044 +#define GCN_DEVICE(name, NAME, ELF, ...) \ + EF_AMDGPU_MACH_AMDGCN_ ## NAME = ELF, +#include "../../gcc/config/gcn/gcn-devices.def" } EF_AMDGPU_MACH; const static int EF_AMDGPU_MACH_MASK = 0x000000ff; @@ -1675,98 +1668,28 @@ elf_gcn_isa_field (Elf64_Ehdr *image) return image->e_flags & EF_AMDGPU_MACH_MASK; } -const static char *gcn_gfx803_s = "gfx803"; -const static char *gcn_gfx900_s = "gfx900"; -const static char *gcn_gfx906_s = "gfx906"; -const static char *gcn_gfx908_s = "gfx908"; -const static char *gcn_gfx90a_s = "gfx90a"; -const static char *gcn_gfx90c_s = "gfx90c"; -const static char *gcn_gfx1030_s = "gfx1030"; -const static char *gcn_gfx1036_s = "gfx1036"; -const static char *gcn_gfx1100_s = "gfx1100"; -const static char *gcn_gfx1103_s = "gfx1103"; -const static int gcn_isa_name_len = 7; - /* Returns the name that the HSA runtime uses for the ISA or NULL if we do not support the ISA. */ static const char* -isa_hsa_name (int isa) { +isa_name (int isa) { switch(isa) { - case EF_AMDGPU_MACH_AMDGCN_GFX803: - return gcn_gfx803_s; - case EF_AMDGPU_MACH_AMDGCN_GFX900: - return gcn_gfx900_s; - case EF_AMDGPU_MACH_AMDGCN_GFX906: - return gcn_gfx906_s; - case EF_AMDGPU_MACH_AMDGCN_GFX908: - return gcn_gfx908_s; - case EF_AMDGPU_MACH_AMDGCN_GFX90a: - return gcn_gfx90a_s; - case EF_AMDGPU_MACH_AMDGCN_GFX90c: - return gcn_gfx90c_s; - case EF_AMDGPU_MACH_AMDGCN_GFX1030: - return gcn_gfx1030_s; - case EF_AMDGPU_MACH_AMDGCN_GFX1036: - return gcn_gfx1036_s; - case EF_AMDGPU_MACH_AMDGCN_GFX1100: - return gcn_gfx1100_s; - case EF_AMDGPU_MACH_AMDGCN_GFX1103: - return gcn_gfx1103_s; +#define GCN_DEVICE(name, NAME, ELF, ...) \ + case ELF: return #name; +#include "../../gcc/config/gcn/gcn-devices.def" } return NULL; } -/* Returns the user-facing name that GCC uses to identify the architecture (e.g. - with -march) or NULL if we do not support the ISA. - Keep in sync with /gcc/config/gcn/gcn.{c,opt}. */ - -static const char* -isa_gcc_name (int isa) { - switch(isa) - { - case EF_AMDGPU_MACH_AMDGCN_GFX803: - return "fiji"; - default: - return isa_hsa_name (isa); - } -} - /* Returns the code which is used in the GCN object code to identify the ISA with the given name (as used by the HSA runtime). */ static gcn_isa isa_code(const char *isa) { - if (!strncmp (isa, gcn_gfx803_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX803; - - if (!strncmp (isa, gcn_gfx900_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX900; - - if (!strncmp (isa, gcn_gfx906_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX906; - - if (!strncmp (isa, gcn_gfx908_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX908; - - if (!strncmp (isa, gcn_gfx90a_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX90a; - - if (!strncmp (isa, gcn_gfx90c_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX90c; - - if (!strncmp (isa, gcn_gfx1030_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX1030; - - if (!strncmp (isa, gcn_gfx1036_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX1036; - - if (!strncmp (isa, gcn_gfx1100_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX1100; - - if (!strncmp (isa, gcn_gfx1103_s, gcn_isa_name_len)) - return EF_AMDGPU_MACH_AMDGCN_GFX1103; +#define GCN_DEVICE(name, NAME, ELF, ...) \ + if (!strcmp (isa, #name)) return ELF; +#include "../../gcc/config/gcn/gcn-devices.def" return EF_AMDGPU_MACH_UNSUPPORTED; } @@ -1778,23 +1701,13 @@ max_isa_vgprs (int isa) { switch (isa) { - case EF_AMDGPU_MACH_AMDGCN_GFX803: - case EF_AMDGPU_MACH_AMDGCN_GFX900: - case EF_AMDGPU_MACH_AMDGCN_GFX906: - case EF_AMDGPU_MACH_AMDGCN_GFX908: - return 256; - case EF_AMDGPU_MACH_AMDGCN_GFX90a: - return 512; - case EF_AMDGPU_MACH_AMDGCN_GFX90c: - return 256; - case EF_AMDGPU_MACH_AMDGCN_GFX1030: - case EF_AMDGPU_MACH_AMDGCN_GFX1036: - return 512; /* 512 SIMD32 = 256 wavefrontsize64. */ - case EF_AMDGPU_MACH_AMDGCN_GFX1100: - case EF_AMDGPU_MACH_AMDGCN_GFX1103: - return 1536; /* 1536 SIMD32 = 768 wavefrontsize64. */ - } - GOMP_PLUGIN_fatal ("unhandled ISA in max_isa_vgprs"); +#define GCN_DEVICE(name, NAME, ELF, ISA, XNACK, SRAM, WAVE64, CU, \ + MAX_ISA_VGPRS, ...) \ + case ELF: return MAX_ISA_VGPRS; +#include "../../gcc/config/gcn/gcn-devices.def" + default: + GOMP_PLUGIN_fatal ("unhandled ISA in max_isa_vgprs"); + } } /* }}} */ @@ -2492,7 +2405,7 @@ static bool isa_matches_agent (struct agent_info *agent, Elf64_Ehdr *image) { int isa_field = elf_gcn_isa_field (image); - const char* isa_s = isa_hsa_name (isa_field); + const char* isa_s = isa_name (isa_field); if (!isa_s) { hsa_error ("Unsupported ISA in GCN code object.", HSA_STATUS_ERROR); @@ -2502,15 +2415,13 @@ isa_matches_agent (struct agent_info *agent, Elf64_Ehdr *image) if (isa_field != agent->device_isa) { char msg[120]; - const char *agent_isa_s = isa_hsa_name (agent->device_isa); - const char *agent_isa_gcc_s = isa_gcc_name (agent->device_isa); + const char *agent_isa_s = isa_name (agent->device_isa); assert (agent_isa_s); - assert (agent_isa_gcc_s); snprintf (msg, sizeof msg, "GCN code object ISA '%s' does not match GPU ISA '%s'.\n" "Try to recompile with '-foffload-options=-march=%s'.\n", - isa_s, agent_isa_s, agent_isa_gcc_s); + isa_s, agent_isa_s, agent_isa_s); hsa_error (msg, HSA_STATUS_ERROR); return false; @@ -3461,7 +3372,12 @@ GOMP_OFFLOAD_init_device (int n) agent->device_isa = isa_code (agent->name); if (agent->device_isa == EF_AMDGPU_MACH_UNSUPPORTED) - return hsa_error ("Unknown GCN agent architecture", HSA_STATUS_ERROR); + { + char msg[33 + 64 + 1]; + snprintf (msg, sizeof msg, + "Unknown GCN agent architecture '%s'", agent->name); + return hsa_error (msg, HSA_STATUS_ERROR); + } status = hsa_fns.hsa_agent_get_info_fn (agent->id, HSA_AGENT_INFO_VENDOR_NAME, &agent->vendor_name); |
