Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix RecordEvent interface #39675

Merged
merged 7 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions paddle/fluid/platform/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ double Event::CudaElapsedMs(const Event &e) const {
#endif
}

RecordEvent::RecordEvent(const char *name, const EventRole role,
uint32_t level) {
RecordEvent::RecordEvent(const char *name, const TracerEventType type,
uint32_t level, const EventRole role) {
#ifndef _WIN32
#ifdef PADDLE_WITH_CUDA
if (g_enable_nvprof_hook) {
Expand All @@ -86,11 +86,12 @@ RecordEvent::RecordEvent(const char *name, const EventRole role,
is_enabled_ = true;
shallow_copy_name_ = name;
role_ = role;
type_ = type;
start_ns_ = PosixInNsec();
}

RecordEvent::RecordEvent(const std::string &name, const EventRole role,
uint32_t level) {
RecordEvent::RecordEvent(const std::string &name, const TracerEventType type,
uint32_t level, const EventRole role) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default level低一点

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改

#ifndef _WIN32
#ifdef PADDLE_WITH_CUDA
if (g_enable_nvprof_hook) {
Expand All @@ -109,11 +110,13 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role,
is_enabled_ = true;
name_ = new std::string(name);
role_ = role;
type_ = type;
start_ns_ = PosixInNsec();
}

RecordEvent::RecordEvent(const std::string &name, const EventRole role,
const std::string &attr, uint32_t level) {
RecordEvent::RecordEvent(const std::string &name, const std::string &attr,
const TracerEventType type, uint32_t level,
const EventRole role) {
#ifndef _WIN32
#ifdef PADDLE_WITH_CUDA
if (g_enable_nvprof_hook) {
Expand All @@ -130,6 +133,7 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role,
return;
}
is_enabled_ = true;
type_ = type;
name_ = new std::string(name);
start_ns_ = PosixInNsec();
attr_ = new std::string(attr);
Expand Down Expand Up @@ -164,17 +168,15 @@ void RecordEvent::End() {
uint64_t end_ns = PosixInNsec();
if (LIKELY(FLAGS_enable_host_event_recorder_hook && is_enabled_)) {
if (LIKELY(shallow_copy_name_ != nullptr)) {
HostEventRecorder::GetInstance().RecordEvent(shallow_copy_name_,
start_ns_, end_ns, role_,
TracerEventType::NumTypes);
HostEventRecorder::GetInstance().RecordEvent(
shallow_copy_name_, start_ns_, end_ns, role_, type_);
} else if (name_ != nullptr) {
if (attr_ == nullptr) {
HostEventRecorder::GetInstance().RecordEvent(
*name_, start_ns_, end_ns, role_, TracerEventType::NumTypes);
HostEventRecorder::GetInstance().RecordEvent(*name_, start_ns_, end_ns,
role_, type_);
} else {
HostEventRecorder::GetInstance().RecordEvent(
*name_, start_ns_, end_ns, role_, TracerEventType::NumTypes,
*attr_);
HostEventRecorder::GetInstance().RecordEvent(*name_, start_ns_, end_ns,
role_, type_, *attr_);
delete attr_;
}
delete name_;
Expand Down Expand Up @@ -301,7 +303,7 @@ void PopMemEvent(uint64_t start_ns, uint64_t end_ns, size_t bytes,
void Mark(const std::string &name) {
if (FLAGS_enable_host_event_recorder_hook) {
HostEventRecorder::GetInstance().RecordEvent(
name, 0, 0, EventRole::kOrdinary, TracerEventType::NumTypes);
name, 0, 0, EventRole::kOrdinary, TracerEventType::UserDefined);
return;
}
GetEventList().Record(EventType::kMark, name, g_thread_id);
Expand Down
20 changes: 12 additions & 8 deletions paddle/fluid/platform/profiler/event_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ struct RecordInstantEvent {
// Chrome Trace Viewer Format: Duration Event/Complte Event
class RecordEvent {
public:
explicit RecordEvent(const std::string& name,
const EventRole role = EventRole::kOrdinary,
uint32_t level = 1);
explicit RecordEvent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改接口会导致部分使用EventRole的case无法编译,需要修改这些

const std::string& name,
const TracerEventType type = TracerEventType::UserDefined,
uint32_t level = 4, const EventRole role = EventRole::kOrdinary);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把默认level 4定义一个const常量,这样用户需要设置后面的默认参数而不想改level时可以用这个

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改


explicit RecordEvent(const char* name,
const EventRole role = EventRole::kOrdinary,
uint32_t level = 1);
explicit RecordEvent(
const char* name,
const TracerEventType type = TracerEventType::UserDefined,
uint32_t level = 4, const EventRole role = EventRole::kOrdinary);

RecordEvent(const std::string& name, const EventRole role,
const std::string& attr, uint32_t level = 1);
RecordEvent(const std::string& name, const std::string& attr,
const TracerEventType type = TracerEventType::UserDefined,
uint32_t level = 4, const EventRole role = EventRole::kOrdinary);

// Stop event tracing explicitly before the object goes out of scope.
// Sometimes it's inconvenient to use RAII
Expand All @@ -65,6 +68,7 @@ class RecordEvent {
// different kernel invocations within an op.
// std::string full_name_;
EventRole role_{EventRole::kOrdinary};
TracerEventType type_{TracerEventType::UserDefined};
std::string* attr_{nullptr};
bool finished_{false};
};
Expand Down
12 changes: 12 additions & 0 deletions paddle/fluid/platform/profiler/trace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ enum class TracerEventType {
Memset = 6,
// Used to mark record defined by user
UserDefined = 7,
// Used to mark operator detail, (such as infer shape, compute)
OperatorInner = 8,
// Used to mark model training or testing perspective, forward process
Forward = 9,
// Used to mark model training perspective, backward process
Backward = 10,
// Used to mark model training perspective, optimization process
Optimization = 11,
// Used to mark distributed training perspective
Communication = 12,
// Used to mark python api
PythonOp = 13,
// A flag to denote the number of current types
NumTypes
};
Expand Down