diff --git a/lite/core/profile/profiler.cc b/lite/core/profile/profiler.cc index 2a23d5818752eb227281f195e74eea13a6bcb901..de4f93a05c15072d1343adfe9d4bde84f8fc4e7e 100644 --- a/lite/core/profile/profiler.cc +++ b/lite/core/profile/profiler.cc @@ -24,10 +24,16 @@ namespace profile { namespace { auto op_comp = [](const OpCharacter& c1, const OpCharacter& c2) { - return (c1.target < c2.target) || (c1.op_type < c2.op_type) || - (c1.kernel_name < c2.kernel_name) || (c1.remark < c2.remark); + if (c1.kernel_func_name == "NotImpl" && c2.kernel_func_name == "NotImpl") { + return (c1.target < c2.target) || (c1.op_type < c2.op_type) || + (c1.kernel_name < c2.kernel_name) || (c1.remark < c2.remark); + } else { // compare with ch.kernel_func_name + return (c1.target < c2.target) || (c1.op_type < c2.op_type) || + (c1.kernel_name < c2.kernel_name) || + (c1.kernel_func_name < c2.kernel_func_name); + } }; -} +} // namespace std::map TypeStr{ {Type::kUnk, "Unknown"}, @@ -88,6 +94,36 @@ void Profiler::StopTiming(Type type, const int index, KernelContext* ctx) { #endif } +int Profiler::GetKernelFuncCalledTimes(const std::string& op_type, + const std::string& kernel_func_name) { + int count = 0; + for (size_t i = 0; i < units_.size(); ++i) { + if ((units_[i].character.kernel_func_name == kernel_func_name) && + (units_[i].character.kernel_func_name != "NotImpl")) { + ++count; + } else if ((units_[i].character.kernel_func_name == "NotImpl") && + (units_[i].character.op_type == op_type)) { + ++count; + } + } + return count; +} + +float Profiler::GetKernelFuncSummaryGOPs(const std::string& op_type, + const std::string& kernel_func_name) { + float GOPs = 0; + for (size_t i = 0; i < units_.size(); ++i) { + if ((units_[i].character.kernel_func_name == kernel_func_name) && + (units_[i].character.kernel_func_name != "NotImpl")) { + GOPs += units_[i].character.macs; + } else if ((units_[i].character.kernel_func_name == "NotImpl") && + (units_[i].character.op_type == op_type)) { + GOPs += units_[i].character.macs; + } + } + return GOPs * 1e-9f; +} + std::string Profiler::Summary(Type type, bool concise, size_t w) { using std::setw; using std::left; @@ -108,13 +144,11 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << " warm-ups =====" << std::endl; } ss << setw(20) << left << "OperatorType" - << " " << setw(30) << left << "KerneAttr"; - if (!concise) { - ss << " " << setw(24) << left << "KernelName"; - } - ss << " " << setw(26) << left << "Remark"; + << " " << setw(30) << left << "KerneAttr(Place)" + << " " << setw(24) << left << "KernelFuncName"; if (!concise) { - ss << " " << setw(15) << left << "InDim" + ss << " " << setw(26) << left << "Remark" + << " " << setw(15) << left << "InDim" << " " << setw(15) << left << "FilterDim" << " " << setw(15) << left << "OutDim"; } @@ -124,10 +158,13 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { if (!concise) { ss << " " << setw(7) << left << "Last(ms)"; } - ss << " " << setw(7) << left << "Avg(%)"; + ss << " " << setw(7) << left << "Avg(%)" + << " " << setw(7) << left << "GOPs"; if (!concise) { - ss << " " << setw(7) << left << "GOPs" - << " " << setw(7) << left << "GOPS"; + ss << " " << setw(7) << left << "GOPS"; + } + if (concise) { + ss << " " << setw(11) << left << "CalledTimes"; } #ifdef LITE_WITH_OPENCL ss << " " << setw(9) << left << "clAvg(ms)" @@ -185,14 +222,20 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { // clang-format off ss << setw(20) << left << fixed << item.first.op_type << " " << setw(30) << left << fixed << item.first.kernel_attr - << " " << setw(26) << left << fixed << item.first.remark + << " " << setw(24) << left << fixed << item.first.kernel_func_name << " " << setw(7) << left << fixed << setprecision(3) << item.second.avg << " " << setw(7) << left << fixed << setprecision(3) << item.second.min << " " << setw(7) << left << fixed << setprecision(3) - << item.second.max - << " " << setprecision(2) << percent << "% "; + << item.second.max + << " " << setprecision(2) << percent << "% " + << " " << setw(7) << left << fixed << setprecision(3) + << GetKernelFuncSummaryGOPs(item.first.op_type, + item.first.kernel_func_name) + << " " << setw(11) << left << fixed + << GetKernelFuncCalledTimes(item.first.op_type, + item.first.kernel_func_name); #ifdef LITE_WITH_OPENCL float cl_percent = 0; if (cl_total > 0) { @@ -204,7 +247,7 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << item.second.cl_min << " " << setw(9) << left << fixed << setprecision(3) << item.second.cl_max - << " " << left << fixed < #include "lite/core/op_lite.h" +#ifdef LITE_WITH_PROFILE +#include "lite/api/paddle_place.h" +#endif namespace paddle { namespace lite { @@ -34,6 +37,58 @@ class ActivationOp : public OpLite { std::string DebugString() const override { return "activation_op"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter* ch) { + auto input_dims = param_.X->dims(); + auto output_dims = param_.Out->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = ActivationTypeToStr(param_.active_type); + switch (param_.active_type) { + case lite_api::ActivationType::kRelu: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kRelu6: + ch->macs = param_.X->numel() * 2.0; + break; + case lite_api::ActivationType::kLeakyRelu: + ch->macs = param_.X->numel() * 2.0; + break; + case lite_api::ActivationType::kPRelu: + ch->macs = param_.X->numel() * 2.0; + break; + case lite_api::ActivationType::kSwish: + ch->macs = param_.X->numel() * 4.0; + break; + case lite_api::ActivationType::kSigmoid: + ch->macs = param_.X->numel() * 3.0; + break; + case lite_api::ActivationType::kTanh: + ch->macs = param_.X->numel() * 5.0; + break; + case lite_api::ActivationType::kExp: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kAbs: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kHardSwish: + ch->macs = param_.X->numel() * 5.0; + break; + case lite_api::ActivationType::kReciprocal: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kIndentity: + break; + default: + LOG(FATAL) << "This Type of Activation:" + << static_cast(param_.active_type) + << ActivationTypeToStr(param_.active_type) + << " doesn't support"; + } + } +#endif + private: mutable operators::ActivationParam param_; }; diff --git a/lite/operators/affine_channel_op.h b/lite/operators/affine_channel_op.h index 5a3d9d66259d477d42ac00e0e1b1a7ba1bf2e862..e58ad8419ff605c1b33f7e82b8822be402ab39e5 100644 --- a/lite/operators/affine_channel_op.h +++ b/lite/operators/affine_channel_op.h @@ -39,6 +39,17 @@ class AffineChannelOpLite : public OpLite { std::string DebugString() const override { return "affine_channel"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.X->dims(); + auto output_dims = param_.Out->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = param_.data_layout; + ch->macs = param_.X->numel() * 2.0; + } +#endif + private: mutable AffineChannelParam param_; }; diff --git a/lite/operators/argmax_op.h b/lite/operators/argmax_op.h index e6944507cf9f6ded86ccbae7c3cec79106e8ba98..14920108996e9bac006744d43c5f69991801bc27 100644 --- a/lite/operators/argmax_op.h +++ b/lite/operators/argmax_op.h @@ -39,6 +39,27 @@ class ArgmaxOpLite : public OpLite { std::string DebugString() const override { return "argmax"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.X->dims(); + auto output_dims = param_.Out->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "axis" + std::to_string(param_.Axis); + + auto axis = param_.Axis; + if (axis < 0) { + axis += input_dims.size(); + } + int max_num = 1; + for (int64_t i = axis + 1; i < input_dims.size(); i++) + max_num *= input_dims[i]; + float gops = 1.0f; + for (int i = 1; i <= max_num; i++) gops *= i; + ch->macs = gops * output_dims.production(); + } +#endif + private: mutable ArgmaxParam param_; }; diff --git a/lite/operators/assign_op.h b/lite/operators/assign_op.h index 9e7039bb5b0088a6bda6acbf2baf7a50444df8b2..9b0a74cf0dbefbf3669118707c92c304f7ef63b2 100644 --- a/lite/operators/assign_op.h +++ b/lite/operators/assign_op.h @@ -37,6 +37,17 @@ class AssignOpLite : public OpLite { void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } std::string DebugString() const override { return "assign"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.X->dims(); + auto output_dims = param_.Out->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + // ch->remark = ""; + ch->macs = param_.X->numel() * 1.0; + } +#endif + private: mutable AssignParam param_; }; diff --git a/lite/operators/assign_value_op.h b/lite/operators/assign_value_op.h index 030da048184c9862b76f59198574b394457768d5..08a857dfb9bbec944e99c27e7f9491515a683533 100644 --- a/lite/operators/assign_value_op.h +++ b/lite/operators/assign_value_op.h @@ -39,6 +39,17 @@ class AssignValueOpLite : public OpLite { std::string DebugString() const override { return "assign value"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + // auto input_dims = param_.X->dims(); + auto output_dims = param_.Out->dims(); + // ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "dtype" + std::to_string(param_.dtype); + ch->macs = param_.Out->numel() * 1.0; + } +#endif + private: mutable AssignValueParam param_; }; diff --git a/lite/operators/axpy_op.h b/lite/operators/axpy_op.h index e9d9f44ca5f5843628af998d9140519a3f3a1c29..ff3a59a3d53766ceee5b29f17e545266143fd61d 100644 --- a/lite/operators/axpy_op.h +++ b/lite/operators/axpy_op.h @@ -39,6 +39,17 @@ class AxpyOpLite : public OpLite { std::string DebugString() const override { return "axpy"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.X->dims(); + auto output_dims = param_.Out->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + // ch->remark = ""; + ch->macs = param_.X->numel() * 2.0; + } +#endif + private: mutable AxpyParam param_; }; diff --git a/lite/operators/batch_norm_op.h b/lite/operators/batch_norm_op.h index 9598763713564192ed4ad0c99200f0fdb1d88d37..8734de4afaad9d548780f5a6ebd23d8cb0ee7799 100644 --- a/lite/operators/batch_norm_op.h +++ b/lite/operators/batch_norm_op.h @@ -37,6 +37,17 @@ class BatchNormOp : public OpLite { void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } std::string DebugString() const override { return "batch_norm"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.x->dims(); + auto output_dims = param_.y->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + // ch->remark = ""; + ch->macs = param_.y->numel() * 2.0; + } +#endif + private: mutable BatchNormParam param_; }; diff --git a/lite/operators/box_clip_op.h b/lite/operators/box_clip_op.h index 0aae2112ec8b91ba63205fadd4123bc3c5fce2fd..5fa3ae71f36013a4581716a1258d64e04e1dc10f 100644 --- a/lite/operators/box_clip_op.h +++ b/lite/operators/box_clip_op.h @@ -39,6 +39,17 @@ class BoxClipOpLite : public OpLite { std::string DebugString() const override { return "box clip"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.Input->dims(); + auto output_dims = param_.Output->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + // ch->remark = ""; + ch->macs = param_.Output->numel() * 2.0; + } +#endif + private: mutable BoxClipParam param_; }; diff --git a/lite/operators/box_coder_op.h b/lite/operators/box_coder_op.h index 51e86423e39786426d53fe8ced861866bfeb1053..2039ed19ea579ade6eeb3895a18094ba86bd7ede 100644 --- a/lite/operators/box_coder_op.h +++ b/lite/operators/box_coder_op.h @@ -34,8 +34,21 @@ class BoxCoderOpLite : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "box_coder"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + // auto input_dims = param_.Input->dims(); + // auto output_dims = param_.Output->dims(); + // ch->input_shape = ch->DimToStr(input_dims); + // ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "proposals" + std::to_string(param_.proposals->dims()[0]) + + "x" + std::to_string(param_.proposals->dims()[1]); + ch->macs = param_.proposals->dims()[0] * param_.proposals->dims()[1] * 30.f; + } +#endif + private: mutable BoxCoderParam param_; }; diff --git a/lite/operators/calib_op.h b/lite/operators/calib_op.h index 94240880f55e782f025fe5777eba19e0c96cfbee..1ce41d1dc1d98d3985bd40c9b6bf5f3f685d5178 100644 --- a/lite/operators/calib_op.h +++ b/lite/operators/calib_op.h @@ -50,6 +50,17 @@ class CalibOpLite : public OpLite { std::string DebugString() const override { return "calib"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.input->dims(); + auto output_dims = param_.output->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "scale" + std::to_string(param_.scale); + ch->macs = param_.output->numel() * 1.0f; + } +#endif + private: mutable CalibParam param_; }; diff --git a/lite/operators/compare_op.h b/lite/operators/compare_op.h index c94cf88516af7676f8e524c091713cbaa4dd70ff..384016be8aca4a95006b1a5300ef6eee474c7a30 100644 --- a/lite/operators/compare_op.h +++ b/lite/operators/compare_op.h @@ -38,6 +38,18 @@ class CompareOp : public OpLite { std::string DebugString() const override { return "binary logical"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto output_dims = param_.Out->dims(); + ch->input_shape = "X:" + ch->DimToStr(param_.X->dims()) + "Y:" + + ch->DimToStr(param_.Y->dims()); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "axis" + std::to_string(param_.axis) + "force_cpu" + + std::to_string(param_.force_cpu); + ch->macs = param_.Out->numel() * 1.0f; + } +#endif + private: mutable CompareParam param_; }; diff --git a/lite/operators/concat_op.h b/lite/operators/concat_op.h index 2ac1572c833db217546aaa176640cb5c1022d3bf..166148bc048e736ec222df97a44a2875f92e3c7a 100644 --- a/lite/operators/concat_op.h +++ b/lite/operators/concat_op.h @@ -37,6 +37,21 @@ class ConcatOpLite : public OpLite { void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } std::string DebugString() const override { return "concat"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto output_dims = param_.output->dims(); + std::string inputs_shape = ""; + for (size_t i = 0; i < param_.x.size(); ++i) { + inputs_shape += ch->DimToStr(param_.x[i]->dims()); + if (i != param_.x.size() - 1) inputs_shape += "/"; + } + ch->input_shape = inputs_shape; + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "axis" + std::to_string(param_.axis); + ch->macs = 0.f; // no calc. only io operation + } +#endif + private: mutable ConcatParam param_; }; diff --git a/lite/operators/conv_transpose_op.h b/lite/operators/conv_transpose_op.h index 891ece4f052128c8c236db5650414d6015ea9565..1d88fc9609e83d80ba800c1f460a18be932c980d 100644 --- a/lite/operators/conv_transpose_op.h +++ b/lite/operators/conv_transpose_op.h @@ -21,6 +21,9 @@ #include "lite/core/tensor.h" #include "lite/operators/op_params.h" #include "lite/utils/all.h" +#ifdef LITE_WITH_PROFILE +#include "lite/api/paddle_place.h" +#endif namespace paddle { namespace lite { @@ -42,6 +45,29 @@ class ConvTransposeOpLite : public OpLite { std::string DebugString() const override { return "conv_transpose"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto filter_dims = param_.filter->dims(); + auto input_dims = param_.x->dims(); + auto output_dims = param_.output->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->filter_shape = ch->DimToStr(filter_dims); + ch->remark = + std::to_string(filter_dims[2]) + "x" + std::to_string(filter_dims[3]) + + "p" + std::to_string((*param_.paddings)[0]) + "s" + + std::to_string(param_.strides[0]) + "g" + + std::to_string(param_.groups) + "d" + + std::to_string((*param_.dilations)[0]) + (param_.bias ? "Bias" : "") + + ActivationTypeToStr(param_.activation_param.active_type); + // MACs = 2.f * kw * kh * batchsize * out_c * out_h * out_w * in_c / group + // GMACs = 1e-9f * MACs + // GMACPS = 1e-6f * MACs / predict_ms + ch->macs = 2.f * filter_dims[2] * filter_dims[3] * + output_dims.production() * input_dims[1] / param_.groups; + } +#endif + private: mutable ConvParam param_; std::string padding_algorithm_{""}; diff --git a/lite/operators/elementwise_ops.h b/lite/operators/elementwise_ops.h index 0f1b682fa5f267dd802c5ee0e35aca8f6d68f39c..526281067876d9c18f3a865660d4458ae30bc8a6 100644 --- a/lite/operators/elementwise_ops.h +++ b/lite/operators/elementwise_ops.h @@ -35,6 +35,17 @@ class ElementwiseOp : public OpLite { std::string DebugString() const override { return "elementwise_op"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter* ch) { + auto output_dims = param_.Out->dims(); + ch->input_shape = "X" + ch->DimToStr(param_.X->dims()) + "Y" + + ch->DimToStr(param_.Y->dims()); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "axis" + std::to_string(param_.axis); + ch->macs = 1.0f * param_.Out->numel(); + } +#endif + private: mutable operators::ElementwiseParam param_; }; diff --git a/lite/operators/fc_op.h b/lite/operators/fc_op.h index 2e6a3ad59a1ca6d2e31f42ceb4b2d1b381c697ee..26227db17b25794c4e2491c792a8fcc97cfd8c36 100644 --- a/lite/operators/fc_op.h +++ b/lite/operators/fc_op.h @@ -43,6 +43,17 @@ class FcOpLite : public OpLite { std::string DebugString() const override { return "fc"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto m = param_.input->dims().count(0, param_.in_num_col_dims); + ch->input_shape = ch->DimToStr(param_.input->dims()); + ch->filter_shape = ch->DimToStr(param_.w->dims()); + ch->output_shape = ch->DimToStr(param_.output->dims()); + ch->remark = (param_.bias ? "Bias" : "") + param_.activation_type; + ch->macs = m * param_.w->dims()[0] * param_.w->dims()[1] * 3.0f; + } +#endif + private: mutable FcParam param_; }; diff --git a/lite/operators/increment_op.h b/lite/operators/increment_op.h index d4e6fd6b1ff1aea47df130d510bc84ab0a0b6019..34ff255d36be56040a35a2fcf494c84c5b8e09b8 100644 --- a/lite/operators/increment_op.h +++ b/lite/operators/increment_op.h @@ -38,6 +38,15 @@ class IncrementOp : public OpLite { std::string DebugString() const override { return "increment"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = "step" + std::to_string(param_.step); + ch->macs = param_.X->numel() * 1.0f; + } +#endif + private: mutable IncrementParam param_; }; diff --git a/lite/operators/instance_norm_op.h b/lite/operators/instance_norm_op.h index 94a1f69fa4433072a986f1d82d5f1b8401a03386..fd0b011cee00703bcca7dcea3be22560d0cc60bd 100644 --- a/lite/operators/instance_norm_op.h +++ b/lite/operators/instance_norm_op.h @@ -36,8 +36,22 @@ class InstanceNormOp : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "instance_norm"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.x->dims()); + ch->output_shape = ch->DimToStr(param_.out->dims()); + // ch->remark = ""; + auto x_dims = param_.x->dims(); + auto nc = x_dims[0] * x_dims[1]; + auto hw = x_dims[2] * x_dims[3]; + auto nchw = x_dims.production(); + ch->macs = 5.f * nchw + 3.f * (nc + hw); + } +#endif + private: mutable InstanceNormParam param_; }; diff --git a/lite/operators/interpolate_op.h b/lite/operators/interpolate_op.h index 2bc938964811c57189e45d3b9d892542f9f02e8f..d8fc674c5bd6ba5da1d89c609be6c6bfedcc49a9 100644 --- a/lite/operators/interpolate_op.h +++ b/lite/operators/interpolate_op.h @@ -36,8 +36,18 @@ class InterpolateOp : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "interpolate"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = param_.interp_method; + ch->macs = param_.Out->numel() * 14.f; + } +#endif + private: mutable InterpolateParam param_; }; diff --git a/lite/operators/layer_norm_op.h b/lite/operators/layer_norm_op.h index 6e15d2f599beb14df024f2591b098b128c3af8dd..3d8cbe53ff260a5ef76d32e337cb41e620debc8f 100644 --- a/lite/operators/layer_norm_op.h +++ b/lite/operators/layer_norm_op.h @@ -38,6 +38,15 @@ class LayerNormOp : public OpLite { std::string DebugString() const override { return "layer_norm"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Y->dims()); + ch->remark = "begin_norm_axis" + std::to_string(param_.begin_norm_axis); + ch->macs = param_.Y->numel() * 7.f; + } +#endif + private: mutable LayerNormParam param_; }; diff --git a/lite/operators/logical_op.h b/lite/operators/logical_op.h index e784d4d99b7de29593e411db9b6a888e5bd52e21..ba217389c2e3ac2c68b68217d7a820a9ac76064c 100644 --- a/lite/operators/logical_op.h +++ b/lite/operators/logical_op.h @@ -38,6 +38,16 @@ class BinaryLogicalOp : public OpLite { std::string DebugString() const override { return "binary logical"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = "X" + ch->DimToStr(param_.X->dims()) + "Y" + + ch->DimToStr(param_.Y->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + // ch->remark = ""; + ch->macs = param_.Out->numel() * 3.f; + } +#endif + private: mutable LogicalParam param_; }; @@ -57,6 +67,16 @@ class UnaryLogicalOp : public OpLite { std::string DebugString() const override { return "binary logical"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = "X" + ch->DimToStr(param_.X->dims()) + "Y" + + ch->DimToStr(param_.Y->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + // ch->remark = ""; + ch->macs = param_.Out->numel() * 3.f; + } +#endif + private: mutable LogicalParam param_; }; diff --git a/lite/operators/lrn_op.h b/lite/operators/lrn_op.h index 13dfdefdc6f28dc289f490340faa14c166485db0..c9b88f0a256994b592bae2773f43eea98abd9c39 100644 --- a/lite/operators/lrn_op.h +++ b/lite/operators/lrn_op.h @@ -33,8 +33,18 @@ class LrnOpLite : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "lrn"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = "n" + std::to_string(param_.n) + param_.norm_region; + ch->macs = param_.Out->numel() * param_.k * 2.f; + } +#endif + private: mutable LrnParam param_; }; diff --git a/lite/operators/matmul_op.h b/lite/operators/matmul_op.h index acb9d512f7ac50818e9521ca67e04318397dabb0..388b6b612bd36602bb77b6ada777038feeb42994 100644 --- a/lite/operators/matmul_op.h +++ b/lite/operators/matmul_op.h @@ -41,6 +41,31 @@ class MatMulOpLite : public OpLite { std::string DebugString() const override { return "matmul"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->filter_shape = ch->DimToStr(param_.Y->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = "alpha" + std::to_string(param_.alpha) + "trans_x" + + std::to_string(param_.transpose_X) + "trans_y" + + std::to_string(param_.transpose_Y); + + auto x_dims = param_.X->dims(); + auto y_dims = param_.Y->dims(); + auto m = x_dims[x_dims.size() - 2]; + auto k = x_dims[x_dims.size() - 1]; + auto n = y_dims[y_dims.size() - 1]; + if (param_.transpose_X) { + m = x_dims[x_dims.size() - 1]; + k = x_dims[x_dims.size() - 2]; + } + if (param_.transpose_Y) { + n = y_dims[y_dims.size() - 2]; + } + ch->macs = 3.f * m * n * k; + } +#endif + private: mutable MatMulParam param_; }; diff --git a/lite/operators/mean_op.h b/lite/operators/mean_op.h index c4dff93ce78aa4598bd12fb3181aa5f2bd4820b6..a8d7439470394814e26a192010378a6c61487f6b 100644 --- a/lite/operators/mean_op.h +++ b/lite/operators/mean_op.h @@ -35,6 +35,15 @@ class MeanOp : public OpLite { std::string DebugString() const override { return "mean"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + // ch->remark = ""; + ch->macs = param_.X->numel() * 1.f; + } +#endif + private: mutable operators::MeanParam param_; }; diff --git a/lite/operators/mul_op.h b/lite/operators/mul_op.h index 74b64f11ae2ec75efa61a7799da49187c9e684ea..7775530ccb88ed3a0ad0cc227457ce482696bd94 100644 --- a/lite/operators/mul_op.h +++ b/lite/operators/mul_op.h @@ -63,6 +63,20 @@ class MulOpLite : public OpLite { std::string DebugString() const override { return "mul"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.x->dims()); + ch->filter_shape = ch->DimToStr(param_.y->dims()); + ch->output_shape = ch->DimToStr(param_.output->dims()); + // ch->remark = ""; + auto x_dims = param_.x->dims(); + auto y_dims = param_.y->dims(); + auto x_mat_dims = x_dims.Flatten2D(param_.x_num_col_dims); + auto y_mat_dims = y_dims.Flatten2D(param_.y_num_col_dims); + ch->macs = 1.f * x_mat_dims[0] * x_mat_dims[1] * y_mat_dims[1]; + } +#endif + private: mutable MulParam param_; }; diff --git a/lite/operators/negative_op.h b/lite/operators/negative_op.h index 04ec92532559c050cc5a9e8ac6bdf9a817e0dc70..912a6f3eb1113b3b4611c217b6fefc67acfdcfcd 100644 --- a/lite/operators/negative_op.h +++ b/lite/operators/negative_op.h @@ -35,8 +35,18 @@ class NegativeOpLite : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "negative"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + // ch->remark = ""; + ch->macs = 1.f * param_.Out->numel(); + } +#endif + private: mutable NegativeParam param_; }; diff --git a/lite/operators/power_op.h b/lite/operators/power_op.h index e89dfa7b8f682e029bfba1059fda9c17340c420b..3b88dd04b945cec7c8424c817f0ff918e64b5df8 100644 --- a/lite/operators/power_op.h +++ b/lite/operators/power_op.h @@ -36,8 +36,18 @@ class PowerOp : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "power"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + // ch->remark = ""; + ch->macs = param_.Out->numel() * 3.0f; + } +#endif + private: mutable PowerParam param_; }; diff --git a/lite/operators/reduce_max_op.h b/lite/operators/reduce_max_op.h index 54b136a7576fb2bb078c5bcae727b15d319bdf8e..b5e4a0496fc2a415f7c568b2fae1ff8cc79b69b9 100644 --- a/lite/operators/reduce_max_op.h +++ b/lite/operators/reduce_max_op.h @@ -32,8 +32,29 @@ class ReduceMaxOp : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "reduce_max"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = "keep_dim" + std::to_string(param_.keep_dim); + + auto dims = param_.dim; + auto in_sum = param_.X->numel(); + if (dims.size() == 0 || dims.size() == 1) { + ch->macs = 1.f * in_sum; + } else if (dims.size() == 2) { + ch->macs = 2.f * in_sum; + } else { + LOG(FATAL) << "This dims size of ReduceMaxParm: " << dims.size() + << " doesn't support"; + ch->macs = 0.f; + } + } +#endif + private: mutable ReduceMaxParam param_; }; diff --git a/lite/operators/reduce_mean_op.h b/lite/operators/reduce_mean_op.h index 43fe955690b3e4569f75c88a4d7b9ba9e961fcca..b1b96f868a07e1210cbc6e719d66f20e5cf5ef69 100644 --- a/lite/operators/reduce_mean_op.h +++ b/lite/operators/reduce_mean_op.h @@ -26,14 +26,41 @@ namespace operators { class ReduceMeanOp : public OpLite { public: ReduceMeanOp() {} + explicit ReduceMeanOp(const std::string &op_type) : OpLite(op_type) {} + bool CheckShape() const override; + bool InferShapeImpl() const override; + bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "reduce_mean"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = "keep_dim" + std::to_string(param_.keep_dim); + + auto dims = param_.dim; + auto in_sum = param_.X->numel(); + if (dims.size() == 0) { + ch->macs = 1.f * in_sum; + } else if (dims.size() == 1) { + ch->macs = 2.f * in_sum; + } else if (dims.size() == 2) { + ch->macs = 4.f * in_sum; + } else { + LOG(FATAL) << "This dims size of ReduceMean: " << dims.size() + << " doesn't support"; + ch->macs = 0.f; + } + } +#endif + private: mutable ReduceMeanParam param_; }; diff --git a/lite/operators/reduce_prod_op.h b/lite/operators/reduce_prod_op.h index d8bb1400b9aecf449499d4c6920c2ef88eb119b2..cc11fc30ccea0a64e38209270a6bb19473230770 100644 --- a/lite/operators/reduce_prod_op.h +++ b/lite/operators/reduce_prod_op.h @@ -37,6 +37,27 @@ class ReduceProdOpLite : public OpLite { std::string DebugString() const override { return "reduce_prod"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.x->dims()); + ch->output_shape = ch->DimToStr(param_.output->dims()); + ch->remark = "keep_dim" + std::to_string(param_.keep_dim) + "reduce_all" + + std::to_string(param_.reduce_all); + + auto dims = param_.dim; + auto in_sum = param_.x->numel(); + if (dims.size() == 0 || dims.size() == 1) { + ch->macs = 1.f * in_sum; + } else if (dims.size() == 2) { + ch->macs = 2.f * in_sum; + } else { + LOG(FATAL) << "This dims size of ReduceProd: " << dims.size() + << " doesn't support"; + ch->macs = 0.f; + } + } +#endif + private: mutable ReduceParam param_; }; diff --git a/lite/operators/relu_op.h b/lite/operators/relu_op.h index 7577f2ffbab62298138b22970c00caf9ab01367f..d8b94b16fb7d3f84fbbdf4a392e458ba55787f37 100644 --- a/lite/operators/relu_op.h +++ b/lite/operators/relu_op.h @@ -18,6 +18,9 @@ #include "lite/core/op_lite.h" #include "lite/core/scope.h" #include "lite/utils/all.h" +#ifdef LITE_WITH_PROFILE +#include "lite/api/paddle_place.h" +#endif namespace paddle { namespace lite { @@ -35,8 +38,61 @@ class ReluOp : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "relu"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.X->dims(); + auto output_dims = param_.Out->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = ActivationTypeToStr(param_.active_type); + switch (param_.active_type) { + case lite_api::ActivationType::kRelu: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kRelu6: + ch->macs = param_.X->numel() * 2.0; + break; + case lite_api::ActivationType::kLeakyRelu: + ch->macs = param_.X->numel() * 2.0; + break; + case lite_api::ActivationType::kPRelu: + ch->macs = param_.X->numel() * 2.0; + break; + case lite_api::ActivationType::kSwish: + ch->macs = param_.X->numel() * 4.0; + break; + case lite_api::ActivationType::kSigmoid: + ch->macs = param_.X->numel() * 3.0; + break; + case lite_api::ActivationType::kTanh: + ch->macs = param_.X->numel() * 5.0; + break; + case lite_api::ActivationType::kExp: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kAbs: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kHardSwish: + ch->macs = param_.X->numel() * 5.0; + break; + case lite_api::ActivationType::kReciprocal: + ch->macs = param_.X->numel(); + break; + case lite_api::ActivationType::kIndentity: + break; + default: + LOG(FATAL) << "This Type of Activation:" + << static_cast(param_.active_type) + << ActivationTypeToStr(param_.active_type) + << " doesn't support"; + } + } +#endif + private: mutable ActivationParam param_; }; diff --git a/lite/operators/scale_op.h b/lite/operators/scale_op.h index 38970bfcfd82eebce51612e6afb531cbf3b10966..73a01ab24e57b4490f881d5fc7d051e4fd82e709 100644 --- a/lite/operators/scale_op.h +++ b/lite/operators/scale_op.h @@ -35,8 +35,19 @@ class ScaleOp : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "scale"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.x->dims()); + ch->output_shape = ch->DimToStr(param_.output->dims()); + ch->remark = + param_.activation_type + "alpha" + std::to_string(param_.alpha); + ch->macs = param_.x->numel() * 1.f; + } +#endif + private: mutable ScaleParam param_; }; diff --git a/lite/operators/search_aligned_mat_mul_op.h b/lite/operators/search_aligned_mat_mul_op.h index 8242e06d0170a8a4c178f0e460c64f93b0c2bc3c..37329a97b0e91252f956741d25c4f8f58cf3e45b 100644 --- a/lite/operators/search_aligned_mat_mul_op.h +++ b/lite/operators/search_aligned_mat_mul_op.h @@ -27,17 +27,48 @@ class SearchAlignedMatMulOpLite : public OpLite { public: SearchAlignedMatMulOpLite() {} - explicit SearchAlignedMatMulOpLite(const std::string &type) : OpLite(type) {} + explicit SearchAlignedMatMulOpLite(const std::string& type) : OpLite(type) {} bool CheckShape() const override; bool InferShapeImpl() const override; - void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + void AttachKernel(KernelBase* kernel) override { kernel->SetParam(param_); } + + bool AttachImpl(const cpp::OpDesc& op_desc, lite::Scope* scope) override; - bool AttachImpl(const cpp::OpDesc &op_desc, lite::Scope *scope) override; std::string DebugString() const override { return "search_aligned_mat_mul"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter* ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->filter_shape = ch->DimToStr(param_.Y->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = "alpha" + std::to_string(param_.alpha) + "trans_x" + + std::to_string(param_.transpose_X) + "trans_y" + + std::to_string(param_.transpose_Y); + + const auto x_dims = param_.X->dims(); + const auto y_dims = param_.Y->dims(); + const auto& x_lod = param_.X->lod(); + const auto& y_lod = param_.Y->lod(); + const auto& x_lod_0 = x_lod[0]; + const auto& y_lod_0 = y_lod[0]; + + int x_inner_size = x_dims[1]; + int y_inner_size = y_dims[1]; + int x_batch_size = x_lod_0[1]; + int y_batch_size = y_lod_0[1]; + int M = param_.transpose_X ? x_inner_size : x_batch_size; + int N = param_.transpose_Y ? y_batch_size : y_inner_size; + int X_K = param_.transpose_X ? x_batch_size : x_inner_size; + int Y_K = param_.transpose_Y ? y_inner_size : y_batch_size; + CHECK_EQ(X_K, Y_K) << "K of Input(X) and Input(Y) is not equal"; + int K = X_K; + ch->macs = 2.0 * M * N * K; + } +#endif + private: mutable MatMulParam param_; }; diff --git a/lite/operators/search_fc_op.h b/lite/operators/search_fc_op.h index 235c24c57ff0e925d763fa11a78f56cfe72613cd..f4206040a4bdd01037d4ce81234bda335baf82f8 100644 --- a/lite/operators/search_fc_op.h +++ b/lite/operators/search_fc_op.h @@ -35,8 +35,21 @@ class SearchFcOpLite : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "search_fc"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.X->dims()); + ch->filter_shape = ch->DimToStr(param_.W->dims()); + ch->output_shape = ch->DimToStr(param_.Out->dims()); + ch->remark = "out_size" + std::to_string(param_.out_size); + auto x_dims = param_.X->dims(); + auto w_dims = param_.W->dims(); + ch->macs = 2.f * x_dims[0] * x_dims[1] * w_dims[0]; + } +#endif + private: mutable SearchFcParam param_; }; diff --git a/lite/operators/search_seq_fc_op.h b/lite/operators/search_seq_fc_op.h index bacafcfe6ffa2a2c518cf3b8f226fa29c9b95e95..b8867c44c2ba2fb2cb116d6d02a57b95646247bd 100644 --- a/lite/operators/search_seq_fc_op.h +++ b/lite/operators/search_seq_fc_op.h @@ -36,8 +36,21 @@ class SearchSeqFcOpLite : public OpLite { void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } bool AttachImpl(const cpp::OpDesc &op_desc, lite::Scope *scope) override; + std::string DebugString() const override { return "search_seq_fc"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + ch->input_shape = ch->DimToStr(param_.x->dims()); + ch->filter_shape = ch->DimToStr(param_.w->dims()); + ch->output_shape = ch->DimToStr(param_.out->dims()); + ch->remark = "out_size" + std::to_string(param_.out_size); + auto x_dims = param_.x->dims(); + auto w_dims = param_.w->dims(); + ch->macs = 2.f * x_dims[0] * x_dims[1] * w_dims[0]; + } +#endif + private: mutable SearchSeqFcParam param_; }; diff --git a/lite/operators/search_seq_softmax_op.h b/lite/operators/search_seq_softmax_op.h index dca3619eab9013f22d962b16c577c73862ee5e64..173d834da8ce7d2a796c4a02415bac37efb1dd0b 100644 --- a/lite/operators/search_seq_softmax_op.h +++ b/lite/operators/search_seq_softmax_op.h @@ -36,8 +36,20 @@ class SearchSeqSoftmaxOp : public OpLite { bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } + std::string DebugString() const override { return "search_seq_softmax_op"; } +#ifdef LITE_WITH_PROFILE + void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { + auto input_dims = param_.x->dims(); + auto output_dims = param_.output->dims(); + ch->input_shape = ch->DimToStr(input_dims); + ch->output_shape = ch->DimToStr(output_dims); + ch->remark = "axis" + std::to_string(param_.axis); + ch->macs = 4.f * param_.x->numel(); + } +#endif + private: mutable SoftmaxParam param_; };