From 6960dcd77eecd23d2bc7342a7fbaea0bff2c19a9 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 7 Feb 2018 09:41:17 -0600 Subject: [PATCH] adding major and minor library versions [ROCm/rocprofiler commit: 6560364df1d039a536679f36360bad81da04f233] --- projects/rocprofiler/inc/rocprofiler.h | 16 +++- projects/rocprofiler/src/core/context.h | 1 + projects/rocprofiler/src/core/metrics.h | 6 +- projects/rocprofiler/src/core/rocprofiler.cpp | 88 ++++++++++++------- projects/rocprofiler/src/util/logger.h | 2 + projects/rocprofiler/test/CMakeLists.txt | 1 + projects/rocprofiler/test/ctrl/tool.cpp | 10 +++ projects/rocprofiler/test/input.xml | 3 +- projects/rocprofiler/test/metrics.xml | 33 +++---- 9 files changed, 107 insertions(+), 53 deletions(-) diff --git a/projects/rocprofiler/inc/rocprofiler.h b/projects/rocprofiler/inc/rocprofiler.h index 600b68dab7..b28e3e8dfb 100644 --- a/projects/rocprofiler/inc/rocprofiler.h +++ b/projects/rocprofiler/inc/rocprofiler.h @@ -66,10 +66,19 @@ #include #include +#define ROCPROFILER_VERSION_MAJOR 1 +#define ROCPROFILER_VERSION_MINOR 0 + #ifdef __cplusplus extern "C" { #endif // __cplusplus +//////////////////////////////////////////////////////////////////////////////// +// Returning library version + +uint32_t rocprofiler_version_major(); +uint32_t rocprofiler_version_minor(); + //////////////////////////////////////////////////////////////////////////////// // Returning the error string method @@ -305,6 +314,7 @@ typedef union { // Profiling info data typedef struct { + uint32_t agent_idx; rocprofiler_info_kind_t kind; // info data kind union { struct { @@ -327,20 +337,20 @@ typedef struct { // Return the info for a given info kind hsa_status_t rocprofiler_get_info( - hsa_agent_t agent, // GFXIP handle + const hsa_agent_t* agent, // [in] GFXIP handle rocprofiler_info_kind_t kind, // kind of iterated info void *data); // [in/out] returned data // Iterate over the info for a given info kind, and invoke an application-defined callback on every iteration hsa_status_t rocprofiler_iterate_info( - hsa_agent_t agent, // GFXIP handle + const hsa_agent_t* agent, // [in] GFXIP handle rocprofiler_info_kind_t kind, // kind of iterated info hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback void *data); // [in/out] data passed to callback // Iterate over the info for a given info query, and invoke an application-defined callback on every iteration hsa_status_t rocprofiler_query_info( - hsa_agent_t agent, // GFXIP handle + const hsa_agent_t *agent, // [in] GFXIP handle rocprofiler_info_query_t query, // iterated info query hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback void *data); // [in/out] data passed to callback diff --git a/projects/rocprofiler/src/core/context.h b/projects/rocprofiler/src/core/context.h index 1ad4761baf..ee0a420df5 100644 --- a/projects/rocprofiler/src/core/context.h +++ b/projects/rocprofiler/src/core/context.h @@ -190,6 +190,7 @@ class Context { // Register input features to not duplicate by features referencing for (unsigned i = 0; i < info_count; ++i) { rocprofiler_feature_t* info = &info_array[i]; + if (!info->name) EXC_RAISING(HSA_STATUS_ERROR, "input feature name is NULL"); info_map_[info->name] = info; } diff --git a/projects/rocprofiler/src/core/metrics.h b/projects/rocprofiler/src/core/metrics.h index e53b9e090e..0ea0ed8140 100644 --- a/projects/rocprofiler/src/core/metrics.h +++ b/projects/rocprofiler/src/core/metrics.h @@ -199,8 +199,10 @@ class MetricsDict { for (unsigned block_index = 0; block_index < query.instance_count; ++block_index) { std::ostringstream full_name; full_name << name << '[' << block_index << ']'; + std::ostringstream block_insance; + block_insance << block_name << "[" << block_index << "]"; std::ostringstream alias; - alias << block_name << "[" << block_index << "]:" << event_str; + alias << block_insance.str() << ":" << event_str; const counter_t counter = {full_name.str(), {block_id, block_index, event_id}}; AddMetric(full_name.str(), alias.str(), counter); } @@ -211,8 +213,10 @@ class MetricsDict { } } else { xml::Expr* expr_obj = new xml::Expr(expr_str, new ExprCache(&cache_)); +#if 0 std::cout << "# " << descr << std::endl; std::cout << name << "=" << expr_obj->String() << "\n" << std::endl; +#endif counters_vec_t counters_vec; for (const std::string var : expr_obj->GetVars()) { auto it = cache_.find(var); diff --git a/projects/rocprofiler/src/core/rocprofiler.cpp b/projects/rocprofiler/src/core/rocprofiler.cpp index 0a627e4826..2349c93585 100644 --- a/projects/rocprofiler/src/core/rocprofiler.cpp +++ b/projects/rocprofiler/src/core/rocprofiler.cpp @@ -153,6 +153,10 @@ PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t fa // HSA-runtime tool on-unload method PUBLIC_API void OnUnload() { rocprofiler::RestoreHsaApi(); } +// Returns library vesrion +PUBLIC_API uint32_t rocprofiler_version_major() { return ROCPROFILER_VERSION_MAJOR; } +PUBLIC_API uint32_t rocprofiler_version_minor() { return ROCPROFILER_VERSION_MINOR; } + // Returns the last error message PUBLIC_API hsa_status_t rocprofiler_error_string(const char** str) { API_METHOD_PREFIX @@ -320,16 +324,17 @@ PUBLIC_API hsa_status_t rocprofiler_iterate_trace_data( // Return the info for a given info kind PUBLIC_API hsa_status_t rocprofiler_get_info( - hsa_agent_t agent, + const hsa_agent_t *agent, rocprofiler_info_kind_t kind, void *data) { API_METHOD_PREFIX + if (agent == NULL) EXC_RAISING(HSA_STATUS_ERROR, "NULL agent"); uint32_t* result_32bit_ptr = reinterpret_cast(data); switch (kind) { case ROCPROFILER_INFO_KIND_METRIC_COUNT: - *result_32bit_ptr = rocprofiler::GetMetrics(agent)->Size(); + *result_32bit_ptr = rocprofiler::GetMetrics(*agent)->Size(); break; case ROCPROFILER_INFO_KIND_TRACE_COUNT: *result_32bit_ptr = 1; @@ -342,44 +347,63 @@ PUBLIC_API hsa_status_t rocprofiler_get_info( // Iterate over the info for a given info kind, and invoke an application-defined callback on every iteration PUBLIC_API hsa_status_t rocprofiler_iterate_info( - hsa_agent_t agent, + const hsa_agent_t* agent, rocprofiler_info_kind_t kind, - hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), - void *data) + hsa_status_t (*callback)(const rocprofiler_info_data_t info, void* data), + void* data) { API_METHOD_PREFIX + rocprofiler::util::HsaRsrcFactory* hsa_rsrc = &rocprofiler::util::HsaRsrcFactory::Instance(); rocprofiler_info_data_t info{}; info.kind = kind; + uint32_t agent_idx = 0; + uint32_t agent_max = 0; + const rocprofiler::util::AgentInfo* agent_info = NULL; - switch (kind) { - case ROCPROFILER_INFO_KIND_METRIC: - { - const rocprofiler::MetricsDict* dict = rocprofiler::GetMetrics(agent); - rocprofiler::MetricsDict::const_iterator_t it = dict->Begin(); - rocprofiler::MetricsDict::const_iterator_t end = dict->End(); - while (it != end) { - const rocprofiler::Metric* metric = it->second; - std::string name = metric->GetName(); - const auto* expr = metric->GetExpr(); - std::string description = "Performance metric " + name + " " + ((expr == NULL) ? "basic" : "= " + expr->String()); - info.metric.name = strdup(name.c_str()); - info.metric.description = strdup(description.c_str()); - status = callback(info, data); + if (agent != NULL) { + agent_info = hsa_rsrc->GetAgentInfo(*agent); + agent_idx = agent_info->dev_index; + agent_max = agent_idx + 1; + } - ++it; + while (hsa_rsrc->GetGpuAgentInfo(agent_idx, &agent_info)) { + info.agent_idx = agent_idx; + + switch (kind) { + case ROCPROFILER_INFO_KIND_METRIC: + { + const rocprofiler::MetricsDict* dict = rocprofiler::GetMetrics(agent_info->dev_id); + rocprofiler::MetricsDict::const_iterator_t it = dict->Begin(); + rocprofiler::MetricsDict::const_iterator_t end = dict->End(); + while (it != end) { + const rocprofiler::Metric* metric = it->second; + std::string name = metric->GetName(); + //std::string descr = metric->GetDescr(); + const auto* expr = metric->GetExpr(); + std::string description = "Performance metric " + name + " " + ((expr == NULL) ? "basic" : "= " + expr->String()); + info.metric.name = strdup(name.c_str()); + info.metric.description = strdup(description.c_str()); + status = callback(info, data); + if (status != HSA_STATUS_SUCCESS) break; + ++it; + } + break; } - break; + case ROCPROFILER_INFO_KIND_TRACE: + { + info.trace.name = strdup("TT"); + info.trace.description = strdup("Thread Trace"); + info.trace.parameter_count = 5; + status = callback(info, data); + if (status != HSA_STATUS_SUCCESS) break; + break; + } + default: + EXC_RAISING(HSA_STATUS_ERROR, "unknown info kind(" << kind << ")"); } - case ROCPROFILER_INFO_KIND_TRACE: - { - info.trace.name = strdup("TT"); - info.trace.description = strdup("Thread Trace"); - info.trace.parameter_count = 5; - status = callback(info, data); - break; - } - default: - EXC_RAISING(HSA_STATUS_ERROR, "unknown info kind(" << kind << ")"); + + ++agent_idx; + if (agent_idx == agent_max) break; } if (status == HSA_STATUS_INFO_BREAK) status = HSA_STATUS_SUCCESS; @@ -390,7 +414,7 @@ PUBLIC_API hsa_status_t rocprofiler_iterate_info( // Iterate over the info for a given info query, and invoke an application-defined callback on every iteration PUBLIC_API hsa_status_t rocprofiler_query_info( - hsa_agent_t agent, + const hsa_agent_t *agent, rocprofiler_info_query_t query, hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), void *data) diff --git a/projects/rocprofiler/src/util/logger.h b/projects/rocprofiler/src/util/logger.h index 812fcc68d1..eb21abc779 100644 --- a/projects/rocprofiler/src/util/logger.h +++ b/projects/rocprofiler/src/util/logger.h @@ -91,6 +91,8 @@ class Logger { std::lock_guard lck(mutex_); if (messaging) { message_[GetTid()] = ""; + } else if (streaming_) { + Put("\n"); } messaging_ = messaging; streaming_ = messaging; diff --git a/projects/rocprofiler/test/CMakeLists.txt b/projects/rocprofiler/test/CMakeLists.txt index 495a92a06b..ed6e7adbf8 100644 --- a/projects/rocprofiler/test/CMakeLists.txt +++ b/projects/rocprofiler/test/CMakeLists.txt @@ -30,6 +30,7 @@ target_include_directories ( ${EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ${HSA_R target_link_libraries( ${EXE_NAME} ${ROCPROFILER_TARGET} ${HSA_RUNTIME_LIB} c stdc++ dl pthread rt atomic ) execute_process ( COMMAND sh -xc "cp ${TEST_DIR}/run.sh ${PROJECT_BINARY_DIR}" ) execute_process ( COMMAND sh -xc "cp ${TEST_DIR}/*.xml ${PROJECT_BINARY_DIR}" ) +execute_process ( COMMAND sh -xc "mkdir -p ${PROJECT_BINARY_DIR}/RESULTS" ) ## Build test library set ( TEST_LIB "tool" ) diff --git a/projects/rocprofiler/test/ctrl/tool.cpp b/projects/rocprofiler/test/ctrl/tool.cpp index d372f13ae0..e438b1660c 100644 --- a/projects/rocprofiler/test/ctrl/tool.cpp +++ b/projects/rocprofiler/test/ctrl/tool.cpp @@ -322,6 +322,11 @@ hsa_status_t dispatch_callback(const rocprofiler_callback_data_t* callback_data, return status; } +static hsa_status_t info_callback(const rocprofiler_info_data_t info, void * arg) { + printf(" gpu-agent%d.%s : %s\n", info.agent_idx, info.metric.name, info.metric.description); + return HSA_STATUS_SUCCESS; +} + // Tool constructor CONSTRUCTOR_API void constructor() { @@ -337,6 +342,11 @@ CONSTRUCTOR_API void constructor() parameters_dict["HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_TOKEN_MASK2"] = HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_TOKEN_MASK2; + if (getenv("ROCP_INFO") != NULL) { + rocprofiler_iterate_info(NULL, ROCPROFILER_INFO_KIND_METRIC, info_callback, NULL); + return; + } + // Set output file result_prefix = getenv("ROCP_OUTPUT_DIR"); if (result_prefix != NULL) { diff --git a/projects/rocprofiler/test/input.xml b/projects/rocprofiler/test/input.xml index 2d4924c277..92c2f29caa 100644 --- a/projects/rocprofiler/test/input.xml +++ b/projects/rocprofiler/test/input.xml @@ -1,4 +1,5 @@ - + - - - - + + @@ -83,10 +81,8 @@ - - - - + + @@ -95,11 +91,16 @@ - - - - - + + + + + + + + + + @@ -127,7 +128,7 @@ # GPU_BUSY, percentage # The percentage of time GPU was busy. @@ -169,7 +170,7 @@ # VWriteInsts The average number of vector write instructions to the video memory executed per work-item (affected by flow control). Excludes FLAT instructions that write to video memory. @@ -219,7 +220,7 @@ # SALUBusy The percentage of GPUTime scalar ALU instructions are processed. Value range: 0% (bad) to 100% (optimal).