From 3fdfbc56e4ddc26ed8a77614a948367c1fde1fdf Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 7 Dec 2020 05:35:00 +0000 Subject: [PATCH] Store target ID in isa registry Store target ID string in isa registry and use for returning agent and isa name. Change-Id: I72a20d8ff963c73d86392158aff3853e4c9bfdbd [ROCm/ROCR-Runtime commit: 853ccc762e9b2e2f07854f101340d22d074d70a0] --- .../runtime/hsa-runtime/core/inc/isa.h | 39 ++++++-------- .../core/runtime/amd_gpu_agent.cpp | 15 +++--- .../runtime/hsa-runtime/core/runtime/isa.cpp | 52 ++++++++----------- 3 files changed, 44 insertions(+), 62 deletions(-) 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 818216c496..aed14aa757 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/isa.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/isa.h @@ -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 @@ -178,7 +178,10 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { return true; } - /// @returns This Isa's full name. + /// @returns This Isa's processor name. + std::string GetName() const; + + /// @returns This Isa's full target triple and target ID name. std::string GetFullName() const; /// @brief Query value of requested @p attribute and record it in @p value. @@ -194,23 +197,13 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { private: /// @brief Default constructor. Isa() - : version_(Version(-1, -1, -1)), + : targetid_(nullptr), + version_(Version(-1, -1, -1)), sramecc_(IsaFeature::Unsupported), xnack_(IsaFeature::Unsupported) {} - /// @brief Construct from @p version. - Isa(const Version &version) - : version_(version), - sramecc_(IsaFeature::Unsupported), - xnack_(IsaFeature::Unsupported) {} - - /// @brief Construct from @p version. - Isa(const Version &version, - IsaFeature sramecc, - IsaFeature xnack) - : version_(version), - sramecc_(sramecc), - xnack_(xnack) {} + // @brief Isa's target ID name. + const char* targetid_; /// @brief Isa's version. Version version_; 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 c54107f946..add3302f34 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 @@ -726,21 +726,20 @@ hsa_status_t GpuAgent::EnableDmaProfiling(bool enable) { hsa_status_t GpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { // agent, and vendor name size limit const size_t attribute_u = static_cast(attribute); + // agent, and vendor name length limit excluding terminating nul character. + constexpr size_t hsa_name_size = 63; switch (attribute_u) { - // Build agent name by concatenating the Major, Minor and Stepping Ids - // of devices compute capability with a prefix of "gfx" case HSA_AGENT_INFO_NAME: { - std::stringstream name; - std::memset(value, 0, HSA_PUBLIC_NAME_SIZE); + std::string name = isa_->GetName(); + assert(name.size() <= hsa_name_size); + std::memset(value, 0, hsa_name_size); char* temp = reinterpret_cast(value); - name << "gfx" << isa_->GetMajorVersion() << std::hex << isa_->GetMinorVersion() - << isa_->GetStepping(); - std::strcpy(temp, name.str().c_str()); + std::strcpy(temp, name.c_str()); break; } case HSA_AGENT_INFO_VENDOR_NAME: - std::memset(value, 0, HSA_PUBLIC_NAME_SIZE); + std::memset(value, 0, hsa_name_size); std::memcpy(value, "AMD", sizeof("AMD")); break; case HSA_AGENT_INFO_FEATURE: 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 8f863c81dc..b1fd4335d0 100755 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/isa.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/isa.cpp @@ -42,7 +42,9 @@ #include "core/inc/isa.h" +#include #include +#include #include #include @@ -88,37 +90,14 @@ bool Isa::IsCompatible(const Isa &code_object_isa, return true; } +std::string Isa::GetName() const { + std::string processor(targetid_); + return processor.substr(0, processor.find(':')); +} + std::string Isa::GetFullName() const { - std::stringstream full_name; - auto fmt = full_name.flags(); - full_name << GetArchitecture() << "-" << GetVendor() << "-" << GetOS() << "-" - << GetEnvironment() << "-gfx" << GetMajorVersion() - << std::hex << GetMinorVersion() << GetStepping(); - full_name.flags(fmt); - - switch (sramecc_) { - case IsaFeature::Disabled: - full_name << ":sramecc-"; - break; - case IsaFeature::Enabled: - full_name << ":sramecc+"; - break; - default: - break; - } - - switch (xnack_) { - case IsaFeature::Disabled: - full_name << ":xnack-"; - break; - case IsaFeature::Enabled: - full_name << ":xnack+"; - break; - default: - break; - } - - return full_name.str(); + return GetArchitecture() + '-' + GetVendor() + '-' + GetOS() + '-' + GetEnvironment() + '-' + + targetid_; } bool Isa::GetInfo(const hsa_isa_info_t &attribute, void *value) const { @@ -225,7 +204,11 @@ const Isa *IsaRegistry::GetIsa(const std::string &full_name) { } const Isa *IsaRegistry::GetIsa(const Isa::Version &version, IsaFeature sramecc, IsaFeature xnack) { - auto isareg_iter = supported_isas_.find(Isa(version, sramecc, xnack).GetFullName()); + auto isareg_iter = std::find_if( + supported_isas_.begin(), supported_isas_.end(), [&](const IsaMap::value_type& isareg) { + return isareg.second.version() == version && isareg.second.sramecc() == sramecc && + isareg.second.xnack() == xnack; + }); return isareg_iter == supported_isas_.end() ? nullptr : &isareg_iter->second; } @@ -233,8 +216,15 @@ const IsaRegistry::IsaMap IsaRegistry::supported_isas_ = IsaRegistry::GetSupportedIsas(); const IsaRegistry::IsaMap IsaRegistry::GetSupportedIsas() { + +// agent, and vendor name length limit excluding terminating nul character. +constexpr size_t hsa_name_size = 63; + +// FIXME: Use static_assert when C++17 used. #define ISAREG_ENTRY_GEN(name, maj, min, stp, sramecc, xnack) \ + assert(std::char_traits::length(name) <= hsa_name_size); \ Isa amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack; \ + amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack.targetid_ = name; \ amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack.version_ = Isa::Version(maj, min, stp); \ amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack.sramecc_ = sramecc; \ amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack.xnack_ = xnack; \