diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index dbf94613f3de6c92933482c1c04713a21f35f428..cf2a36cde1f1f68bf33a29b142611a08d95aec33 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 de09860fd26d54894a7917502c4ac569dd5fdd4a..46059100b3802a7f17b83bada6578636f2369d13 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 5cd909b4e08f0d1be01b39846f56616e0d307605..8fa48ffcfb15853c503a4d9af88315a1346a467b 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)