mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
HSA runtime: accept unknown-OS target ids, answer two agent queries
Code objects whose target is spelled amdgcn-amd-amdhsa-unknown-<isa> (the ROCm device library's gfx12-generic object, for one) now load on an agent whose ISA is amdgcn-amd-amdhsa--<isa>; the two spellings name the same target. HSA_AMD_AGENT_INFO_MEMORY_PROPERTIES returns an empty property set and HSA_AMD_AGENT_INFO_PM4_EMULATION returns false for the GPU agent. The current HRX AMDGPU HAL queries both while opening a device.
This commit is contained in:
1 parent
e49c10704b
commit
592738b3c2
5 files changed
+50
-1
No files matched your search
@@ -5,6 +5,12 @@
|
||||
#include <map>
|
||||
|
||||
namespace mac_hsa {
|
||||
bool sameTargetId(const std::string &actual, const std::string &expected) {
|
||||
if (actual == expected) return true;
|
||||
static constexpr std::string_view empty = "amdgcn-amd-amdhsa--", unknown = "amdgcn-amd-amdhsa-unknown-";
|
||||
return expected.starts_with(empty) && actual.starts_with(unknown) &&
|
||||
std::string_view(actual).substr(unknown.size()) == std::string_view(expected).substr(empty.size());
|
||||
}
|
||||
namespace {
|
||||
bool range(uint64_t offset, uint64_t size, uint64_t capacity) {
|
||||
return offset <= capacity && size <= capacity - offset;
|
||||
@@ -114,7 +120,7 @@ bool metadata(std::span<const uint8_t> data, std::vector<KernelMetadata> &kernel
|
||||
version->array[1].kind != Value::Integer || version->array[1].integer > 2 ||
|
||||
!list || list->kind != Value::Array || list->array.empty()) return false;
|
||||
const auto target = root.get("amdhsa.target");
|
||||
if (target && (target->kind != Value::String || target->string != expectedTarget)) return false;
|
||||
if (target && (target->kind != Value::String || !sameTargetId(target->string, expectedTarget))) return false;
|
||||
for (const auto &item : list->array) {
|
||||
KernelMetadata kernel; uint32_t wave = 0;
|
||||
if (!string(item, ".name", kernel.name) || !string(item, ".symbol", kernel.symbol) ||
|
||||
|
||||
@@ -40,4 +40,9 @@ bool parseCodeObject(std::span<const uint8_t> file, CodeObject &output, const Is
|
||||
// The e_flags/EI_ABIVERSION of an AMDHSA ELF header, without parsing further.
|
||||
bool codeObjectHeader(std::span<const uint8_t> file, uint32_t &flags, uint8_t &abiVersion);
|
||||
bool relocateCodeObject(CodeObject &object, uint64_t gpuAddress);
|
||||
// Target IDs compare equal when they differ only in how the triple spells an
|
||||
// empty environment: LLVM normalizes amdgcn-amd-amdhsa- and
|
||||
// amdgcn-amd-amdhsa-unknown- to the same triple, and toolchains write either
|
||||
// (HRX System's prebuilt device library says amdgcn-amd-amdhsa-unknown-).
|
||||
bool sameTargetId(const std::string &actual, const std::string &expected);
|
||||
}
|
||||
@@ -309,6 +309,19 @@ hsa_status_t hsa_agent_get_info(hsa_agent_t handle, hsa_agent_info_t attribute,
|
||||
case HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES:
|
||||
case HSA_AMD_AGENT_INFO_SVM_DIRECT_HOST_ACCESS:
|
||||
return writeValue(value,false);
|
||||
case HSA_AMD_AGENT_INFO_MEMORY_PROPERTIES: {
|
||||
// An 8-byte flag set (hsa_amd_memory_property_agent_t bits). A GPU
|
||||
// behind this transport is a discrete device with its own VRAM, so
|
||||
// none is set: in particular not HSA_AMD_MEMORY_PROPERTY_AGENT_IS_APU.
|
||||
if (!agent->connection) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
std::memset(value, 0, 8);
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
case HSA_AMD_AGENT_INFO_PM4_EMULATION:
|
||||
// The GPU's command processor consumes these AQL queues itself; no
|
||||
// host translates AQL packets into PM4. A CPU agent has no queues.
|
||||
if (!agent->connection) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
return writeValue(value,false);
|
||||
case HSA_AGENT_INFO_DEFAULT_FLOAT_ROUNDING_MODE:
|
||||
return writeValue(value,HSA_DEFAULT_FLOAT_ROUNDING_MODE_NEAR);
|
||||
// The deprecated agent-level ISA attributes answer for the agent's first
|
||||
|
||||
@@ -75,6 +75,16 @@ int main() {
|
||||
CHECK(info<uint32_t>(gpu, HSA_AMD_AGENT_INFO_CHIP_ID) == 0x0f0f, "chip id");
|
||||
CHECK(info<uint32_t>(gpu, HSA_AMD_AGENT_INFO_ASIC_REVISION) == 0x02, "asic revision");
|
||||
CHECK(info<uint32_t>(gpu, HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT) == 104, "compute units");
|
||||
// Queues are consumed by the GPU's own command processor, and the GPU
|
||||
// is a discrete device: no PM4 emulation, no APU memory property.
|
||||
hsa_status_t queried = HSA_STATUS_ERROR;
|
||||
CHECK(!info<bool>(gpu, HSA_AMD_AGENT_INFO_PM4_EMULATION, &queried) && queried == HSA_STATUS_SUCCESS,
|
||||
"AQL queues are not PM4-emulated");
|
||||
uint8_t memoryProperties[8];
|
||||
std::memset(memoryProperties, 0xff, sizeof(memoryProperties));
|
||||
CHECK(hsa_agent_get_info(gpu, hsa_agent_info_t(HSA_AMD_AGENT_INFO_MEMORY_PROPERTIES), memoryProperties) ==
|
||||
HSA_STATUS_SUCCESS && !(memoryProperties[0] & HSA_AMD_MEMORY_PROPERTY_AGENT_IS_APU),
|
||||
"memory properties report a discrete GPU");
|
||||
CHECK(info<uint32_t>(gpu, HSA_AGENT_INFO_WAVEFRONT_SIZE) == 64, "wavefront size 64");
|
||||
CHECK(info<uint32_t>(gpu, HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU) == 4, "SIMDs per CU");
|
||||
CHECK(info<uint32_t>(gpu, HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU) == 32, "max waves per CU = SIMDs x waves/SIMD");
|
||||
|
||||
@@ -217,6 +217,21 @@ int main() {
|
||||
"converted protocol has no GC 11 load sequence and loads nothing");
|
||||
}
|
||||
|
||||
// Metadata target IDs: an empty triple environment may be spelled
|
||||
// "unknown" (HRX System's prebuilt gfx12-generic device library is), and
|
||||
// nothing else about the ID may differ.
|
||||
CHECK(sameTargetId("amdgcn-amd-amdhsa--gfx12-generic", "amdgcn-amd-amdhsa--gfx12-generic"), "identical target IDs match");
|
||||
CHECK(sameTargetId("amdgcn-amd-amdhsa-unknown-gfx12-generic", "amdgcn-amd-amdhsa--gfx12-generic"),
|
||||
"unknown environment matches an empty one");
|
||||
CHECK(sameTargetId("amdgcn-amd-amdhsa-unknown-gfx90a:xnack-", "amdgcn-amd-amdhsa--gfx90a:xnack-"),
|
||||
"unknown environment matches with feature suffixes");
|
||||
CHECK(!sameTargetId("amdgcn-amd-amdhsa-unknown-gfx11-generic", "amdgcn-amd-amdhsa--gfx12-generic"),
|
||||
"a different processor does not match");
|
||||
CHECK(!sameTargetId("amdgcn-amd-amdhsa-gnu-gfx12-generic", "amdgcn-amd-amdhsa--gfx12-generic"),
|
||||
"a named environment does not match");
|
||||
CHECK(!sameTargetId("amdgcn-amd-amdhsa-unknown-gfx90a:xnack+", "amdgcn-amd-amdhsa--gfx90a:xnack-"),
|
||||
"a different feature does not match");
|
||||
|
||||
std::fprintf(stderr, "\n%s: %d failure(s)\n", failures ? "FAIL" : "PASS", failures);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
Reference in new issue
Block a user