diff --git a/hipamd/src/amd_hsa_elf.hpp b/hipamd/src/amd_hsa_elf.hpp index ca22fd1f6c..383d4562be 100644 --- a/hipamd/src/amd_hsa_elf.hpp +++ b/hipamd/src/amd_hsa_elf.hpp @@ -31,7 +31,8 @@ enum { ELFOSABI_AMDGPU_HSA = 64, ELFOSABI_AMDGPU_PAL = 65, ELFOSABI_AMDGPU_MESA3 enum { ELFABIVERSION_AMDGPU_HSA_V2 = 0, ELFABIVERSION_AMDGPU_HSA_V3 = 1, - ELFABIVERSION_AMDGPU_HSA_V4 = 2 + ELFABIVERSION_AMDGPU_HSA_V4 = 2, + ELFABIVERSION_AMDGPU_HSA_V5 = 3 }; // AMDGPU specific e_flags diff --git a/hipamd/src/hip_code_object.cpp b/hipamd/src/hip_code_object.cpp index dd9de6374f..ae697775b5 100644 --- a/hipamd/src/hip_code_object.cpp +++ b/hipamd/src/hip_code_object.cpp @@ -256,8 +256,7 @@ static bool getProcName(uint32_t EFlags, std::string& proc_name, bool& xnackSupp return true; } -static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string& target_id, - unsigned& co_version) { +static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string& target_id) { if (!code_object) return false; const Elf64_Ehdr* ehdr = reinterpret_cast(code_object); if (ehdr->e_machine != EM_AMDGPU) return false; @@ -271,12 +270,12 @@ static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string switch (ehdr->e_ident[EI_ABIVERSION]) { case ELFABIVERSION_AMDGPU_HSA_V2: { - co_version = 2; + LogPrintfInfo("[Code Object V2, target id:%s]", target_id.c_str()); return false; } case ELFABIVERSION_AMDGPU_HSA_V3: { - co_version = 3; + LogPrintfInfo("[Code Object V3, target id:%s]", target_id.c_str()); if (isSramEccSupported) { if (ehdr->e_flags & EF_AMDGPU_FEATURE_SRAMECC_V3) target_id += ":sramecc+"; @@ -292,8 +291,13 @@ static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string break; } - case ELFABIVERSION_AMDGPU_HSA_V4: { - co_version = 4; + case ELFABIVERSION_AMDGPU_HSA_V4: + case ELFABIVERSION_AMDGPU_HSA_V5: { + if (ehdr->e_ident[EI_ABIVERSION] & ELFABIVERSION_AMDGPU_HSA_V4) { + LogPrintfInfo("[Code Object V4, target id:%s]", target_id.c_str()); + } else { + LogPrintfInfo("[Code Object V5, target id:%s]", target_id.c_str()); + } unsigned co_sram_value = (ehdr->e_flags) & EF_AMDGPU_FEATURE_SRAMECC_V4; if (co_sram_value == EF_AMDGPU_FEATURE_SRAMECC_OFF_V4) target_id += ":sramecc-"; @@ -361,18 +365,17 @@ static bool getTargetIDValue(std::string& input, std::string& processor, char& s } static bool getTripleTargetID(std::string bundled_co_entry_id, const void* code_object, - std::string& co_triple_target_id, unsigned& co_version) { + std::string& co_triple_target_id) { std::string offload_kind = trimName(bundled_co_entry_id, '-'); if (offload_kind != OFFLOAD_KIND_HIPV4 && offload_kind != OFFLOAD_KIND_HIP && offload_kind != OFFLOAD_KIND_HCC) return false; if (offload_kind != OFFLOAD_KIND_HIPV4) - return getTripleTargetIDFromCodeObject(code_object, co_triple_target_id, co_version); + return getTripleTargetIDFromCodeObject(code_object, co_triple_target_id); // For code object V4 onwards the bundled code object entry ID correctly - // specifies the target tripple. - co_version = 4; + // specifies the target triple. co_triple_target_id = bundled_co_entry_id.substr(1); return true; } @@ -485,9 +488,8 @@ hipError_t CodeObject::extractCodeObjectFromFatBinary( if (num_code_objs == 0) break; std::string bundleEntryId{desc->bundleEntryId, desc->bundleEntryIdSize}; - unsigned co_version = 0; std::string co_triple_target_id; - if (!getTripleTargetID(bundleEntryId, image, co_triple_target_id, co_version)) continue; + if (!getTripleTargetID(bundleEntryId, image, co_triple_target_id)) continue; for (size_t dev = 0; dev < agent_triple_target_ids.size(); ++dev) { if (code_objs[dev].first) continue; @@ -518,12 +520,11 @@ hipError_t CodeObject::extractCodeObjectFromFatBinary( const void* image = reinterpret_cast(reinterpret_cast(obheader) + desc->offset); - unsigned co_version = 0; std::string co_triple_target_id; - bool valid_co = getTripleTargetID(bundleEntryId, image, co_triple_target_id, co_version); + bool valid_co = getTripleTargetID(bundleEntryId, image, co_triple_target_id); if (valid_co) { - LogPrintfError(" %s - [code object v%u is %s]", bundleEntryId.c_str(), co_version, + LogPrintfError(" %s - [code object targetID is %s]", bundleEntryId.c_str(), co_triple_target_id.c_str()); } else { LogPrintfError(" %s - [Unsupported]", bundleEntryId.c_str()); diff --git a/hipamd/src/hiprtc/hiprtcComgrHelper.cpp b/hipamd/src/hiprtc/hiprtcComgrHelper.cpp index c3794c618b..7c5ab5b772 100644 --- a/hipamd/src/hiprtc/hiprtcComgrHelper.cpp +++ b/hipamd/src/hiprtc/hiprtcComgrHelper.cpp @@ -243,8 +243,7 @@ static bool getProcName(uint32_t EFlags, std::string& proc_name, bool& xnackSupp return true; } -static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string& target_id, - unsigned& co_version) { +static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string& target_id) { if (!code_object) return false; const Elf64_Ehdr* ehdr = reinterpret_cast(code_object); if (ehdr->e_machine != EM_AMDGPU) return false; @@ -258,12 +257,12 @@ static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string switch (ehdr->e_ident[EI_ABIVERSION]) { case ELFABIVERSION_AMDGPU_HSA_V2: { - co_version = 2; + LogPrintfInfo("[Code Object V2, target id:%s]", target_id.c_str()); return false; } case ELFABIVERSION_AMDGPU_HSA_V3: { - co_version = 3; + LogPrintfInfo("[Code Object V3, target id:%s]", target_id.c_str()); if (isSramEccSupported) { if (ehdr->e_flags & EF_AMDGPU_FEATURE_SRAMECC_V3) target_id += ":sramecc+"; @@ -279,8 +278,13 @@ static bool getTripleTargetIDFromCodeObject(const void* code_object, std::string break; } - case ELFABIVERSION_AMDGPU_HSA_V4: { - co_version = 4; + case ELFABIVERSION_AMDGPU_HSA_V4: + case ELFABIVERSION_AMDGPU_HSA_V5: { + if (ehdr->e_ident[EI_ABIVERSION] & ELFABIVERSION_AMDGPU_HSA_V4) { + LogPrintfInfo("[Code Object V4, target id:%s]", target_id.c_str()); + } else { + LogPrintfInfo("[Code Object V5, target id:%s]", target_id.c_str()); + } unsigned co_sram_value = (ehdr->e_flags) & EF_AMDGPU_FEATURE_SRAMECC_V4; if (co_sram_value == EF_AMDGPU_FEATURE_SRAMECC_OFF_V4) target_id += ":sramecc-"; @@ -348,18 +352,17 @@ static bool getTargetIDValue(std::string& input, std::string& processor, char& s } static bool getTripleTargetID(std::string bundled_co_entry_id, const void* code_object, - std::string& co_triple_target_id, unsigned& co_version) { + std::string& co_triple_target_id) { std::string offload_kind = trimName(bundled_co_entry_id, '-'); if (offload_kind != OFFLOAD_KIND_HIPV4 && offload_kind != OFFLOAD_KIND_HIP && offload_kind != OFFLOAD_KIND_HCC) return false; if (offload_kind != OFFLOAD_KIND_HIPV4) - return getTripleTargetIDFromCodeObject(code_object, co_triple_target_id, co_version); + return getTripleTargetIDFromCodeObject(code_object, co_triple_target_id); // For code object V4 onwards the bundled code object entry ID correctly - // specifies the target tripple. - co_version = 4; + // specifies the target triple. co_triple_target_id = bundled_co_entry_id.substr(1); return true; }