From 67200eb670afdf027c9f9cd7e3eec18247f5bcb6 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 10 May 2018 17:37:54 -0500 Subject: [PATCH] revertingROCP_HSA_INTERCEPT env var Change-Id: I1bf41f5773d194ac409056271a15b61366cc6292 [ROCm/rocprofiler commit: ee77feb18661008cad16b3b6b4eabe14aeb04b05] --- projects/rocprofiler/src/core/rocprofiler.cpp | 40 +++++++++++-------- projects/rocprofiler/src/core/tracker.h | 2 +- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/projects/rocprofiler/src/core/rocprofiler.cpp b/projects/rocprofiler/src/core/rocprofiler.cpp index 9d43ee3284..3f3679289b 100644 --- a/projects/rocprofiler/src/core/rocprofiler.cpp +++ b/projects/rocprofiler/src/core/rocprofiler.cpp @@ -95,8 +95,10 @@ void RestoreHsaApi() { typedef void (*tool_handler_t)(); typedef void (*tool_handler_prop_t)(rocprofiler_settings_t*); -void * kTtoolHandle = NULL; +void * tool_handle = NULL; +// Load profiling tool library +// Return true if intercepting mode is enabled bool LoadTool() { bool intercept_mode = false; const char* tool_lib = getenv("ROCP_TOOL_LIB"); @@ -104,20 +106,20 @@ bool LoadTool() { if (tool_lib) { intercept_mode = true; - kTtoolHandle = dlopen(tool_lib, RTLD_NOW); - if (kTtoolHandle == NULL) { + tool_handle = dlopen(tool_lib, RTLD_NOW); + if (tool_handle == NULL) { fprintf(stderr, "ROCProfiler: can't load tool library \"%s\"\n", tool_lib); fprintf(stderr, "%s\n", dlerror()); abort(); } - tool_handler_t handler = reinterpret_cast(dlsym(kTtoolHandle, "OnLoadTool")); - tool_handler_prop_t handler_prop = reinterpret_cast(dlsym(kTtoolHandle, "OnLoadToolProp")); + tool_handler_t handler = reinterpret_cast(dlsym(tool_handle, "OnLoadTool")); + tool_handler_prop_t handler_prop = reinterpret_cast(dlsym(tool_handle, "OnLoadToolProp")); if ((handler == NULL) && (handler_prop == NULL)) { fprintf(stderr, "ROCProfiler: tool library corrupted, OnLoadTool()/OnLoadToolProp() method is expected\n"); fprintf(stderr, "%s\n", dlerror()); abort(); } - tool_handler_t on_unload_handler = reinterpret_cast(dlsym(kTtoolHandle, "OnUnloadTool")); + tool_handler_t on_unload_handler = reinterpret_cast(dlsym(tool_handle, "OnUnloadTool")); if (on_unload_handler == NULL) { fprintf(stderr, "ROCProfiler: tool library corrupted, OnUnloadTool() method is expected\n"); fprintf(stderr, "%s\n", dlerror()); @@ -145,16 +147,17 @@ bool LoadTool() { return intercept_mode; } +// Unload profiling tool librray void UnloadTool() { - if (kTtoolHandle) { - tool_handler_t handler = reinterpret_cast(dlsym(kTtoolHandle, "OnUnloadTool")); + if (tool_handle) { + tool_handler_t handler = reinterpret_cast(dlsym(tool_handle, "OnUnloadTool")); if (handler == NULL) { fprintf(stderr, "ROCProfiler error: tool library corrupted, OnUnloadTool() method is expected\n"); fprintf(stderr, "%s\n", dlerror()); abort(); } handler(); - dlclose(kTtoolHandle); + dlclose(tool_handle); } } @@ -168,12 +171,6 @@ DESTRUCTOR_API void destructor() { util::Logger::Destroy(); } -hsa_status_t GetExcStatus(const std::exception& e) { - const util::exception* rocprofiler_exc_ptr = dynamic_cast(&e); - return (rocprofiler_exc_ptr) ? static_cast(rocprofiler_exc_ptr->status()) - : HSA_STATUS_ERROR; -} - const MetricsDict* GetMetrics(const hsa_agent_t& agent) { rocprofiler::util::HsaRsrcFactory* hsa_rsrc = &rocprofiler::util::HsaRsrcFactory::Instance(); const rocprofiler::util::AgentInfo* agent_info = hsa_rsrc->GetAgentInfo(agent); @@ -185,6 +182,12 @@ const MetricsDict* GetMetrics(const hsa_agent_t& agent) { return metrics; } +hsa_status_t GetExcStatus(const std::exception& e) { + const util::exception* rocprofiler_exc_ptr = dynamic_cast(&e); + return (rocprofiler_exc_ptr) ? static_cast(rocprofiler_exc_ptr->status()) + : HSA_STATUS_ERROR; +} + rocprofiler_properties_t rocprofiler_properties; uint64_t Context::timeout_ = UINT64_MAX; uint32_t SqttProfile::output_buffer_size_ = 0x2000000; // 32M @@ -204,7 +207,12 @@ PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t fa const char* const* failed_tool_names) { rocprofiler::SaveHsaApi(table); rocprofiler::ProxyQueue::InitFactory(); - const bool intercept_mode = rocprofiler::LoadTool(); + bool intercept_mode = false; + const char* intercept_env = getenv("ROCP_HSA_INTERCEPT"); + if (intercept_env != NULL) { + if (strncmp(intercept_env, "1", 1) == 0) intercept_mode = true; + } + if (rocprofiler::LoadTool()) intercept_mode = true; // HSA intercepting if (intercept_mode) { rocprofiler::ProxyQueue::HsaIntercept(table); diff --git a/projects/rocprofiler/src/core/tracker.h b/projects/rocprofiler/src/core/tracker.h index 651dcd42ff..5627b8ea56 100644 --- a/projects/rocprofiler/src/core/tracker.h +++ b/projects/rocprofiler/src/core/tracker.h @@ -147,7 +147,7 @@ class Tracker { return (timestamp_t)timestamp_ns; } - // Timestamp frequency + // Timestamp frequency factor freq_t timestamp_factor_; // Timeout for wait on destruction timestamp_t timeout_;