未验证 提交 d9acc87e 编写于 作者: P pangyoki 提交者: GitHub

add profile record (infer_shape, compute) for dygraph (#39023)

* add profile record for dygraph

* add op type in record

* fix little bug

* solve conflict
上级 eb45bb4e
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "paddle/fluid/platform/device/xpu/xpu_op_list.h" #include "paddle/fluid/platform/device/xpu/xpu_op_list.h"
#endif #endif
#include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h"
#include "paddle/fluid/platform/profiler.h"
DECLARE_bool(check_nan_inf); DECLARE_bool(check_nan_inf);
DECLARE_bool(run_pten_kernel); DECLARE_bool(run_pten_kernel);
...@@ -505,12 +506,21 @@ static void PreparedOpRunImpl( ...@@ -505,12 +506,21 @@ static void PreparedOpRunImpl(
// TODO(zjl): remove scope in dygraph // TODO(zjl): remove scope in dygraph
framework::Scope scope; framework::Scope scope;
DygraphInferShapeContext<VarType> infer_shape_ctx( {
&ins, &outs, &attrs, &default_attrs, op.Type(), &kernel_type); platform::RecordEvent record_event(op.Type() + " infer_shape",
op.Info().infer_shape_(&infer_shape_ctx); platform::EventRole::kInnerOp);
DygraphInferShapeContext<VarType> infer_shape_ctx(
&ins, &outs, &attrs, &default_attrs, op.Type(), &kernel_type);
op.Info().infer_shape_(&infer_shape_ctx);
}
{
platform::RecordEvent record_event(op.Type() + " compute",
platform::EventRole::kInnerOp);
func(DygraphExecutionContext<VarType>(op, scope, *dev_ctx, ctx, ins, outs, func(DygraphExecutionContext<VarType>(op, scope, *dev_ctx, ctx, ins, outs,
attrs, default_attrs)); attrs, default_attrs));
}
if (FLAGS_check_nan_inf) { if (FLAGS_check_nan_inf) {
framework::details::CheckOpHasNanOrInfInDygraph<VarType>( framework::details::CheckOpHasNanOrInfInDygraph<VarType>(
...@@ -551,18 +561,27 @@ static void PreparedOpRunPtImpl( ...@@ -551,18 +561,27 @@ static void PreparedOpRunPtImpl(
const NameVarMap<VarType>& ins, const NameVarMap<VarType>& outs, const NameVarMap<VarType>& ins, const NameVarMap<VarType>& outs,
const framework::AttributeMap& attrs, const framework::AttributeMap& attrs,
const framework::AttributeMap& default_attrs) { const framework::AttributeMap& default_attrs) {
DygraphInferShapeContext<VarType> infer_shape_ctx( {
&ins, &outs, &attrs, &default_attrs, op.Type(), &kernel_type); platform::RecordEvent record_event(op.Type() + " infer_shape",
op.Info().infer_shape_(&infer_shape_ctx); platform::EventRole::kInnerOp);
DygraphInferShapeContext<VarType> infer_shape_ctx(
&ins, &outs, &attrs, &default_attrs, op.Type(), &kernel_type);
op.Info().infer_shape_(&infer_shape_ctx);
}
{
platform::RecordEvent record_event(op.Type() + " compute",
platform::EventRole::kInnerOp);
PreparePtenData<VarType>(pt_kernel, pt_kernel_signature, ins); PreparePtenData<VarType>(pt_kernel, pt_kernel_signature, ins);
pten::KernelContext pt_kernel_context; pten::KernelContext pt_kernel_context;
BuildDygraphPtenKernelContext<VarType>(pt_kernel_signature, pt_kernel, ins, BuildDygraphPtenKernelContext<VarType>(pt_kernel_signature, pt_kernel, ins,
outs, attrs, default_attrs, dev_ctx, outs, attrs, default_attrs, dev_ctx,
&pt_kernel_context); &pt_kernel_context);
pt_kernel(&pt_kernel_context); pt_kernel(&pt_kernel_context);
}
if (FLAGS_benchmark) { if (FLAGS_benchmark) {
dev_ctx->Wait(); dev_ctx->Wait();
......
...@@ -123,6 +123,7 @@ static PyObject * %s(PyObject *self, PyObject *args, PyObject *kwargs) ...@@ -123,6 +123,7 @@ static PyObject * %s(PyObject *self, PyObject *args, PyObject *kwargs)
PyThreadState *tstate = nullptr; PyThreadState *tstate = nullptr;
try try
{ {
platform::RecordEvent op_type_record_event("%s pybind_imperative_func");
%s %s
framework::AttributeMap attrs; framework::AttributeMap attrs;
ConstructAttrMapFromPyArgs("%s", args, %d, PyTuple_GET_SIZE(args) , attrs); ConstructAttrMapFromPyArgs("%s", args, %d, PyTuple_GET_SIZE(args) , attrs);
...@@ -371,8 +372,8 @@ std::string GenerateOpFunctionsBody( ...@@ -371,8 +372,8 @@ std::string GenerateOpFunctionsBody(
// generate op funtcion body // generate op funtcion body
auto op_function_str = paddle::string::Sprintf( auto op_function_str = paddle::string::Sprintf(
OP_FUNCTION_TEMPLATE, func_name, ins_cast_str, op_type, input_args_num, OP_FUNCTION_TEMPLATE, func_name, op_type, ins_cast_str, op_type,
inplace_strategy_str, outs_initializer, ins_initializer, input_args_num, inplace_strategy_str, outs_initializer, ins_initializer,
ins_initializer_with_null + outs_initializer_with_null + ins_initializer_with_null + outs_initializer_with_null +
view_strategy_str, view_strategy_str,
op_type, inplace_mapping_str, return_str); op_type, inplace_mapping_str, return_str);
...@@ -461,6 +462,7 @@ int main(int argc, char* argv[]) { ...@@ -461,6 +462,7 @@ int main(int argc, char* argv[]) {
#endif #endif
std::vector<std::string> headers{"\"paddle/fluid/imperative/tracer.h\"", std::vector<std::string> headers{"\"paddle/fluid/imperative/tracer.h\"",
"\"paddle/fluid/platform/profiler.h\"",
"\"pybind11/detail/common.h\"", "\"pybind11/detail/common.h\"",
"<Python.h>"}; "<Python.h>"};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册