未验证 提交 8476c552 编写于 作者: Y YuanRisheng 提交者: GitHub

[PHI Decoupling]Remove Profiler header (Part3) (#50721)

* move profiler

* fix compile bugs
上级 22925c21
...@@ -38,10 +38,6 @@ PADDLE_DEFINE_EXPORTED_bool(enable_rpc_profiler, ...@@ -38,10 +38,6 @@ PADDLE_DEFINE_EXPORTED_bool(enable_rpc_profiler,
false, false,
"Enable rpc profiler or not."); "Enable rpc profiler or not.");
DEFINE_bool(enable_record_op_info,
false,
"enable operator supplement info recorder");
DEFINE_bool(enable_record_memory, false, "enable memory recorder"); DEFINE_bool(enable_record_memory, false, "enable memory recorder");
namespace paddle { namespace paddle {
...@@ -110,25 +106,6 @@ RecordOpInfoSupplement::RecordOpInfoSupplement( ...@@ -110,25 +106,6 @@ RecordOpInfoSupplement::RecordOpInfoSupplement(
PosixInNsec(), type, input_shapes, dtypes, attrs, op_id); PosixInNsec(), type, input_shapes, dtypes, attrs, op_id);
} }
RecordOpInfoSupplement::RecordOpInfoSupplement(
const std::string &type,
const std::vector<std::pair<const char *, std::vector<framework::DDim>>>
&input_shapes,
const framework::AttributeMap &attrs) {
if (FLAGS_enable_host_event_recorder_hook == false) {
return;
}
if (IsEnabled() == false) {
return;
}
std::map<std::string, std::vector<framework::proto::VarType::Type>> dtypes;
uint64_t op_id = 0;
HostEventRecorder<OperatorSupplementOriginEvent>::GetInstance().RecordEvent(
PosixInNsec(), type, input_shapes, dtypes, attrs, op_id);
}
bool RecordOpInfoSupplement::IsEnabled() { return FLAGS_enable_record_op_info; }
bool RecordMemEvent::IsEnabled() { return FLAGS_enable_record_memory; } bool RecordMemEvent::IsEnabled() { return FLAGS_enable_record_memory; }
std::map<const char *, std::map<uint64_t, std::vector<uint64_t>>> std::map<const char *, std::map<uint64_t, std::vector<uint64_t>>>
...@@ -873,10 +850,6 @@ void DisableHostEventRecorder() { ...@@ -873,10 +850,6 @@ void DisableHostEventRecorder() {
FLAGS_enable_host_event_recorder_hook = false; FLAGS_enable_host_event_recorder_hook = false;
} }
void EnableOpInfoRecorder() { FLAGS_enable_record_op_info = true; }
void DisableOpInfoRecorder() { FLAGS_enable_record_op_info = false; }
void EnableMemoryRecorder() { FLAGS_enable_record_memory = true; } void EnableMemoryRecorder() { FLAGS_enable_record_memory = true; }
void DisableMemoryRecorder() { FLAGS_enable_record_memory = false; } void DisableMemoryRecorder() { FLAGS_enable_record_memory = false; }
......
...@@ -214,9 +214,6 @@ void DisableHostEventRecorder(); ...@@ -214,9 +214,6 @@ void DisableHostEventRecorder();
void EnableMemoryRecorder(); void EnableMemoryRecorder();
void DisableMemoryRecorder(); void DisableMemoryRecorder();
void EnableOpInfoRecorder();
void DisableOpInfoRecorder();
// Defined for UT // Defined for UT
std::string PrintHostEvents(); std::string PrintHostEvents();
......
...@@ -50,27 +50,7 @@ struct OperatorSupplementOriginEvent { ...@@ -50,27 +50,7 @@ struct OperatorSupplementOriginEvent {
strncpy(buf, type_name.c_str(), type_name.length() + 1); strncpy(buf, type_name.c_str(), type_name.length() + 1);
op_type = buf; op_type = buf;
} }
OperatorSupplementOriginEvent(
std::function<void *(size_t)> arena_allocator,
uint64_t timestamp_ns,
const std::string &type_name,
const std::vector<std::pair<const char *, std::vector<framework::DDim>>>
&shapes,
const std::map<std::string, std::vector<framework::proto::VarType::Type>>
&dtypes,
const framework::AttributeMap &attributes,
uint64_t op_id)
: timestamp_ns(timestamp_ns),
dtypes(dtypes),
attributes(attributes),
op_id(op_id) {
auto buf = static_cast<char *>(arena_allocator(type_name.length() + 1));
strncpy(buf, type_name.c_str(), type_name.length() + 1);
op_type = buf;
for (auto it = shapes.begin(); it != shapes.end(); it++) {
input_shapes[std::string((*it).first)] = (*it).second;
}
}
uint64_t timestamp_ns; uint64_t timestamp_ns;
const char *op_type = nullptr; // not owned, designed for performance const char *op_type = nullptr; // not owned, designed for performance
// input shapes // input shapes
......
...@@ -21,6 +21,7 @@ limitations under the License. */ ...@@ -21,6 +21,7 @@ limitations under the License. */
#include "paddle/fluid/framework/shape_inference.h" #include "paddle/fluid/framework/shape_inference.h"
#include "paddle/fluid/framework/type_defs.h" #include "paddle/fluid/framework/type_defs.h"
#include "paddle/fluid/platform/profiler/trace_event.h" #include "paddle/fluid/platform/profiler/trace_event.h"
#include "paddle/phi/api/profiler/supplement_tracing.h"
#include "paddle/phi/core/compat/arg_map_context.h" #include "paddle/phi/core/compat/arg_map_context.h"
namespace paddle { namespace paddle {
...@@ -30,10 +31,8 @@ class RuntimeContext; ...@@ -30,10 +31,8 @@ class RuntimeContext;
} }
namespace platform { namespace platform {
class RecordOpInfoSupplement { class RecordOpInfoSupplement : public phi::RecordOpInfoSupplement {
public: public:
static bool IsEnabled();
/** /**
* @param type: Operator type name. * @param type: Operator type name.
* @param attrs: Attribute map of op. * @param attrs: Attribute map of op.
...@@ -55,15 +54,6 @@ class RecordOpInfoSupplement { ...@@ -55,15 +54,6 @@ class RecordOpInfoSupplement {
const framework::AttributeMap& attrs, const framework::AttributeMap& attrs,
const framework::InferShapeContext& shape_ctx, const framework::InferShapeContext& shape_ctx,
const phi::KernelSignature& kernel_signature); const phi::KernelSignature& kernel_signature);
/**
*
*/
explicit RecordOpInfoSupplement(
const std::string& type,
const std::vector<std::pair<const char*, std::vector<framework::DDim>>>&
input_shapes,
const framework::AttributeMap& attrs);
}; };
} // namespace platform } // namespace platform
......
...@@ -2453,8 +2453,8 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -2453,8 +2453,8 @@ All parameter, weight, gradient are variables in Paddle.
m.def("load_profiler_result", &paddle::platform::LoadProfilerResult); m.def("load_profiler_result", &paddle::platform::LoadProfilerResult);
m.def("enable_memory_recorder", &paddle::platform::EnableMemoryRecorder); m.def("enable_memory_recorder", &paddle::platform::EnableMemoryRecorder);
m.def("disable_memory_recorder", &paddle::platform::DisableMemoryRecorder); m.def("disable_memory_recorder", &paddle::platform::DisableMemoryRecorder);
m.def("enable_op_info_recorder", &paddle::platform::EnableOpInfoRecorder); m.def("enable_op_info_recorder", &phi::EnableOpInfoRecorder);
m.def("disable_op_info_recorder", &paddle::platform::DisableOpInfoRecorder); m.def("disable_op_info_recorder", &phi::DisableOpInfoRecorder);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
m.def("set_cublas_switch", platform::SetAllowTF32Cublas); m.def("set_cublas_switch", platform::SetAllowTF32Cublas);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "paddle/phi/api/profiler/event.h" // import EventRole, TODO(TIEXING): remove later #include "paddle/phi/api/profiler/event.h" // import EventRole, TODO(TIEXING): remove later
#include "paddle/phi/api/profiler/trace_event.h" #include "paddle/phi/api/profiler/trace_event.h"
#include "paddle/phi/core/attribute.h"
#include "paddle/phi/core/ddim.h" #include "paddle/phi/core/ddim.h"
namespace phi { namespace phi {
...@@ -104,4 +105,31 @@ struct CommonMemEvent { ...@@ -104,4 +105,31 @@ struct CommonMemEvent {
uint64_t peak_reserved; uint64_t peak_reserved;
}; };
struct OperatorSupplementOriginEvent {
public:
OperatorSupplementOriginEvent(
std::function<void *(size_t)> arena_allocator,
uint64_t timestamp_ns,
const std::string &type_name,
const std::vector<std::pair<const char *, std::vector<DDim>>> &shapes,
const AttributeMap &attributes,
uint64_t op_id)
: timestamp_ns(timestamp_ns), attributes(attributes), op_id(op_id) {
auto buf = static_cast<char *>(arena_allocator(type_name.length() + 1));
strncpy(buf, type_name.c_str(), type_name.length() + 1);
op_type = buf;
for (auto it = shapes.begin(); it != shapes.end(); it++) {
input_shapes[std::string((*it).first)] = (*it).second;
}
}
uint64_t timestamp_ns;
const char *op_type = nullptr; // not owned, designed for performance
// input shapes
std::map<std::string, std::vector<DDim>> input_shapes;
// op attributes
AttributeMap attributes;
// op id
uint64_t op_id;
};
} // namespace phi } // namespace phi
...@@ -35,6 +35,10 @@ DEFINE_bool(enable_host_event_recorder_hook, ...@@ -35,6 +35,10 @@ DEFINE_bool(enable_host_event_recorder_hook,
false, false,
"enable HostEventRecorder, hook Profiler"); "enable HostEventRecorder, hook Profiler");
DEFINE_bool(enable_record_op_info,
false,
"enable operator supplement info recorder");
namespace phi { namespace phi {
ProfilerState ProfilerHelper::g_state = ProfilerState::kDisabled; ProfilerState ProfilerHelper::g_state = ProfilerState::kDisabled;
...@@ -265,4 +269,25 @@ bool RecordEvent::IsEnabled() { ...@@ -265,4 +269,25 @@ bool RecordEvent::IsEnabled() {
ProfilerHelper::g_state != ProfilerState::kDisabled; ProfilerHelper::g_state != ProfilerState::kDisabled;
} }
RecordOpInfoSupplement::RecordOpInfoSupplement(
const std::string &type,
const std::vector<std::pair<const char *, std::vector<DDim>>> &input_shapes,
const AttributeMap &attrs) {
if (FLAGS_enable_host_event_recorder_hook == false) {
return;
}
if (IsEnabled() == false) {
return;
}
uint64_t op_id = 0;
HostEventRecorder<OperatorSupplementOriginEvent>::GetInstance().RecordEvent(
PosixInNsec(), type, input_shapes, attrs, op_id);
}
bool RecordOpInfoSupplement::IsEnabled() { return FLAGS_enable_record_op_info; }
void EnableOpInfoRecorder() { FLAGS_enable_record_op_info = true; }
void DisableOpInfoRecorder() { FLAGS_enable_record_op_info = false; }
} // namespace phi } // namespace phi
...@@ -26,6 +26,7 @@ limitations under the License. */ ...@@ -26,6 +26,7 @@ limitations under the License. */
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "paddle/phi/api/profiler/event_tracing.h" #include "paddle/phi/api/profiler/event_tracing.h"
#include "paddle/phi/api/profiler/supplement_tracing.h"
DECLARE_bool(enable_host_event_recorder_hook); DECLARE_bool(enable_host_event_recorder_hook);
...@@ -88,4 +89,7 @@ void PopEvent(const std::string& name, ...@@ -88,4 +89,7 @@ void PopEvent(const std::string& name,
const EventRole role, const EventRole role,
const std::string attr = "none"); const std::string attr = "none");
void EnableOpInfoRecorder();
void DisableOpInfoRecorder();
} // namespace phi } // namespace phi
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <map>
#include <string>
#include <utility>
#include "paddle/phi/core/attribute.h"
#include "paddle/phi/core/ddim.h"
namespace phi {
class RecordOpInfoSupplement {
public:
static bool IsEnabled();
RecordOpInfoSupplement() = default;
explicit RecordOpInfoSupplement(
const std::string& type,
const std::vector<std::pair<const char*, std::vector<DDim>>>&
input_shapes,
const AttributeMap& attrs);
};
} // namespace phi
...@@ -886,7 +886,7 @@ PADDLE_API {self.get_return_type(inplace_flag=True)} {api_func_name}({self.get_d ...@@ -886,7 +886,7 @@ PADDLE_API {self.get_return_type(inplace_flag=True)} {api_func_name}({self.get_d
input_tensor_code = ( input_tensor_code = (
input_tensor_code input_tensor_code
+ f""" + f"""
{code_indent} if(platform::RecordOpInfoSupplement::IsEnabled()){{""" {code_indent} if(phi::RecordOpInfoSupplement::IsEnabled()){{"""
) )
single_tensor_names = [] single_tensor_names = []
list_tensor_names = [] list_tensor_names = []
...@@ -1030,7 +1030,7 @@ PADDLE_API {self.get_return_type(inplace_flag=True)} {api_func_name}({self.get_d ...@@ -1030,7 +1030,7 @@ PADDLE_API {self.get_return_type(inplace_flag=True)} {api_func_name}({self.get_d
) )
input_tensor_code += f""" input_tensor_code += f"""
{code_indent} framework::AttributeMap attrs;""" {code_indent} phi::AttributeMap attrs;"""
for attr_name in self.attrs['names']: for attr_name in self.attrs['names']:
if 'IntArray' in self.attrs['attr_info'][attr_name][0]: if 'IntArray' in self.attrs['attr_info'][attr_name][0]:
...@@ -1096,7 +1096,7 @@ PADDLE_API {self.get_return_type(inplace_flag=True)} {api_func_name}({self.get_d ...@@ -1096,7 +1096,7 @@ PADDLE_API {self.get_return_type(inplace_flag=True)} {api_func_name}({self.get_d
input_tensor_code = ( input_tensor_code = (
input_tensor_code input_tensor_code
+ f""" + f"""
{code_indent} platform::RecordOpInfoSupplement("{self.api}", input_shapes, attrs); {code_indent} phi::RecordOpInfoSupplement("{self.api}", input_shapes, attrs);
{code_indent} }}""" {code_indent} }}"""
) )
kernel_args = ["*dev_ctx"] kernel_args = ["*dev_ctx"]
......
...@@ -344,7 +344,7 @@ def source_include(header_file_path): ...@@ -344,7 +344,7 @@ def source_include(header_file_path):
#include "paddle/phi/infermeta/ternary.h" #include "paddle/phi/infermeta/ternary.h"
#include "paddle/phi/api/profiler/event_tracing.h" #include "paddle/phi/api/profiler/event_tracing.h"
#include "paddle/fluid/platform/profiler/supplement_tracing.h" #include "paddle/phi/api/profiler/supplement_tracing.h"
DECLARE_bool(conv2d_disable_cudnn); DECLARE_bool(conv2d_disable_cudnn);
DECLARE_int32(low_precision_op_list); DECLARE_int32(low_precision_op_list);
......
...@@ -287,7 +287,7 @@ def source_include(header_file_path): ...@@ -287,7 +287,7 @@ def source_include(header_file_path):
#include "paddle/phi/infermeta/unary.h" #include "paddle/phi/infermeta/unary.h"
#include "paddle/phi/api/profiler/event_tracing.h" #include "paddle/phi/api/profiler/event_tracing.h"
#include "paddle/fluid/platform/profiler/supplement_tracing.h" #include "paddle/phi/api/profiler/supplement_tracing.h"
DECLARE_bool(conv2d_disable_cudnn); DECLARE_bool(conv2d_disable_cudnn);
DECLARE_int32(low_precision_op_list); DECLARE_int32(low_precision_op_list);
......
...@@ -53,7 +53,7 @@ def source_include(header_file_path): ...@@ -53,7 +53,7 @@ def source_include(header_file_path):
#include "paddle/phi/infermeta/sparse/multiary.h" #include "paddle/phi/infermeta/sparse/multiary.h"
#include "paddle/phi/api/profiler/event_tracing.h" #include "paddle/phi/api/profiler/event_tracing.h"
#include "paddle/fluid/platform/profiler/supplement_tracing.h" #include "paddle/phi/api/profiler/supplement_tracing.h"
DECLARE_int32(low_precision_op_list); DECLARE_int32(low_precision_op_list);
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册