Add agent query for nearest CPU agent

Add agent info query to return nearest CPU agent. This can be used to
determine which CPU agent is in the same NUMA region as the GPU agent.

Change-Id: I5400b4347ffbf4d2a836df31c4de443a38b0ecd1
Dieser Commit ist enthalten in:
David Yat Sin committed 2023-07-24 13:59:13 -04:00
1 Ursprung 0d14144e3a
Commit 469defa78a
4 Dateien geändert
+29 -13

Keine Dateien entsprechen Ihrer Suche

+2
Datei anzeigen
@@ -289,6 +289,8 @@ class GpuAgent : public GpuAgentInt {
return current_coherency_type_;
}
core::Agent* GetNearestCpuAgent(void) const;
// Getter & setters.
// @brief Returns Hive ID
@@ -391,6 +391,9 @@ hsa_status_t CpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const {
case HSA_AMD_AGENT_INFO_DRIVER_UID:
*((uint32_t*)value) = 0;
break;
case HSA_AMD_AGENT_INFO_NEAREST_CPU:
((hsa_agent_t*)value)->handle = 0;
break;
default:
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
break;
+18 -12
Datei anzeigen
@@ -1367,6 +1367,9 @@ hsa_status_t GpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const {
case HSA_AMD_AGENT_INFO_DRIVER_UID:
*((uint32_t*)value) = KfdGpuID();
break;
case HSA_AMD_AGENT_INFO_NEAREST_CPU:
*((hsa_agent_t*)value) = GetNearestCpuAgent()->public_handle();
break;
default:
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
break;
@@ -1985,18 +1988,7 @@ void GpuAgent::Trim() {
}
void GpuAgent::InitNumaAllocator() {
Agent* nearCpu = nullptr;
uint32_t dist = -1u;
for (auto cpu : core::Runtime::runtime_singleton_->cpu_agents()) {
const core::Runtime::LinkInfo link_info =
core::Runtime::runtime_singleton_->GetLinkInfo(node_id(), cpu->node_id());
if (link_info.info.numa_distance < dist) {
dist = link_info.info.numa_distance;
nearCpu = cpu;
}
}
for (auto pool : nearCpu->regions()) {
for (auto pool : GetNearestCpuAgent()->regions()) {
if (pool->kernarg()) {
system_allocator_ = [pool](size_t size, size_t alignment,
MemoryRegion::AllocateFlags alloc_flags) -> void* {
@@ -2016,5 +2008,19 @@ void GpuAgent::InitNumaAllocator() {
assert(false && "Nearest NUMA node did not have a kernarg pool.");
}
core::Agent* GpuAgent::GetNearestCpuAgent() const {
core::Agent* nearCpu = nullptr;
uint32_t dist = -1u;
for (auto cpu : core::Runtime::runtime_singleton_->cpu_agents()) {
const core::Runtime::LinkInfo link_info =
core::Runtime::runtime_singleton_->GetLinkInfo(node_id(), cpu->node_id());
if (link_info.info.numa_distance < dist) {
dist = link_info.info.numa_distance;
nearCpu = cpu;
}
}
return nearCpu;
}
} // namespace amd
} // namespace rocr
+6 -1
Datei anzeigen
@@ -399,7 +399,12 @@ typedef enum hsa_amd_agent_info_s {
* Queries for driver unique identifier.
* The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_DRIVER_UID = 0xA112
HSA_AMD_AGENT_INFO_DRIVER_UID = 0xA112,
/**
* Returns the hsa_agent_t of the nearest CPU agent
* The type of this attribute is hsa_agent_t.
*/
HSA_AMD_AGENT_INFO_NEAREST_CPU = 0xA113
} hsa_amd_agent_info_t;
/**