Separate agent cache from queue controller (#145)

* Update lib/rocprofiler/agent.{hpp,cpp}

- get_agents() function for internal access to agent pointers

* Update AgentCache

- make member variables and member functions distinguish b/t hsa agent and rocprofiler agent clear

* Change ctor of AgentCache

* Update lib/rocprofiler/hsa/queue_controller.cpp

- QueueController::init uses agent::get_agent_cache

* Update lib/rocprofiler/hsa/agent_cache.*

- member function to get index
- operator== for rocprofiler_agent_t and hsa_agent_t
- removed hsa_iterate_agents from ctor (now in agent.cpp)

* Update lib/rocprofiler/agent.*

- construct_agent_cache function
- functions for rocprofiler agent <-> HSA agent
- functions for getting agent cache

* Update lib/rocprofiler/registration.cpp

- invoke construct_agent_cache when HSA table is receieved

* Update lib/rocprofiler/agent.cpp

- loosen failure conditions
- handle spurious duplicate entry warning

* Update lib/rocprofiler/agent.cpp

- improve read_map diagnostics

* Update lib/rocprofiler/agent.cpp

- avoid infinite loop in read_map

* Update lib/rocprofiler/agent.cpp

- handle empty kfd node properties file

* Update lib/rocprofiler/agent.cpp

- check for permissions to read a node properties file

* Update lib/rocprofiler/agent.cpp

- more checks on file readability

* Update lib/rocprofiler/tests/agent.cpp

- print virtual kfd topology

* Update lib/rocprofiler/tests/agent.cpp

- verify id.handle == hsa_agent internal node id

* Update lib/rocprofiler/tests/agent.cpp

- check node_id
- check location id
- check device id
- update abi test

* Update include/rocprofiler/agent.h

- add node_id field
- add reserved0 field to ensure new field increases struct size

* Update lib/rocprofiler/agent.cpp

- node_id instead of id.handle

* Update lib/rocprofiler/agent_cache.cpp

- node_id instead of id.handle

* Update samples/pc_sampling

- node_id for agent instead of id.handle

* Update lib/rocprofiler/buffer.cpp

- remove debug prints
This commit is contained in:
Jonathan R. Madsen
2023-10-19 19:04:02 -05:00
committed by GitHub
parent 87cc748c3d
commit 7f631de401
16 changed files with 434 additions and 167 deletions
+17 -75
View File
@@ -23,16 +23,13 @@
#include <glog/logging.h>
#include <filesystem>
#include <fstream>
#include <limits>
#include <optional>
#include <stdexcept>
#include "lib/common/synchronized.hpp"
#include "lib/common/utility.hpp"
// For Pre-ROCm 6.0 releases
#if ROCPROFILER_HSA_RUNTIME_VERSION <= 100900
# define HSA_AMD_AGENT_INFO_NEAREST_CPU 0xA113
#endif
namespace
{
// This function checks to see if the provided
@@ -118,7 +115,7 @@ init_gpu_pool(const AmdExtTable& api, rocprofiler::hsa::AgentCache& agent)
std::pair<const AmdExtTable*, hsa_amd_memory_pool_t*> params =
std::make_pair(&api, &agent.gpu_pool());
auto status =
api.hsa_amd_agent_iterate_memory_pools_fn(agent.get_agent(), FindStandardPool, &params);
api.hsa_amd_agent_iterate_memory_pools_fn(agent.get_hsa_agent(), FindStandardPool, &params);
if(status != HSA_STATUS_SUCCESS && status != HSA_STATUS_INFO_BREAK)
{
@@ -132,82 +129,27 @@ namespace rocprofiler
{
namespace hsa
{
AgentCache::AgentCache(rocprofiler_agent_t agent_t,
size_t index,
const ::CoreApiTable& table,
const AmdExtTable& ext)
: _agent_t(agent_t)
, _index(index)
, _name(agent_t.name)
AgentCache::AgentCache(const rocprofiler_agent_t* rocp_agent,
hsa_agent_t hsa_agent,
size_t index,
hsa_agent_t nearest_cpu,
const AmdExtTable& ext_table)
: m_rocp_agent{rocp_agent}
, m_index{index}
, m_hsa_agent{hsa_agent}
, m_nearest_cpu{nearest_cpu}
, m_name{rocp_agent->name}
{
// Get HSA Agents
std::vector<hsa_agent_t> agents;
table.hsa_iterate_agents_fn(
[](hsa_agent_t agent, void* data) {
CHECK_NOTNULL(static_cast<std::vector<hsa_agent_t>*>(data))->emplace_back(agent);
return HSA_STATUS_SUCCESS;
},
&agents);
// In case HSA_AMD_AGENT_INFO_NEAREST_CPU is non-functional, default to original v1 behavior
// of last CPU agent being nearest.
std::optional<hsa_agent_t> last_cpu;
bool found = false;
// Find the HSA agent that is represented by rocprofiler_agent_t
for(const auto& agent : agents)
{
hsa_device_type_t type = HSA_DEVICE_TYPE_CPU;
if(table.hsa_agent_get_info_fn(agent, HSA_AGENT_INFO_DEVICE, &type) != HSA_STATUS_SUCCESS)
{
throw std::runtime_error("hsa_agent_get_info failed to find device");
}
if(type != HSA_DEVICE_TYPE_GPU)
{
if(type == HSA_DEVICE_TYPE_CPU && !last_cpu) last_cpu = agent;
continue;
}
uint32_t node_id = 0;
if(table.hsa_agent_get_info_fn(
agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_DRIVER_NODE_ID), &node_id) !=
HSA_STATUS_SUCCESS)
{
throw std::runtime_error("hsa_agent_get_info failed to find driver id");
}
// Match rocprofiler_agent_t to hsa_agent for GPU agents
if(_index != node_id) continue;
if(table.hsa_agent_get_info_fn(
agent,
static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_NEAREST_CPU),
&_nearest_cpu) != HSA_STATUS_SUCCESS)
{
_nearest_cpu = last_cpu ? *last_cpu : hsa_agent_t{.handle = 0};
}
found = true;
_agent = agent;
}
if(!found)
{
throw std::runtime_error(fmt::format("Could not find GPU id = {}", agent_t.id.handle));
}
// Construct CPU/GPU pools
try
{
init_cpu_pool(ext, *this);
init_gpu_pool(ext, *this);
init_cpu_pool(ext_table, *this);
init_gpu_pool(ext_table, *this);
} catch(std::runtime_error& e)
{
LOG(WARNING) << fmt::format(
"Buffer creation for Agent {} failed ({}), Some profiling options will be unavialable.",
agent_t.id.handle,
"Buffer creation for Agent {} failed ({}), Some profiling options will be unavailable.",
rocp_agent->node_id,
e.what());
}
}