Skip to content

Commit 8b6b9c1

Browse files
cfreeamdAlexandru Tudor
authored andcommitted
rocr: Dynamically allocate supported_isas map
This was missing from a previous commit regarding dynamically allocated static data structures. Change-Id: Ia22c1620292f9fbb58aa6931fbca1bebb9a1c6bd
1 parent 4d96f2e commit 8b6b9c1

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

runtime/hsa-runtime/core/inc/isa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> {
185185
hsa_fp_type_t fp_type,
186186
hsa_flush_mode_t flush_mode) const;
187187

188-
private:
189188
/// @brief Default constructor.
190189
Isa()
191190
: targetid_(nullptr),
192191
version_(Version(-1, -1, -1)),
193192
sramecc_(IsaFeature::Unsupported),
194193
xnack_(IsaFeature::Unsupported) {}
194+
private:
195195

196196
// @brief Isa's target ID name.
197197
const char* targetid_;

runtime/hsa-runtime/core/runtime/isa.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
////////////////////////////////////////////////////////////////////////////////
4242

4343
#include "core/inc/isa.h"
44+
#include "core/util/utils.h"
4445

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

99+
static __forceinline std::string prepend_isa_prefix(const std::string &isa_name) {
100+
constexpr char hsa_isa_name_prefix[] = "amdgcn-amd-amdhsa--";
101+
return hsa_isa_name_prefix + isa_name;
102+
}
103+
98104
std::string Isa::GetIsaName() const {
99105
constexpr char hsa_isa_name_prefix[] = "amdgcn-amd-amdhsa--";
100106
return std::string(hsa_isa_name_prefix) + targetid_;
@@ -221,27 +227,27 @@ const Isa *IsaRegistry::GetIsa(const Isa::Version &version, IsaFeature sramecc,
221227

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

224-
// agent, and vendor name length limit excluding terminating nul character.
225-
constexpr size_t hsa_name_size = 63;
230+
// agent, and vendor name length limit excluding terminating nul character.
231+
constexpr size_t hsa_name_size = 63;
232+
// This allocation is meant to last until the last thread has exited.
233+
// It is intentionally not freed.
234+
static IsaMap* supported_isas = new IsaMap();
235+
236+
if (supported_isas->size() > 0) {
237+
return *supported_isas;
238+
}
226239

227240
// FIXME: Use static_assert when C++17 used.
228241
#define ISAREG_ENTRY_GEN(name, maj, min, stp, sramecc, xnack, wavefrontsize) \
229-
assert(std::char_traits<char>::length(name) <= hsa_name_size); \
230-
Isa amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize; \
231-
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.targetid_ = name; \
232-
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.version_ = Isa::Version(maj, min, stp); \
233-
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.sramecc_ = sramecc; \
234-
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.xnack_ = xnack; \
235-
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.wavefront_.num_threads_ = wavefrontsize; \
236-
supported_isas.insert(std::make_pair( \
237-
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize.GetIsaName(), \
238-
amd_amdgpu_##maj##min##stp##_SRAMECC_##sramecc##_XNACK_##xnack##_WAVEFRONTSIZE_##wavefrontsize)); \
239-
240-
static IsaMap supported_isas;
241-
242-
if (supported_isas.size() > 0) {
243-
return supported_isas;
244-
}
242+
{ \
243+
assert(std::char_traits<char>::length(name) <= hsa_name_size); \
244+
std::string isa_name = prepend_isa_prefix(name); \
245+
(*supported_isas)[isa_name].targetid_ = name; \
246+
(*supported_isas)[isa_name].version_ = Isa::Version(maj, min, stp); \
247+
(*supported_isas)[isa_name].sramecc_ = sramecc; \
248+
(*supported_isas)[isa_name].xnack_ = xnack; \
249+
(*supported_isas)[isa_name].wavefront_.num_threads_ = wavefrontsize; \
250+
}
245251

246252
const IsaFeature unsupported = IsaFeature::Unsupported;
247253
const IsaFeature any = IsaFeature::Any;
@@ -359,7 +365,7 @@ constexpr size_t hsa_name_size = 63;
359365
ISAREG_ENTRY_GEN("gfx1200", 12, 0, 0, unsupported, unsupported, 32)
360366
ISAREG_ENTRY_GEN("gfx1201", 12, 0, 1, unsupported, unsupported, 32)
361367
#undef ISAREG_ENTRY_GEN
362-
return supported_isas;
368+
return *supported_isas;
363369
}
364370

365371
} // namespace core

0 commit comments

Comments
 (0)