support for python apps profiling

This commit is contained in:
Evgeny
2019-05-16 12:09:37 -05:00
والد a52a9f3cd1
کامیت 0d7f600c7a
4فایلهای تغییر یافته به همراه36 افزوده شده و 22 حذف شده
+10 -4
مشاهده پرونده
@@ -1,9 +1,15 @@
#ifndef SRC_CORE_LOADER_H_
#define SRC_CORE_LOADER_H_
#include <atomic>
#include <mutex>
#include <dlfcn.h>
#define LOADER_INSTANTIATE() \
std::atomic<roctracer::HipLoader*> roctracer::HipLoader::instance_{}; \
std::atomic<roctracer::HccLoader*> roctracer::HccLoader::instance_{}; \
roctracer::Loader::mutex_t roctracer::Loader::mutex_;
namespace roctracer {
// Base runtime loader class
@@ -95,13 +101,13 @@ class HccLoader : protected Loader {
return *obj;
}
HccLoader() : Loader("libmcwamp.so") {
HccLoader() : Loader("libmcwamp_hsa.so") {
// Kalmar::CLAMP::InitActivityCallback
InitActivityCallback = GetFun<InitActivityCallback_t>("_ZN6Kalmar5CLAMP20InitActivityCallbackEPvS1_S1_");
InitActivityCallback = GetFun<InitActivityCallback_t>("InitActivityCallbackImpl");
// Kalmar::CLAMP::EnableActivityIdCallback
EnableActivityCallback = GetFun<EnableActivityCallback_t>("_ZN6Kalmar5CLAMP22EnableActivityCallbackEjb");
EnableActivityCallback = GetFun<EnableActivityCallback_t>("EnableActivityCallbackImpl");
// Kalmar::CLAMP::GetCmdName
GetCmdName = GetFun<GetCmdName_t>("_ZN6Kalmar5CLAMP10GetCmdNameEj");
GetCmdName = GetFun<GetCmdName_t>("GetCmdNameImpl");
}
InitActivityCallback_t* InitActivityCallback;
+2 -4
مشاهده پرونده
@@ -439,12 +439,10 @@ std::atomic<util::Logger*> util::Logger::instance_{};
MemoryPool* memory_pool = NULL;
typedef std::recursive_mutex memory_pool_mutex_t;
memory_pool_mutex_t memory_pool_mutex;
Loader::mutex_t Loader::mutex_;
std::atomic<HipLoader*> HipLoader::instance_{};
std::atomic<HccLoader*> HccLoader::instance_{};
}
LOADER_INSTANTIATE();
std::atomic<proxy::Tracker*> proxy::Tracker::instance_{};
proxy::Tracker::mutex_t proxy::Tracker::glob_mutex_;
proxy::Tracker::counter_t proxy::Tracker::counter_ = 0;
+5 -5
مشاهده پرونده
@@ -45,14 +45,14 @@ eval_test() {
# Standalone test
# rocTrecer is used explicitely by test
eval_test "standalone HIP test" "LD_PRELOAD=$HCC_HOME/lib/libmcwamp_hsa.so ./test/MatrixTranspose_test"
eval_test "standalone HIP test" ./test/MatrixTranspose_test
# Tool test
# rocTracer/tool is loaded by HSA runtime
export HSA_TOOLS_LIB="test/libtracer_tool.so libroctracer64.so"
export HSA_TOOLS_LIB="libroctracer64.so test/libtracer_tool.so"
# HIP test
eval_test "tool HIP test" "LD_PRELOAD='$HCC_HOME/lib/libmcwamp_hsa.so $HSA_TOOLS_LIB' ./test/MatrixTranspose"
eval_test "tool HIP test" ./test/MatrixTranspose
# HSA test
export ROCTRACER_DOMAIN="hsa"
@@ -69,11 +69,11 @@ export ROCP_AGENTS=1
# each thread creates a queue pre GPU agent
export ROCP_THRS=1
eval_test "tool HSA test" "LD_PRELOAD='$HSA_TOOLS_LIB' ./test/hsa/ctrl"
eval_test "tool HSA test" ./test/hsa/ctrl
echo "<trace name=\"HSA\"><parameters api=\"hsa_agent_get_info, hsa_amd_memory_pool_allocate\"></parameters></trace>" > input.xml
export ROCP_INPUT=input.xml
eval_test "tool HSA test input" "LD_PRELOAD='$HSA_TOOLS_LIB' ./test/hsa/ctrl"
eval_test "tool HSA test input" ./test/hsa/ctrl
#valgrind --leak-check=full $tbin
#valgrind --tool=massif $tbin
+19 -9
مشاهده پرونده
@@ -31,6 +31,7 @@ THE SOFTWARE.
#include <inc/roctracer_hip.h>
#include <inc/roctracer_hcc.h>
#include <inc/ext/hsa_rt_utils.hpp>
#include <src/core/loader.h>
#include <util/xml.h>
#define PUBLIC_API __attribute__((visibility("default")))
@@ -54,6 +55,8 @@ thread_local timestamp_t hip_begin_timestamp = 0;
bool trace_hsa = false;
bool trace_hip = false;
LOADER_INSTANTIATE();
// Global output file handle
FILE* hsa_api_file_handle = NULL;
FILE* hsa_async_copy_file_handle = NULL;
@@ -116,33 +119,40 @@ void hip_api_callback(
hsa_begin_timestamp = timer->timestamp_fn_ns();
} else {
const timestamp_t end_timestamp = timer->timestamp_fn_ns();
fprintf(hip_api_file_handle, "%lu:%lu %u:%u %s(", hsa_begin_timestamp, end_timestamp, GetPid(), GetTid(), roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, cid, 0));
std::ostringstream oss; \
oss << std::dec <<
hsa_begin_timestamp << ":" << end_timestamp << " " << GetPid() << ":" << GetTid() << " " << roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, cid, 0); \
switch (cid) {
case HIP_API_ID_hipMemcpy:
fprintf(hip_api_file_handle, "dst(%p) src(%p) size(0x%x) kind(%u)",
fprintf(hip_api_file_handle, "%s(dst(%p) src(%p) size(0x%x) kind(%u))",
oss.str().c_str(),
data->args.hipMemcpy.dst,
data->args.hipMemcpy.src,
(uint32_t)(data->args.hipMemcpy.sizeBytes),
(uint32_t)(data->args.hipMemcpy.kind));
break;
case HIP_API_ID_hipMalloc:
fprintf(hip_api_file_handle, "ptr(0x%p) size(0x%x)",
fprintf(hip_api_file_handle, "%s(ptr(0x%p) size(0x%x))",
oss.str().c_str(),
*(data->args.hipMalloc.ptr),
(uint32_t)(data->args.hipMalloc.size));
break;
case HIP_API_ID_hipFree:
fprintf(hip_api_file_handle, "ptr(%p)",
fprintf(hip_api_file_handle, "%s(ptr(%p))",
oss.str().c_str(),
data->args.hipFree.ptr);
break;
case HIP_API_ID_hipModuleLaunchKernel:
fprintf(hip_api_file_handle, "kernel(%s) stream(%p)",
hipKernelNameRef(data->args.hipModuleLaunchKernel.f),
fprintf(hip_api_file_handle, "%s(kernel(%s) stream(%p))",
oss.str().c_str(),
roctracer::HipLoader::Instance().KernelNameRef(data->args.hipModuleLaunchKernel.f),
data->args.hipModuleLaunchKernel.stream);
break;
default:
break;
}
fprintf(hip_api_file_handle, ")\n"); fflush(hip_api_file_handle);
fflush(hip_api_file_handle);
}
}
@@ -305,7 +315,7 @@ extern "C" PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version,
NULL};
roctracer_set_properties(ACTIVITY_DOMAIN_HSA_OPS, &ops_properties);
printf(" HSA-trace(");
fprintf(stdout, " HSA-trace("); fflush(stdout);
if (hsa_api_vec.size() != 0) {
for (unsigned i = 0; i < hsa_api_vec.size(); ++i) {
uint32_t cid = HSA_API_ID_NUMBER;
@@ -326,7 +336,7 @@ extern "C" PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version,
hip_api_file_handle = open_output_file(output_prefix, "hip_api_trace.txt");
hcc_activity_file_handle = open_output_file(output_prefix, "hcc_ops_trace.txt");
printf(" HIP-trace()\n");
fprintf(stdout, " HIP-trace()\n"); fflush(stdout);
// Allocating tracing pool
roctracer_properties_t properties{};
properties.buffer_size = 0x1000;