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
이 커밋은 다음에 포함됨:
David Yat Sin가 2023-07-24 13:59:13 -04:00를 커밋했습니다
1 부모 0d14144e3a
커밋 469defa78a
4 파일이 변경됨
+29 -13

검색과 일치하는 파일 없음

+2
파일 보기
@@ -289,6 +289,8 @@ class GpuAgent : public GpuAgentInt {
return current_coherency_type_;
}
core::Agent* GetNearestCpuAgent(void) const;
// Getter & setters.
// @brief Returns Hive ID
+3
파일 보기
@@ -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
파일 보기
@@ -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