Skip to content

Commit

Permalink
rocr: Dynamically allocate supported_isas map
Browse files Browse the repository at this point in the history
This was missing from a previous commit regarding
dynamically allocated static data structures.

Change-Id: Ia22c1620292f9fbb58aa6931fbca1bebb9a1c6bd
  • Loading branch information
cfreeamd authored and Alexandru Tudor committed Dec 10, 2024
1 parent 4d96f2e commit 8b6b9c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion runtime/hsa-runtime/core/inc/isa.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> {
hsa_fp_type_t fp_type,
hsa_flush_mode_t flush_mode) const;

private:
/// @brief Default constructor.
Isa()
: targetid_(nullptr),
version_(Version(-1, -1, -1)),
sramecc_(IsaFeature::Unsupported),
xnack_(IsaFeature::Unsupported) {}
private:

// @brief Isa's target ID name.
const char* targetid_;
Expand Down
44 changes: 25 additions & 19 deletions runtime/hsa-runtime/core/runtime/isa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "core/inc/isa.h"
#include "core/util/utils.h"

#include <algorithm>
#include <cstring>
Expand Down Expand Up @@ -95,6 +96,11 @@ std::string Isa::GetProcessorName() const {
return processor.substr(0, processor.find(':'));
}

static __forceinline std::string prepend_isa_prefix(const std::string &isa_name) {
constexpr char hsa_isa_name_prefix[] = "amdgcn-amd-amdhsa--";
return hsa_isa_name_prefix + isa_name;
}

std::string Isa::GetIsaName() const {
constexpr char hsa_isa_name_prefix[] = "amdgcn-amd-amdhsa--";
return std::string(hsa_isa_name_prefix) + targetid_;
Expand Down Expand Up @@ -221,27 +227,27 @@ const Isa *IsaRegistry::GetIsa(const Isa::Version &version, IsaFeature sramecc,

const IsaRegistry::IsaMap& IsaRegistry::GetSupportedIsas() {

// agent, and vendor name length limit excluding terminating nul character.
constexpr size_t hsa_name_size = 63;
// agent, and vendor name length limit excluding terminating nul character.
constexpr size_t hsa_name_size = 63;
// This allocation is meant to last until the last thread has exited.
// It is intentionally not freed.
static IsaMap* supported_isas = new IsaMap();

if (supported_isas->size() > 0) {
return *supported_isas;
}

// FIXME: Use static_assert when C++17 used.
#define ISAREG_ENTRY_GEN(name, maj, min, stp, sramecc, xnack, wavefrontsize) \
assert(std::char_traits<char>::length(name) <= hsa_name_size); \
Isa amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize; \
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.targetid_ = name; \
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.version_ = Isa::Version(maj, min, stp); \
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.sramecc_ = sramecc; \
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.xnack_ = xnack; \
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.wavefront_.num_threads_ = wavefrontsize; \
supported_isas.insert(std::make_pair( \
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.GetIsaName(), \
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize)); \

static IsaMap supported_isas;

if (supported_isas.size() > 0) {
return supported_isas;
}
{ \
assert(std::char_traits<char>::length(name) <= hsa_name_size); \
std::string isa_name = prepend_isa_prefix(name); \
(*supported_isas)[isa_name].targetid_ = name; \
(*supported_isas)[isa_name].version_ = Isa::Version(maj, min, stp); \
(*supported_isas)[isa_name].sramecc_ = sramecc; \
(*supported_isas)[isa_name].xnack_ = xnack; \
(*supported_isas)[isa_name].wavefront_.num_threads_ = wavefrontsize; \
}

const IsaFeature unsupported = IsaFeature::Unsupported;
const IsaFeature any = IsaFeature::Any;
Expand Down Expand Up @@ -359,7 +365,7 @@ constexpr size_t hsa_name_size = 63;
ISAREG_ENTRY_GEN("gfx1200", 12, 0, 0, unsupported, unsupported, 32)
ISAREG_ENTRY_GEN("gfx1201", 12, 0, 1, unsupported, unsupported, 32)
#undef ISAREG_ENTRY_GEN
return supported_isas;
return *supported_isas;
}

} // namespace core
Expand Down

0 comments on commit 8b6b9c1

Please sign in to comment.