未验证 提交 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,
false,
"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");
namespace paddle {
......@@ -110,25 +106,6 @@ RecordOpInfoSupplement::RecordOpInfoSupplement(
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; }
std::map<const char *, std::map<uint64_t, std::vector<uint64_t>>>
......@@ -873,10 +850,6 @@ void DisableHostEventRecorder() {
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 DisableMemoryRecorder() { FLAGS_enable_record_memory = false; }
......
......@@ -214,9 +214,6 @@ void DisableHostEventRecorder();
void EnableMemoryRecorder();
void DisableMemoryRecorder();
void EnableOpInfoRecorder();
void DisableOpInfoRecorder();
// Defined for UT
std::string PrintHostEvents();
......
......@@ -50,27 +50,7 @@ struct OperatorSupplementOriginEvent {
strncpy(buf, type_name.c_str(), type_name.length() + 1);
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;
const char *op_type = nullptr; // not owned, designed for performance
// input shapes
......
......@@ -21,6 +21,7 @@ limitations under the License. */
#include "paddle/fluid/framework/shape_inference.h"
#include "paddle/fluid/framework/type_defs.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"
namespace paddle {
......@@ -30,10 +31,8 @@ class RuntimeContext;
}
namespace platform {
class RecordOpInfoSupplement {
class RecordOpInfoSupplement : public phi::RecordOpInfoSupplement {
public:
static bool IsEnabled();
/**
* @param type: Operator type name.
* @param attrs: Attribute map of op.
......@@ -55,15 +54,6 @@ class RecordOpInfoSupplement {
const framework::AttributeMap& attrs,
const framework::InferShapeContext& shape_ctx,
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
......
......@@ -2453,8 +2453,8 @@ All parameter, weight, gradient are variables in Paddle.
m.def("load_profiler_result", &paddle::platform::LoadProfilerResult);
m.def("enable_memory_recorder", &paddle::platform::EnableMemoryRecorder);
m.def("disable_memory_recorder", &paddle::platform::DisableMemoryRecorder);
m.def("enable_op_info_recorder", &paddle::platform::EnableOpInfoRecorder);
m.def("disable_op_info_recorder", &paddle::platform::DisableOpInfoRecorder);
m.def("enable_op_info_recorder", &phi::EnableOpInfoRecorder);
m.def("disable_op_info_recorder", &phi::DisableOpInfoRecorder);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
m.def("set_cublas_switch", platform::SetAllowTF32Cublas);
......
......@@ -20,6 +20,7 @@
#include "paddle/phi/api/profiler/event.h" // import EventRole, TODO(TIEXING): remove later
#include "paddle/phi/api/profiler/trace_event.h"
#include "paddle/phi/core/attribute.h"
#include "paddle/phi/core/ddim.h"
namespace phi {
......@@ -104,4 +105,31 @@ struct CommonMemEvent {
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
......@@ -35,6 +35,10 @@ DEFINE_bool(enable_host_event_recorder_hook,
false,
"enable HostEventRecorder, hook Profiler");
DEFINE_bool(enable_record_op_info,
false,
"enable operator supplement info recorder");
namespace phi {
ProfilerState ProfilerHelper::g_state = ProfilerState::kDisabled;
......@@ -265,4 +269,25 @@ bool RecordEvent::IsEnabled() {
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
......@@ -26,6 +26,7 @@ limitations under the License. */
#include "gflags/gflags.h"
#include "paddle/phi/api/profiler/event_tracing.h"
#include "paddle/phi/api/profiler/supplement_tracing.h"
DECLARE_bool(enable_host_event_recorder_hook);
......@@ -88,4 +89,7 @@ void PopEvent(const std::string& name,
const EventRole role,
const std::string attr = "none");
void EnableOpInfoRecorder();
void DisableOpInfoRecorder();
} // 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
input_tensor_code = (
input_tensor_code
+ f"""
{code_indent} if(platform::RecordOpInfoSupplement::IsEnabled()){{"""
{code_indent} if(phi::RecordOpInfoSupplement::IsEnabled()){{"""
)
single_tensor_names = []
list_tensor_names = []
......@@ -1030,7 +1030,7 @@ PADDLE_API {self.get_return_type(inplace_flag=True)} {api_func_name}({self.get_d
)
input_tensor_code += f"""
{code_indent} framework::AttributeMap attrs;"""
{code_indent} phi::AttributeMap attrs;"""
for attr_name in self.attrs['names']:
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
input_tensor_code = (
input_tensor_code
+ f"""
{code_indent} platform::RecordOpInfoSupplement("{self.api}", input_shapes, attrs);
{code_indent} phi::RecordOpInfoSupplement("{self.api}", input_shapes, attrs);
{code_indent} }}"""
)
kernel_args = ["*dev_ctx"]
......
......@@ -344,7 +344,7 @@ def source_include(header_file_path):
#include "paddle/phi/infermeta/ternary.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_int32(low_precision_op_list);
......
......@@ -287,7 +287,7 @@ def source_include(header_file_path):
#include "paddle/phi/infermeta/unary.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_int32(low_precision_op_list);
......
......@@ -53,7 +53,7 @@ def source_include(header_file_path):
#include "paddle/phi/infermeta/sparse/multiary.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);
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册