Skip to content

Commit 3ad8f1b

Browse files
committed
SWDEV-496667 - Support gfx9-4-generic target
Support gfx9-4-generic target to cover mi3XX. Support features sramecc and xnack in generic target. Improve some code formats. Add more log on compiler. Change-Id: I6b3c6af55c60cffd43ce6f17b75998f751b75713
1 parent 537f2ff commit 3ad8f1b

File tree

5 files changed

+45
-12
lines changed

5 files changed

+45
-12
lines changed

hipamd/src/amd_hsa_elf.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ enum : unsigned {
121121
EF_AMDGPU_MACH_AMDGCN_RESERVED_0X57 = 0x057,
122122
EF_AMDGPU_MACH_AMDGCN_RESERVED_0X58 = 0x058,
123123
EF_AMDGPU_MACH_AMDGCN_GFX12_GENERIC = 0x059,
124+
EF_AMDGPU_MACH_AMDGCN_GFX9_4_GENERIC = 0x05f,
124125

125126
// First/last AMDGCN-based processors.
126127
EF_AMDGPU_MACH_AMDGCN_FIRST = EF_AMDGPU_MACH_AMDGCN_GFX600,
127-
EF_AMDGPU_MACH_AMDGCN_LAST = EF_AMDGPU_MACH_AMDGCN_GFX12_GENERIC,
128+
EF_AMDGPU_MACH_AMDGCN_LAST = EF_AMDGPU_MACH_AMDGCN_GFX9_4_GENERIC,
128129

129130
// Indicates if the "xnack" target feature is enabled for all code contained
130131
// in the object.

hipamd/src/hip_code_object.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool CodeObject::IsClangOffloadMagicBundle(const void* data, bool& isCompressed)
9797
return false;
9898
}
9999

100-
unsigned int CodeObject::getGenericVersion(const void* image) {
100+
uint32_t CodeObject::getGenericVersion(const void* image) {
101101
const Elf64_Ehdr* ehdr = reinterpret_cast<const Elf64_Ehdr*>(image);
102102
return (ehdr->e_machine == EM_AMDGPU && ehdr->e_ident[EI_OSABI] == ELFOSABI_AMDGPU_HSA &&
103103
ehdr->e_ident[EI_ABIVERSION] == ELFABIVERSION_AMDGPU_HSA_V6) ?
@@ -339,6 +339,11 @@ static bool getProcName(uint32_t EFlags, std::string& proc_name, bool& xnackSupp
339339
sramEccSupported = false;
340340
proc_name = "gfx9-generic";
341341
break;
342+
case EF_AMDGPU_MACH_AMDGCN_GFX9_4_GENERIC:
343+
xnackSupported = true;
344+
sramEccSupported = true;
345+
proc_name = "gfx9-4-generic";
346+
break;
342347
case EF_AMDGPU_MACH_AMDGCN_GFX10_1_GENERIC:
343348
xnackSupported = true;
344349
sramEccSupported = false;
@@ -455,6 +460,11 @@ static bool isCompatibleWithGenericTarget(std::string& coTarget, std::string& ag
455460
{"gfx906", "gfx9-generic"},
456461
{"gfx909", "gfx9-generic"},
457462
{"gfx90c", "gfx9-generic"},
463+
// "gfx9-4-generic"
464+
{"gfx940", "gfx9-4-generic"},
465+
{"gfx941", "gfx9-4-generic"},
466+
{"gfx942", "gfx9-4-generic"},
467+
{"gfx950", "gfx9-4-generic"},
458468
// "gfx10-1-generic"
459469
{"gfx1010", "gfx10-1-generic"},
460470
{"gfx1011", "gfx10-1-generic"},
@@ -656,17 +666,17 @@ hipError_t CodeObject::extractCodeObjectFromFatBinary(
656666
std::string bundleEntryId{desc->bundleEntryId, desc->bundleEntryIdSize};
657667

658668
std::string co_triple_target_id;
659-
unsigned int genericVersion = getGenericVersion(image);
669+
uint32_t genericVersion = getGenericVersion(image);
660670
if (!getTripleTargetID(bundleEntryId, image, co_triple_target_id)) continue;
661-
LogPrintfInfo("bundleEntryId=%s, co_triple_target_id=%s, genericVersion=%d\n", bundleEntryId.c_str(),
662-
co_triple_target_id.c_str(), genericVersion);
671+
LogPrintfInfo("bundleEntryId=%s, co_triple_target_id=%s, genericVersion=%u\n",
672+
bundleEntryId.c_str(), co_triple_target_id.c_str(), genericVersion);
663673

664674
for (size_t dev = 0; dev < agent_triple_target_ids.size(); ++dev) {
665675
if (code_objs[dev].first) {
666-
// Specific target already matched, skipped.
667-
// But for generic target, we will continue searching for matched specific target.
668676
if (!isGenericTarget(code_objs[dev].first)) {
669-
continue;
677+
continue; // Specific target already found
678+
} else if(genericVersion >= EF_AMDGPU_GENERIC_VERSION_MIN) {
679+
continue; // Generic target already found, no need to check another generic
670680
}
671681
}
672682
if (isCodeObjectCompatibleWithDevice(co_triple_target_id, agent_triple_target_ids[dev],

hipamd/src/hip_code_object.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CodeObject {
6565

6666
static bool IsClangOffloadMagicBundle(const void* data, bool& isCompressed);
6767

68-
static unsigned int getGenericVersion(const void* image);
68+
static uint32_t getGenericVersion(const void* image);
6969

7070
static bool isGenericTarget(const void* image);
7171

rocclr/device/device.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,18 @@ std::pair<const Isa*, const Isa*> Isa::supportedIsas() {
200200
{"gfx90c", nullptr, true, true, 9, 0, 12, NONE, ANY, 4, 16, 1, 256, 64 * Ki, 32},
201201
{"gfx90c:xnack-", "gfx90c", true, true, 9, 0, 12, NONE, OFF, 4, 16, 1, 256, 64 * Ki, 32},
202202
{"gfx90c:xnack+", "gfx90d", true, true, 9, 0, 12, NONE, ON, 4, 16, 1, 256, 64 * Ki, 32},
203-
{"gfx9-generic", nullptr, true, true, 9, 0, 0, NONE, ON, 4, 16, 1, 256, 64 * Ki, 32},
203+
{"gfx9-generic", nullptr, true, true, 9, 0, 0, NONE, ANY, 4, 16, 1, 256, 64 * Ki, 32},
204+
{"gfx9-generic:xnack-", nullptr, true, true, 9, 0, 0, NONE, OFF, 4, 16, 1, 256, 64 * Ki, 32},
205+
{"gfx9-generic:xnack+", nullptr, true, true, 9, 0, 0, NONE, ON, 4, 16, 1, 256, 64 * Ki, 32},
206+
{"gfx9-4-generic", nullptr, true, true, 9, 4, 0, ANY, ANY, 4, 16, 1, 256, 64 * Ki, 32},
207+
{"gfx9-4-generic:sramecc-",nullptr, true, true, 9, 4, 0, OFF, ANY, 4, 16, 1, 256, 64 * Ki, 32},
208+
{"gfx9-4-generic:sramecc+",nullptr, true, true, 9, 4, 0, ON, ANY, 4, 16, 1, 256, 64 * Ki, 32},
209+
{"gfx9-4-generic:xnack-", nullptr, true, true, 9, 4, 0, ANY, OFF, 4, 16, 1, 256, 64 * Ki, 32},
210+
{"gfx9-4-generic:xnack+", nullptr, true, true, 9, 4, 0, ANY, ON, 4, 16, 1, 256, 64 * Ki, 32},
211+
{"gfx9-4-generic:sramecc-:xnack-",nullptr,true,true, 9, 4, 0, OFF, OFF, 4, 16, 1, 256, 64 * Ki, 32},
212+
{"gfx9-4-generic:sramecc-:xnack+",nullptr,true,true, 9, 4, 0, OFF, ON, 4, 16, 1, 256, 64 * Ki, 32},
213+
{"gfx9-4-generic:sramecc+:xnack-",nullptr,true,true, 9, 4, 0, ON, OFF, 4, 16, 1, 256, 64 * Ki, 32},
214+
{"gfx9-4-generic:sramecc+:xnack+",nullptr,true,true, 9, 4, 0, ON, ON, 4, 16, 1, 256, 64 * Ki, 32},
204215
{"gfx1010", "gfx1010", true, true, 10, 1, 0, NONE, ANY, 2, 32, 1, 256, 64 * Ki, 32},
205216
{"gfx1010:xnack-", "gfx1010", true, true, 10, 1, 0, NONE, OFF, 2, 32, 1, 256, 64 * Ki, 32},
206217
{"gfx1010:xnack+", nullptr, true, true, 10, 1, 0, NONE, ON, 2, 32, 1, 256, 64 * Ki, 32},
@@ -213,7 +224,9 @@ std::pair<const Isa*, const Isa*> Isa::supportedIsas() {
213224
{"gfx1013", "gfx1013", true, false, 10, 1, 3, NONE, ANY, 2, 32, 1, 256, 64 * Ki, 32},
214225
{"gfx1013:xnack-", "gfx1013", true, false, 10, 1, 3, NONE, OFF, 2, 32, 1, 256, 64 * Ki, 32},
215226
{"gfx1013:xnack+", nullptr, true, false, 10, 1, 3, NONE, ON, 2, 32, 1, 256, 64 * Ki, 32},
216-
{"gfx10-1-generic", nullptr, true, true, 10, 1, 0, NONE, ON, 2, 32, 1, 256, 64 * Ki, 32},
227+
{"gfx10-1-generic", nullptr, true, true, 10, 1, 0, NONE, ANY, 2, 32, 1, 256, 64 * Ki, 32},
228+
{"gfx10-1-generic:xnack-", nullptr, true, true, 10, 1, 0, NONE, OFF, 2, 32, 1, 256, 64 * Ki, 32},
229+
{"gfx10-1-generic:xnack+", nullptr, true, true, 10, 1, 0, NONE, ON, 2, 32, 1, 256, 64 * Ki, 32},
217230
{"gfx1030", "gfx1030", true, true, 10, 3, 0, NONE, NONE, 2, 32, 1, 256, 64 * Ki, 32},
218231
{"gfx1031", "gfx1031", true, true, 10, 3, 1, NONE, NONE, 2, 32, 1, 256, 64 * Ki, 32},
219232
{"gfx1032", "gfx1032", true, true, 10, 3, 2, NONE, NONE, 2, 32, 1, 256, 64 * Ki, 32},
@@ -252,8 +265,11 @@ bool Isa::isCompatible(const Isa &codeObjectIsa, const Isa &agentIsa) {
252265
if (codeObjectIsa.versionMajor() != agentIsa.versionMajor() ||
253266
codeObjectIsa.versionMinor() > agentIsa.versionMinor() ||
254267
(codeObjectIsa.versionMinor() == agentIsa.versionMinor() &&
255-
codeObjectIsa.versionStepping() > agentIsa.versionStepping()))
268+
codeObjectIsa.versionStepping() > agentIsa.versionStepping())) {
256269
return false;
270+
}
271+
#ifdef DEBUG
272+
// Only check in DEBUG mode
257273
if (std::strstr(agentIsa.targetId(), "gfx906") != nullptr) {
258274
// For the generic target of gfx906, codeObjectIsa.isSrameccSupported() == false while
259275
// agentIsa.isSrameccSupported() = true
@@ -263,6 +279,7 @@ bool Isa::isCompatible(const Isa &codeObjectIsa, const Isa &agentIsa) {
263279
assert(codeObjectIsa.isSrameccSupported() == agentIsa.isSrameccSupported() &&
264280
agentIsa.sramecc() != Feature::Any);
265281
}
282+
#endif
266283
} else {
267284
if (codeObjectIsa.versionMajor() != agentIsa.versionMajor() ||
268285
codeObjectIsa.versionMinor() != agentIsa.versionMinor() ||

rocclr/platform/program.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,16 @@ bool Program::load(const std::vector<Device*>& devices) {
612612
}
613613

614614
if (!devProgram.load()) {
615+
if (!devProgram.buildLog().empty()) {
616+
LogPrintfError("devProgram.load() failed with buildLog=%s\n",
617+
devProgram.buildLog().c_str());
618+
}
615619
return false;
616620
}
617621

618622
// Run kernels marked with init
619623
if (!devProgram.runInitKernels()) {
624+
LogError("runInitKernels() failed\n");
620625
return false;
621626
}
622627
}

0 commit comments

Comments
 (0)