From 8e43aaab04b2f604986045443a1fdaf3da3d60ae Mon Sep 17 00:00:00 2001 From: pvanhout Date: Tue, 20 Feb 2024 10:59:06 +0100 Subject: [PATCH] [libamdhsacode] Support COV6/Generic Targets Change-Id: I4680577eb56dc436fbc134b169f172dd476bff37 [ROCm/ROCR-Runtime commit: a93c18dc906be267eb1e1d49f1b04e9f6765edce] --- .../hsa-runtime/core/inc/amd_hsa_code.hpp | 18 +++++------ .../hsa-runtime/core/inc/amd_hsa_loader.hpp | 4 +++ .../runtime/hsa-runtime/inc/amd_hsa_elf.h | 30 +++++++++++++++---- .../libamdhsacode/amd_hsa_code.cpp | 22 ++++++++++++-- .../runtime/hsa-runtime/loader/executable.cpp | 7 +++-- 5 files changed, 61 insertions(+), 20 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp index 724100826a..08a898cc63 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp @@ -2,24 +2,24 @@ // // The University of Illinois/NCSA // Open Source License (NCSA) -// +// // Copyright (c) 2014-2020, Advanced Micro Devices, Inc. All rights reserved. -// +// // Developed by: -// +// // AMD Research and AMD HSA Software Development -// +// // Advanced Micro Devices, Inc. -// +// // www.amd.com -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal with the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: -// +// // - Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimers. // - Redistributions in binary form must reproduce the above copyright @@ -29,7 +29,7 @@ // nor the names of its contributors may be used to endorse or promote // products derived from this Software without specific prior written // permission. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL @@ -270,7 +270,7 @@ namespace code { void AddNoteProducerOptions(int32_t call_convention, const hsa_ext_control_directives_t& user_directives, const std::string& user_options); bool GetNoteProducerOptions(std::string& options); - bool GetIsa(std::string& isaName); + bool GetIsa(std::string& isaName, unsigned *genericVersion = nullptr); bool GetCodeObjectVersion(uint32_t* major, uint32_t* minor); hsa_status_t GetInfo(hsa_code_object_info_t attribute, void *value); hsa_status_t GetSymbol(const char *module_name, const char *symbol_name, hsa_code_symbol_t *sym); diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp index f30047d0bf..72d55afd67 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp @@ -162,8 +162,12 @@ public: virtual hsa_isa_t IsaFromName(const char *name) = 0; + // This function will be deleted in a future patch. Use the overload + // that takes a generic version instead. virtual bool IsaSupportedByAgent(hsa_agent_t agent, hsa_isa_t isa) = 0; + virtual bool IsaSupportedByAgent(hsa_agent_t agent, hsa_isa_t isa, unsigned genericVersion) { return IsaSupportedByAgent(agent, isa); } + virtual void* SegmentAlloc(amdgpu_hsa_elf_segment_t segment, hsa_agent_t agent, size_t size, size_t align, bool zero) = 0; virtual bool SegmentCopy(amdgpu_hsa_elf_segment_t segment, hsa_agent_t agent, void* dst, size_t offset, const void* src, size_t size) = 0; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/inc/amd_hsa_elf.h b/projects/rocr-runtime/runtime/hsa-runtime/inc/amd_hsa_elf.h index 51aa389a06..757a67e78b 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/inc/amd_hsa_elf.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/inc/amd_hsa_elf.h @@ -75,7 +75,8 @@ enum { ELFABIVERSION_AMDGPU_HSA_V2 = 0, ELFABIVERSION_AMDGPU_HSA_V3 = 1, ELFABIVERSION_AMDGPU_HSA_V4 = 2, - ELFABIVERSION_AMDGPU_HSA_V5 = 3 + ELFABIVERSION_AMDGPU_HSA_V5 = 3, + ELFABIVERSION_AMDGPU_HSA_V6 = 4, }; // AMDGPU specific e_flags. @@ -87,6 +88,7 @@ enum : unsigned { EF_AMDGPU_MACH_NONE = 0x000, // AMDGCN-based processors. + // clang-format off EF_AMDGPU_MACH_AMDGCN_GFX600 = 0x020, EF_AMDGPU_MACH_AMDGCN_GFX601 = 0x021, EF_AMDGPU_MACH_AMDGCN_GFX700 = 0x022, @@ -127,13 +129,25 @@ enum : unsigned { EF_AMDGPU_MACH_AMDGCN_GFX1036 = 0x045, EF_AMDGPU_MACH_AMDGCN_GFX1101 = 0x046, EF_AMDGPU_MACH_AMDGCN_GFX1102 = 0x047, + EF_AMDGPU_MACH_AMDGCN_GFX1200 = 0x048, + EF_AMDGPU_MACH_AMDGCN_RESERVED_0X49 = 0x049, EF_AMDGPU_MACH_AMDGCN_GFX1151 = 0x04a, EF_AMDGPU_MACH_AMDGCN_GFX941 = 0x04b, EF_AMDGPU_MACH_AMDGCN_GFX942 = 0x04c, + EF_AMDGPU_MACH_AMDGCN_RESERVED_0X4D = 0x04d, + EF_AMDGPU_MACH_AMDGCN_GFX1201 = 0x04e, + EF_AMDGPU_MACH_AMDGCN_RESERVED_0X4F = 0x04f, + EF_AMDGPU_MACH_AMDGCN_RESERVED_0X50 = 0x050, + EF_AMDGPU_MACH_AMDGCN_GFX9_GENERIC = 0x051, + EF_AMDGPU_MACH_AMDGCN_GFX10_1_GENERIC = 0x052, + EF_AMDGPU_MACH_AMDGCN_GFX10_3_GENERIC = 0x053, + EF_AMDGPU_MACH_AMDGCN_GFX11_GENERIC = 0x054, + EF_AMDGPU_MACH_AMDGCN_RESERVED_0X55 = 0x055, + // clang-format on // First/last AMDGCN-based processors. EF_AMDGPU_MACH_AMDGCN_FIRST = EF_AMDGPU_MACH_AMDGCN_GFX600, - EF_AMDGPU_MACH_AMDGCN_LAST = EF_AMDGPU_MACH_AMDGCN_GFX942, + EF_AMDGPU_MACH_AMDGCN_LAST = EF_AMDGPU_MACH_AMDGCN_GFX11_GENERIC, // Indicates if the "xnack" target feature is enabled for all code contained // in the object. @@ -159,8 +173,7 @@ enum : unsigned { // XNACK selection mask for EF_AMDGPU_FEATURE_XNACK_* values. // - // Only valid for ELFOSABI_AMDGPU_HSA and ELFABIVERSION_AMDGPU_HSA_V4, - // ELFABIVERSION_AMDGPU_HSA_V5. + // Only valid for ELFOSABI_AMDGPU_HSA and ELFABIVERSION_AMDGPU_HSA_V4. EF_AMDGPU_FEATURE_XNACK_V4 = 0x300, // XNACK is not supported. EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4 = 0x000, @@ -173,8 +186,7 @@ enum : unsigned { // SRAMECC selection mask for EF_AMDGPU_FEATURE_SRAMECC_* values. // - // Only valid for ELFOSABI_AMDGPU_HSA and ELFABIVERSION_AMDGPU_HSA_V4, - // ELFABIVERSION_AMDGPU_HSA_V5. + // Only valid for ELFOSABI_AMDGPU_HSA and ELFABIVERSION_AMDGPU_HSA_V4. EF_AMDGPU_FEATURE_SRAMECC_V4 = 0xc00, // SRAMECC is not supported. EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4 = 0x000, @@ -184,6 +196,12 @@ enum : unsigned { EF_AMDGPU_FEATURE_SRAMECC_OFF_V4 = 0x800, // SRAMECC is on. EF_AMDGPU_FEATURE_SRAMECC_ON_V4 = 0xc00, + + // Generic target versioning. This is contained in the list byte of EFLAGS. + EF_AMDGPU_GENERIC_VERSION = 0xff000000, + EF_AMDGPU_GENERIC_VERSION_OFFSET = 24, + EF_AMDGPU_GENERIC_VERSION_MIN = 1, + EF_AMDGPU_GENERIC_VERSION_MAX = 0xff, }; } // end namespace ELF diff --git a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp index 08836a5777..183aff12b1 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp @@ -483,6 +483,10 @@ namespace code { *major = 5; *minor = 0; return true; + case ELF::ELFABIVERSION_AMDGPU_HSA_V6: + *major = 6; + *minor = 0; + return true; } return false; @@ -600,6 +604,10 @@ namespace code { case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1103: MI.Name = "gfx1103"; MI.XnackSupported = false; MI.SrameccSupported = false; break; case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1150: MI.Name = "gfx1150"; MI.XnackSupported = false; MI.SrameccSupported = false; break; case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1151: MI.Name = "gfx1151"; MI.XnackSupported = false; MI.SrameccSupported = false; break; + case ELF::EF_AMDGPU_MACH_AMDGCN_GFX9_GENERIC: MI.Name = "gfx9-generic"; MI.XnackSupported = true; MI.SrameccSupported = false; break; + case ELF::EF_AMDGPU_MACH_AMDGCN_GFX10_1_GENERIC: MI.Name = "gfx10-1-generic"; MI.XnackSupported = true; MI.SrameccSupported = false; break; + case ELF::EF_AMDGPU_MACH_AMDGCN_GFX10_3_GENERIC: MI.Name = "gfx10-3-generic"; MI.XnackSupported = false; MI.SrameccSupported = false; break; + case ELF::EF_AMDGPU_MACH_AMDGCN_GFX11_GENERIC: MI.Name = "gfx11-generic"; MI.XnackSupported = false; MI.SrameccSupported = false; break; default: return false; } return true; @@ -687,13 +695,17 @@ namespace code { return MI.Name; } - bool AmdHsaCode::GetIsa(std::string& isa_name) + bool AmdHsaCode::GetIsa(std::string& isa_name, unsigned *genericVersion) { isa_name.clear(); uint32_t code_object_major_version = 0; uint32_t code_object_minor_version = 0; + // Generic versioning starts at 1, so zero means no generic version. + if (genericVersion) + *genericVersion = 0; + switch (img->EClass()) { case ELFCLASS64: // There is no e_machine and/or OS ABI for R600 so rely on checking @@ -740,7 +752,7 @@ namespace code { MI.Name += ":xnack+"; else if (MI.XnackSupported) MI.Name += ":xnack-"; - } else if (code_object_major_version == 4 || code_object_major_version == 5) { + } else if (code_object_major_version >= 4) { switch (img->EFlags() & ELF::EF_AMDGPU_FEATURE_SRAMECC_V4) { case ELF::EF_AMDGPU_FEATURE_SRAMECC_OFF_V4: MI.Name += ":sramecc-"; @@ -758,6 +770,12 @@ namespace code { MI.Name += ":xnack+"; break; } + + // Generic version is not part of the ISA name. + // Only parse it when the caller wants it. + if (genericVersion && code_object_major_version >= 6) { + *genericVersion = (img->EFlags() & ELF::EF_AMDGPU_GENERIC_VERSION) >> ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET; + } } else { return false; } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp index 2f333fbebe..2b6d09d080 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp @@ -1218,7 +1218,8 @@ hsa_status_t ExecutableImpl::LoadCodeObject( } std::string codeIsa; - if (!code->GetIsa(codeIsa)) { + unsigned genericVersion; + if (!code->GetIsa(codeIsa, &genericVersion)) { logger_ << "LoaderError: failed to determine code object's ISA\n"; return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } @@ -1229,7 +1230,7 @@ hsa_status_t ExecutableImpl::LoadCodeObject( return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } - if (majorVersion < 1 || majorVersion > 5) { + if (majorVersion < 1 || majorVersion > 6) { logger_ << "LoaderError: unsupported code object version: " << majorVersion << "\n"; return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } @@ -1257,7 +1258,7 @@ hsa_status_t ExecutableImpl::LoadCodeObject( return HSA_STATUS_ERROR_INVALID_ISA_NAME; } - if (agent.handle != 0 && !context_->IsaSupportedByAgent(agent, objectsIsa)) { + if (agent.handle != 0 && !context_->IsaSupportedByAgent(agent, objectsIsa, genericVersion)) { logger_ << "LoaderError: code object's ISA (" << codeIsa.c_str() << ") is not supported by the agent\n"; return HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS; }