Skip to content

Commit

Permalink
Maintain old profiler (#41132)
Browse files Browse the repository at this point in the history
* no

* maintain old profiler

* exclude new python record events for old profiler

* maintain old profiler

* maintain

* maintain old profiler

* maintain

* fix cmakes
  • Loading branch information
rainyfly authored Mar 31, 2022
1 parent 7ef6920 commit a6bf221
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
4 changes: 3 additions & 1 deletion paddle/fluid/framework/operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
42 changes: 32 additions & 10 deletions paddle/fluid/platform/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a6bf221

Please sign in to comment.