several fixes; adding direct loading of alprofile library
[ROCm/rocprofiler commit: 8270530fec]
This commit is contained in:
@@ -55,12 +55,14 @@ class InterceptQueue {
|
||||
|
||||
ProxyQueue* proxy = ProxyQueue::Create(agent, size, type, callback, data, private_segment_size,
|
||||
group_segment_size, queue, &status);
|
||||
if (status != HSA_STATUS_SUCCESS) {
|
||||
if (status == HSA_STATUS_SUCCESS) {
|
||||
InterceptQueue* obj = new InterceptQueue(agent, proxy);
|
||||
(*obj_map_)[(uint64_t)(*queue)] = obj;
|
||||
status = proxy->SetInterceptCB(OnSubmitCB, obj);
|
||||
}
|
||||
|
||||
if (status != HSA_STATUS_SUCCESS) abort();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -97,7 +99,7 @@ class InterceptQueue {
|
||||
dispatch_packet->kernel_object,
|
||||
GetKernelName(dispatch_packet)};
|
||||
hsa_status_t status = on_dispatch_cb_(&data, on_dispatch_cb_data_, &group);
|
||||
if (status == HSA_STATUS_SUCCESS) {
|
||||
if ((status == HSA_STATUS_SUCCESS) && (group.context != NULL)) {
|
||||
Context* context = reinterpret_cast<Context*>(group.context);
|
||||
const pkt_vector_t& start_vector = context->StartPackets(group.index);
|
||||
const pkt_vector_t& stop_vector = context->StopPackets(group.index);
|
||||
|
||||
@@ -110,13 +110,18 @@ class MetricsDict {
|
||||
MetricsDict(const util::AgentInfo* agent_info) : xml_(NULL) {
|
||||
const char* xml_name = getenv("ROCP_METRICS");
|
||||
if (xml_name != NULL) {
|
||||
xml_ = new xml::Xml(xml_name);
|
||||
xml_ = xml::Xml::Create(xml_name);
|
||||
if (xml_ == NULL) EXC_RAISING(HSA_STATUS_ERROR, "metrics .xml open error '" << xml_name << "'");
|
||||
std::cout << "ROCProfiler: importing metrics from '" << xml_name << "':" << std::endl;
|
||||
ImportMetrics(agent_info, agent_info->gfxip);
|
||||
ImportMetrics(agent_info, "global");
|
||||
}
|
||||
}
|
||||
|
||||
~MetricsDict() {
|
||||
xml::Xml::Destroy(xml_);
|
||||
}
|
||||
|
||||
void ImportMetrics(const util::AgentInfo* agent_info, const char* scope) {
|
||||
auto scope_list = xml_->GetNodes("top." + std::string(scope) + ".metric");
|
||||
if (!scope_list.empty()) {
|
||||
|
||||
@@ -24,7 +24,7 @@ ProxyQueue* ProxyQueue::Create(hsa_agent_t agent, uint32_t size, hsa_queue_type3
|
||||
ProxyQueue* instance = new SimpleProxyQueue();
|
||||
#endif
|
||||
if (instance != NULL) {
|
||||
const auto suc = instance->Init(agent, size, type, callback, data, private_segment_size,
|
||||
suc = instance->Init(agent, size, type, callback, data, private_segment_size,
|
||||
group_segment_size, queue);
|
||||
if (suc != HSA_STATUS_SUCCESS) {
|
||||
delete instance;
|
||||
@@ -32,10 +32,12 @@ ProxyQueue* ProxyQueue::Create(hsa_agent_t agent, uint32_t size, hsa_queue_type3
|
||||
}
|
||||
}
|
||||
*status = suc;
|
||||
assert(*status == HSA_STATUS_SUCCESS);
|
||||
return instance;
|
||||
}
|
||||
|
||||
hsa_status_t ProxyQueue::Destroy(const ProxyQueue* obj) {
|
||||
assert(obj != NULL);
|
||||
auto suc = obj->Cleanup();
|
||||
delete obj;
|
||||
return suc;
|
||||
|
||||
@@ -7,5 +7,5 @@ void SimpleProxyQueue::HsaIntercept(HsaApiTable* table) {
|
||||
table->core_->hsa_queue_store_write_index_relaxed_fn = rocprofiler::SimpleProxyQueue::StoreIndex;
|
||||
}
|
||||
|
||||
std::map<signal_handle_t, SimpleProxyQueue*> SimpleProxyQueue::queue_map_;
|
||||
SimpleProxyQueue::queue_map_t* SimpleProxyQueue::queue_map_ = NULL;
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -24,8 +24,8 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
static void HsaIntercept(HsaApiTable* table);
|
||||
|
||||
static void SignalStore(hsa_signal_t signal, hsa_signal_value_t que_idx) {
|
||||
auto it = queue_map_.find(signal.handle);
|
||||
if (it != queue_map_.end()) {
|
||||
auto it = queue_map_->find(signal.handle);
|
||||
if (it != queue_map_->end()) {
|
||||
SimpleProxyQueue* instance = it->second;
|
||||
const uint64_t begin = instance->submit_index_;
|
||||
const uint64_t end = que_idx + 1;
|
||||
@@ -46,8 +46,8 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
|
||||
static uint64_t LoadIndex(const hsa_queue_t* queue) {
|
||||
uint64_t index = 0;
|
||||
auto it = queue_map_.find(queue->doorbell_signal.handle);
|
||||
if (it != queue_map_.end()) {
|
||||
auto it = queue_map_->find(queue->doorbell_signal.handle);
|
||||
if (it != queue_map_->end()) {
|
||||
SimpleProxyQueue* instance = it->second;
|
||||
instance->mutex_.lock();
|
||||
index = instance->queue_index_;
|
||||
@@ -58,8 +58,8 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
}
|
||||
|
||||
static void StoreIndex(const hsa_queue_t* queue, uint64_t value) {
|
||||
auto it = queue_map_.find(queue->doorbell_signal.handle);
|
||||
if (it != queue_map_.end()) {
|
||||
auto it = queue_map_->find(queue->doorbell_signal.handle);
|
||||
if (it != queue_map_->end()) {
|
||||
SimpleProxyQueue* instance = it->second;
|
||||
instance->queue_index_ = value;
|
||||
instance->mutex_.unlock();
|
||||
@@ -115,6 +115,8 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
~SimpleProxyQueue() {}
|
||||
|
||||
private:
|
||||
typedef std::map<signal_handle_t, SimpleProxyQueue*> queue_map_t;
|
||||
|
||||
hsa_status_t Init(hsa_agent_t agent, uint32_t size, hsa_queue_type32_t type,
|
||||
void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data),
|
||||
void* data, uint32_t private_segment_size, uint32_t group_segment_size,
|
||||
@@ -129,6 +131,7 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
agent_info_ = util::HsaRsrcFactory::Instance().GetAgentInfo(agent);
|
||||
if (agent_info_ != NULL) {
|
||||
if (agent_info_->dev_type == HSA_DEVICE_TYPE_GPU) {
|
||||
printf("queue_create size 0x%x(%d)\n", size, (int)size);
|
||||
status = hsa_queue_create_fn(agent, size, HSA_QUEUE_TYPE_MULTI, NULL, NULL, UINT32_MAX,
|
||||
UINT32_MAX, &queue_);
|
||||
if (status == HSA_STATUS_SUCCESS) {
|
||||
@@ -138,11 +141,16 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
uintptr_t addr = (uintptr_t)data_array_;
|
||||
queue_->base_address = (void*)((addr + align_mask_) & ~align_mask_);
|
||||
status = hsa_signal_create(1, 0, NULL, &(queue_->doorbell_signal));
|
||||
if (status != HSA_STATUS_SUCCESS) abort();
|
||||
queue_mask_ = size - 1;
|
||||
queue_map_[queue_->doorbell_signal.handle] = this;
|
||||
|
||||
if (queue_map_ == NULL) queue_map_ = new queue_map_t;
|
||||
(*queue_map_)[queue_->doorbell_signal.handle] = this;
|
||||
}
|
||||
else abort();
|
||||
}
|
||||
}
|
||||
if (status != HSA_STATUS_SUCCESS) abort();
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -155,7 +163,7 @@ class SimpleProxyQueue : public ProxyQueue {
|
||||
return status;
|
||||
}
|
||||
|
||||
static std::map<signal_handle_t, SimpleProxyQueue*> queue_map_;
|
||||
static queue_map_t* queue_map_;
|
||||
const util::AgentInfo* agent_info_;
|
||||
hsa_queue_t* queue_;
|
||||
static const uintptr_t align_mask_ = sizeof(packet_t) - 1;
|
||||
|
||||
@@ -24,6 +24,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "util/hsa_rsrc_factory.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <hsa.h>
|
||||
#include <hsa_ext_finalize.h>
|
||||
#include <stdint.h>
|
||||
@@ -85,7 +86,10 @@ HsaRsrcFactory::HsaRsrcFactory() {
|
||||
// Get AqlProfile API table
|
||||
aqlprofile_api_ = {0};
|
||||
status = hsa_system_get_extension_table(HSA_EXTENSION_AMD_AQLPROFILE, 1, 0, &aqlprofile_api_);
|
||||
CHECK_STATUS("aqlprofile API table query failed", status);
|
||||
#ifdef ROCP_LOAD_AQLPROF
|
||||
if (status != HSA_STATUS_SUCCESS) status = LoadAqlProfileLib(&aqlprofile_api_);
|
||||
#endif
|
||||
CHECK_STATUS("aqlprofile API table load failed", status);
|
||||
|
||||
// Get Loader API table
|
||||
loader_api_ = {0};
|
||||
@@ -99,6 +103,39 @@ HsaRsrcFactory::~HsaRsrcFactory() {
|
||||
CHECK_STATUS("Error in hsa_shut_down", status);
|
||||
}
|
||||
|
||||
hsa_status_t HsaRsrcFactory::LoadAqlProfileLib(aqlprofile_pfn_t* api) {
|
||||
void* handle = dlopen(kAqlProfileLib, RTLD_NOW);
|
||||
if (handle == NULL) {
|
||||
fprintf(stderr, "Loading '%s' failed, %s\n", kAqlProfileLib, dlerror());
|
||||
return HSA_STATUS_ERROR;
|
||||
}
|
||||
dlerror(); /* Clear any existing error */
|
||||
|
||||
api->hsa_ven_amd_aqlprofile_error_string =
|
||||
(decltype(::hsa_ven_amd_aqlprofile_error_string)*)
|
||||
dlsym(handle, "hsa_ven_amd_aqlprofile_error_string");
|
||||
api->hsa_ven_amd_aqlprofile_validate_event =
|
||||
(decltype(::hsa_ven_amd_aqlprofile_validate_event)*)
|
||||
dlsym(handle, "hsa_ven_amd_aqlprofile_validate_event");
|
||||
api->hsa_ven_amd_aqlprofile_start =
|
||||
(decltype(::hsa_ven_amd_aqlprofile_start)*)
|
||||
dlsym(handle, "hsa_ven_amd_aqlprofile_start");
|
||||
api->hsa_ven_amd_aqlprofile_stop =
|
||||
(decltype(::hsa_ven_amd_aqlprofile_stop)*)
|
||||
dlsym(handle, "hsa_ven_amd_aqlprofile_stop");
|
||||
api->hsa_ven_amd_aqlprofile_legacy_get_pm4 =
|
||||
(decltype(::hsa_ven_amd_aqlprofile_legacy_get_pm4)*)
|
||||
dlsym(handle, "hsa_ven_amd_aqlprofile_legacy_get_pm4");
|
||||
api->hsa_ven_amd_aqlprofile_get_info =
|
||||
(decltype(::hsa_ven_amd_aqlprofile_get_info)*)
|
||||
dlsym(handle, "hsa_ven_amd_aqlprofile_get_info");
|
||||
api->hsa_ven_amd_aqlprofile_iterate_data =
|
||||
(decltype(::hsa_ven_amd_aqlprofile_iterate_data)*)
|
||||
dlsym(handle, "hsa_ven_amd_aqlprofile_iterate_data");
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Add system agent info
|
||||
const AgentInfo* HsaRsrcFactory::AddAgentInfo(const hsa_agent_t agent) {
|
||||
// Determine if device is a Gpu agent
|
||||
|
||||
@@ -222,7 +222,8 @@ class HsaRsrcFactory {
|
||||
bool PrintGpuAgents(const std::string& header);
|
||||
|
||||
// Return AqlProfile API table
|
||||
const hsa_ven_amd_aqlprofile_1_00_pfn_t* AqlProfileApi() const { return &aqlprofile_api_; }
|
||||
typedef hsa_ven_amd_aqlprofile_1_00_pfn_t aqlprofile_pfn_t;
|
||||
const aqlprofile_pfn_t* AqlProfileApi() const { return &aqlprofile_api_; }
|
||||
|
||||
// Return Loader API table
|
||||
const hsa_ven_amd_loader_1_00_pfn_t* LoaderApi() const { return &loader_api_; }
|
||||
@@ -234,6 +235,9 @@ class HsaRsrcFactory {
|
||||
// Callback function to find and bind kernarg region of an agent
|
||||
static hsa_status_t FindMemRegionsCallback(hsa_region_t region, void* data);
|
||||
|
||||
// Load AQL profile HSA extension library directly
|
||||
static hsa_status_t LoadAqlProfileLib(aqlprofile_pfn_t* api);
|
||||
|
||||
// Constructor of the class. Will initialize the Hsa Runtime and
|
||||
// query the system topology to get the list of Cpu and Gpu devices
|
||||
HsaRsrcFactory();
|
||||
@@ -257,7 +261,7 @@ class HsaRsrcFactory {
|
||||
std::map<hsa_agent_handle_t, const AgentInfo*> agent_map_;
|
||||
|
||||
// AqlProfile API table
|
||||
hsa_ven_amd_aqlprofile_1_00_pfn_t aqlprofile_api_;
|
||||
aqlprofile_pfn_t aqlprofile_api_;
|
||||
|
||||
// Loader API table
|
||||
hsa_ven_amd_loader_1_00_pfn_t loader_api_;
|
||||
|
||||
@@ -27,6 +27,33 @@ class Xml {
|
||||
|
||||
enum { DECL_STATE, BODY_STATE };
|
||||
|
||||
static Xml* Create(const char* file_name) {
|
||||
Xml* xml = new Xml(file_name);
|
||||
if (xml->fd_ == -1) {
|
||||
delete xml;
|
||||
xml = NULL;
|
||||
}
|
||||
return xml;
|
||||
}
|
||||
|
||||
static void Destroy(Xml *xml) { delete xml; }
|
||||
|
||||
std::vector<level_t*> GetNodes(std::string global_tag) { return map_[global_tag]; }
|
||||
|
||||
void Print() const {
|
||||
for (auto& elem : map_) {
|
||||
for (auto node : elem.second) {
|
||||
if (node->opts.size()) {
|
||||
std::cout << elem.first << ":" << std::endl;
|
||||
for (auto& opt : node->opts) {
|
||||
std::cout << " " << opt.first << " = " << opt.second << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Xml(const char* file_name)
|
||||
: file_name_(file_name),
|
||||
file_line_(0),
|
||||
@@ -39,7 +66,7 @@ class Xml {
|
||||
|
||||
fd_ = open(file_name, O_RDONLY);
|
||||
if (fd_ == -1) {
|
||||
std::cout << "XML file not found: " << file_name << std::endl;
|
||||
perror("open XML file");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -117,22 +144,8 @@ class Xml {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<level_t*> GetNodes(std::string global_tag) { return map_[global_tag]; }
|
||||
~Xml() {}
|
||||
|
||||
void Print() const {
|
||||
for (auto& elem : map_) {
|
||||
for (auto node : elem.second) {
|
||||
if (node->opts.size()) {
|
||||
std::cout << elem.first << ":" << std::endl;
|
||||
for (auto& opt : node->opts) {
|
||||
std::cout << " " << opt.first << " = " << opt.second << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool LineEndCheck() {
|
||||
bool found = false;
|
||||
if (buffer_[index_] == '\n') {
|
||||
|
||||
Viittaa uudesa ongelmassa
Block a user