From a6bf221881edac70e253557b47f46abcc4d48219 Mon Sep 17 00:00:00 2001 From: chenjian Date: Thu, 31 Mar 2022 15:12:52 +0800 Subject: [PATCH] Maintain old profiler (#41132) * no * maintain old profiler * exclude new python record events for old profiler * maintain old profiler * maintain * maintain old profiler * maintain * fix cmakes --- paddle/fluid/framework/operator.cc | 4 ++- paddle/fluid/platform/CMakeLists.txt | 6 ++-- paddle/fluid/platform/profiler.cc | 42 +++++++++++++++++++++------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index dbf94613f3..cf2a36cde1 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -59,6 +59,7 @@ DECLARE_bool(benchmark); DECLARE_bool(check_nan_inf); DECLARE_bool(enable_unused_var_check); DECLARE_bool(run_kp_kernel); +DECLARE_bool(enable_host_event_recorder_hook); namespace paddle { namespace framework { @@ -264,7 +265,8 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) { Type(), platform::TracerEventType::Operator, 1); auto op_name = platform::OpName(outputs_, Type()); platform::RecordEvent op_name_record_event( - op_name, platform::TracerEventType::Operator, 10, + op_name, platform::TracerEventType::Operator, + FLAGS_enable_host_event_recorder_hook ? 20 : 1, platform::EventRole::kUniqueOp); RunImpl(scope, place); } diff --git a/paddle/fluid/platform/CMakeLists.txt b/paddle/fluid/platform/CMakeLists.txt index de09860fd2..46059100b3 100644 --- a/paddle/fluid/platform/CMakeLists.txt +++ b/paddle/fluid/platform/CMakeLists.txt @@ -192,13 +192,13 @@ add_subdirectory(profiler) cc_library(device_tracer SRCS device_tracer.cc DEPS boost profiler_proto framework_proto ${GPU_CTX_DEPS}) if(WITH_GPU) - nv_library(profiler SRCS profiler.cc profiler.cu DEPS os_info device_tracer gpu_info enforce dynload_cuda) + nv_library(profiler SRCS profiler.cc profiler.cu DEPS os_info device_tracer gpu_info enforce dynload_cuda new_profiler) nv_library(device_memory_aligment SRCS device_memory_aligment.cc DEPS cpu_info gpu_info place) elseif(WITH_ROCM) - hip_library(profiler SRCS profiler.cc profiler.cu DEPS os_info device_tracer gpu_info enforce) + hip_library(profiler SRCS profiler.cc profiler.cu DEPS os_info device_tracer gpu_info enforce new_profiler) hip_library(device_memory_aligment SRCS device_memory_aligment.cc DEPS cpu_info gpu_info place) else() - cc_library(profiler SRCS profiler.cc DEPS os_info device_tracer enforce) + cc_library(profiler SRCS profiler.cc DEPS os_info device_tracer enforce new_profiler) cc_library(device_memory_aligment SRCS device_memory_aligment.cc DEPS cpu_info place) endif() diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 5cd909b4e0..8fa48ffcfb 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -24,6 +24,7 @@ limitations under the License. */ #include "paddle/fluid/platform/profiler/common_event.h" #include "paddle/fluid/platform/profiler/host_event_recorder.h" #include "paddle/fluid/platform/profiler/host_tracer.h" +#include "paddle/fluid/platform/profiler/profiler.h" #include "paddle/fluid/platform/profiler_helper.h" #ifdef PADDLE_WITH_CUDA #include "paddle/fluid/platform/dynload/nvtx.h" @@ -76,15 +77,21 @@ RecordEvent::RecordEvent(const char *name, const TracerEventType type, } #endif #endif + if (UNLIKELY(HostTraceLevel::GetInstance().NeedTrace(level) == false)) { + return; + } + if (FLAGS_enable_host_event_recorder_hook == false) { if (g_state != ProfilerState::kDisabled) { // avoid temp string - OriginalConstruct(name, role, "none"); + if (type == TracerEventType::Operator || + type == TracerEventType::OperatorInner || + type == TracerEventType::UserDefined) { + OriginalConstruct(name, role, "none"); + } } return; } - if (UNLIKELY(HostTraceLevel::GetInstance().NeedTrace(level) == false)) { - return; - } + is_enabled_ = true; shallow_copy_name_ = name; role_ = role; @@ -102,13 +109,19 @@ RecordEvent::RecordEvent(const std::string &name, const TracerEventType type, } #endif #endif - if (FLAGS_enable_host_event_recorder_hook == false) { - OriginalConstruct(name, role, "none"); + if (UNLIKELY(HostTraceLevel::GetInstance().NeedTrace(level) == false)) { return; } - if (UNLIKELY(HostTraceLevel::GetInstance().NeedTrace(level) == false)) { + + if (FLAGS_enable_host_event_recorder_hook == false) { + if (type == TracerEventType::Operator || + type == TracerEventType::OperatorInner || + type == TracerEventType::UserDefined) { + OriginalConstruct(name, role, "none"); + } return; } + is_enabled_ = true; name_ = new std::string(name); role_ = role; @@ -127,13 +140,20 @@ RecordEvent::RecordEvent(const std::string &name, const std::string &attr, } #endif #endif - if (FLAGS_enable_host_event_recorder_hook == false) { - OriginalConstruct(name, role, attr); + + if (UNLIKELY(HostTraceLevel::GetInstance().NeedTrace(level) == false)) { return; } - if (UNLIKELY(HostTraceLevel::GetInstance().NeedTrace(level) == false)) { + + if (FLAGS_enable_host_event_recorder_hook == false) { + if (type == TracerEventType::Operator || + type == TracerEventType::OperatorInner || + type == TracerEventType::UserDefined) { + OriginalConstruct(name, role, attr); + } return; } + is_enabled_ = true; type_ = type; name_ = new std::string(name); @@ -333,6 +353,8 @@ void EnableProfiler(ProfilerState state) { return; } g_state = state; + ProfilerOptions option; + HostTraceLevel::GetInstance().SetLevel(option.trace_level); should_send_profile_state = true; GetDeviceTracer()->Enable(); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) -- GitLab