diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_elf_image.hpp b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_elf_image.hpp index 763c5c831c..6667c3b364 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_elf_image.hpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_elf_image.hpp @@ -207,6 +207,7 @@ namespace amd { virtual uint16_t Machine() = 0; virtual uint16_t Type() = 0; + virtual uint32_t EFlags() = 0; std::string output() { return out.str(); } 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 a202079148..4d79660e9c 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 @@ -267,6 +267,7 @@ namespace code { const amd::elf::Section* HsaText() const { assert(hsatext); return hsatext; } amd::elf::SymbolTable* Symtab() { assert(img); return img->symtab(); } uint16_t Machine() const { return img->Machine(); } + uint32_t EFlags() const { return img->EFlags(); } AmdHsaCode(bool combineDataSegments = true); virtual ~AmdHsaCode(); diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/isa.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/isa.h index f2c224f2ff..a6c08fba2a 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/isa.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/isa.h @@ -168,14 +168,20 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { private: /// @brief Default constructor. - Isa(): version_(Version(-1, -1, -1)) {} + Isa(): version_(Version(-1, -1, -1)), xnackEnabled_(false) {} /// @brief Construct from @p version. - Isa(const Version &version): version_(version) {} + Isa(const Version &version): version_(version), xnackEnabled_(false) {} + + /// @brief Construct from @p version. + Isa(const Version &version, const bool xnack): version_(version), xnackEnabled_(xnack) {} /// @brief Isa's version. Version version_; + /// @brief Isa's supported xnack flag. + bool xnackEnabled_; + /// @brief Isa's supported wavefront. Wavefront wavefront_; @@ -190,7 +196,7 @@ class IsaRegistry final { /// @returns Isa for requested @p full_name, null pointer if not supported. static const Isa *GetIsa(const std::string &full_name); /// @returns Isa for requested @p version, null pointer if not supported. - static const Isa *GetIsa(const Isa::Version &version); + static const Isa *GetIsa(const Isa::Version &version, bool xnack); private: /// @brief IsaRegistry's map type. diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index 4200adbba3..fce4fe71e2 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -96,7 +96,7 @@ GpuAgent::GpuAgent(HSAuint32 node, const HsaNodeProperties& node_props) // Set instruction set architecture via node property, only on GPU device. isa_ = (core::Isa*)core::IsaRegistry::GetIsa(core::Isa::Version( node_props.EngineId.ui32.Major, node_props.EngineId.ui32.Minor, - node_props.EngineId.ui32.Stepping)); + node_props.EngineId.ui32.Stepping), profile_ == HSA_PROFILE_FULL); // Check if the device is Kaveri, only on GPU device. if (isa_->GetMajorVersion() == 7 && isa_->GetMinorVersion() == 0 && diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/isa.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/isa.cpp index 889e966f16..9ba0e82899 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/isa.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/isa.cpp @@ -70,6 +70,11 @@ std::string Isa::GetFullName() const { full_name << GetVendor() << ":" << GetArchitecture() << ":" << GetMajorVersion() << ":" << GetMinorVersion() << ":" << GetStepping(); + + if (xnackEnabled_) { + full_name << "-xnack"; + } + return full_name.str(); } @@ -176,8 +181,8 @@ const Isa *IsaRegistry::GetIsa(const std::string &full_name) { return isareg_iter == supported_isas_.end() ? nullptr : &isareg_iter->second; } -const Isa *IsaRegistry::GetIsa(const Isa::Version &version) { - auto isareg_iter = supported_isas_.find(Isa(version).GetFullName()); +const Isa *IsaRegistry::GetIsa(const Isa::Version &version, bool xnack) { + auto isareg_iter = supported_isas_.find(Isa(version, xnack).GetFullName()); return isareg_iter == supported_isas_.end() ? nullptr : &isareg_iter->second; } @@ -185,29 +190,30 @@ const IsaRegistry::IsaMap IsaRegistry::supported_isas_ = IsaRegistry::GetSupportedIsas(); const IsaRegistry::IsaMap IsaRegistry::GetSupportedIsas() { -#define ISAREG_ENTRY_GEN(maj, min, stp) \ +#define ISAREG_ENTRY_GEN(maj, min, stp, xnack) \ Isa amd_amdgpu_##maj##min##stp; \ amd_amdgpu_##maj##min##stp.version_ = Isa::Version(maj, min, stp); \ + amd_amdgpu_##maj##min##stp.xnackEnabled_ = xnack; \ supported_isas.insert( \ std::make_pair( \ amd_amdgpu_##maj##min##stp.GetFullName(), amd_amdgpu_##maj##min##stp)); \ IsaMap supported_isas; - ISAREG_ENTRY_GEN(7, 0, 0) - ISAREG_ENTRY_GEN(7, 0, 1) - ISAREG_ENTRY_GEN(7, 0, 2) - ISAREG_ENTRY_GEN(8, 0, 1) - ISAREG_ENTRY_GEN(8, 0, 2) - ISAREG_ENTRY_GEN(8, 0, 3) - ISAREG_ENTRY_GEN(9, 0, 0) - ISAREG_ENTRY_GEN(9, 0, 1) - ISAREG_ENTRY_GEN(9, 0, 2) - ISAREG_ENTRY_GEN(9, 0, 3) - ISAREG_ENTRY_GEN(9, 0, 4) - ISAREG_ENTRY_GEN(9, 0, 5) - ISAREG_ENTRY_GEN(9, 0, 6) - ISAREG_ENTRY_GEN(9, 0, 7) + ISAREG_ENTRY_GEN(7, 0, 0, false) + ISAREG_ENTRY_GEN(7, 0, 1, false) + ISAREG_ENTRY_GEN(7, 0, 2, false) + ISAREG_ENTRY_GEN(8, 0, 1, true) + ISAREG_ENTRY_GEN(8, 0, 2, false) + ISAREG_ENTRY_GEN(8, 0, 3, false) + ISAREG_ENTRY_GEN(9, 0, 0, false) + ISAREG_ENTRY_GEN(9, 0, 1, false) + ISAREG_ENTRY_GEN(9, 0, 2, true) + ISAREG_ENTRY_GEN(9, 0, 3, false) + ISAREG_ENTRY_GEN(9, 0, 4, false) + ISAREG_ENTRY_GEN(9, 0, 5, false) + ISAREG_ENTRY_GEN(9, 0, 6, false) + ISAREG_ENTRY_GEN(9, 0, 7, false) return supported_isas; } 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 a24dc85b7a..e0702b1751 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 @@ -52,6 +52,10 @@ #define EF_AMDGPU_XNACK 0x00000001 #define EF_AMDGPU_TRAP_HANDLER 0x00000002 +// FIXME: We really need to start thinking about separating legacy code out, +// it is getting messy. +#define EF_AMDGPU_XNACK_LC 0x100 + // ELF Section Header Flag Enumeration Values. #define SHF_AMDGPU_HSA_GLOBAL (0x00100000 & SHF_MASKOS) #define SHF_AMDGPU_HSA_READONLY (0x00200000 & SHF_MASKOS) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp index 80c25d5206..ee9ff3135e 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp @@ -703,6 +703,7 @@ namespace amd { uint16_t Machine() override { return ehdr.e_machine; } uint16_t Type() override { return ehdr.e_type; } + uint32_t EFlags() override{ return ehdr.e_flags; } GElfStringTable* shstrtab() override; GElfStringTable* strtab() override; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp index 2f138190df..122002dbd1 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp @@ -1110,9 +1110,6 @@ hsa_status_t ExecutableImpl::LoadCodeObject( std::string codeIsa; if (!code->GetNoteIsa(codeIsa)) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } - hsa_isa_t objectsIsa = context_->IsaFromName(codeIsa.c_str()); - if (!objectsIsa.handle) { return HSA_STATUS_ERROR_INVALID_ISA_NAME; } - uint32_t majorVersion, minorVersion; if (!code->GetNoteCodeObjectVersion(&majorVersion, &minorVersion)) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; @@ -1120,6 +1117,13 @@ hsa_status_t ExecutableImpl::LoadCodeObject( if (majorVersion != 1 && majorVersion != 2) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } if (agent.handle == 0 && majorVersion == 1) { return HSA_STATUS_ERROR_INVALID_AGENT; } + + if (majorVersion == 2 && (code->EFlags() & EF_AMDGPU_XNACK_LC)) + codeIsa = codeIsa + "-xnack"; + + hsa_isa_t objectsIsa = context_->IsaFromName(codeIsa.c_str()); + if (!objectsIsa.handle) { return HSA_STATUS_ERROR_INVALID_ISA_NAME; } + if (agent.handle != 0 && !context_->IsaSupportedByAgent(agent, objectsIsa)) { return HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS; } uint32_t codeHsailMajor;