From d3f88584a77b119d965ac0b200ab4ddc47547331 Mon Sep 17 00:00:00 2001 From: xiebaiyuan Date: Thu, 16 May 2019 17:56:05 +0800 Subject: [PATCH] fix crash when close optimise in gpu test close #1626 --- src/framework/executor.cpp | 30 +++++++++++++++++--------- src/framework/executor.h | 5 +++++ src/framework/type_trait.h | 44 ++++++++++++++++++++++++++++++++++++++ src/operators/op_param.h | 21 ++---------------- 4 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 src/framework/type_trait.h diff --git a/src/framework/executor.cpp b/src/framework/executor.cpp index 47fd9c3c66..2ac7035a70 100644 --- a/src/framework/executor.cpp +++ b/src/framework/executor.cpp @@ -467,21 +467,32 @@ PMStatus Executor::Predict() { ++op_index; #endif } + +#ifdef PADDLE_MOBILE_PROFILE + PrintProfile(profile); +#endif + return PMSuccess; +} + #ifdef PADDLE_MOBILE_PROFILE +template +void Executor::PrintProfile( + const vector::ProfInfo> &profile) const { std::unordered_map _tp; for (int i = 0; i < profile.size(); i++) { const auto &pInfo = profile[i]; uint64_t timeCost = pInfo.runEnd - pInfo.runBegin; - if (ops_of_block0_[i]->Type() == "conv2d" || - ops_of_block0_[i]->Type() == "depthwise_conv2d") { - auto inputs = ops_of_block0_[i]->Inputs(); - auto *filter = - GetVarValue("Filter", inputs, *(program_.scope)); + if (this->ops_of_block0_[i]->Type() == "conv2d" || + this->ops_of_block0_[i]->Type() == "depthwise_conv2d") { + auto inputs = this->ops_of_block0_[i]->Inputs(); + + auto *filter = GetVarValue("Filter", inputs, + *(this->program_.scope)); int kernel_size = filter->dims()[2]; - _tp[ops_of_block0_[i]->Type() + "_" + std::to_string(kernel_size)] += - timeCost; + _tp[this->ops_of_block0_[i]->Type() + "_" + + std::to_string(kernel_size)] += timeCost; } else { - _tp[ops_of_block0_[i]->Type()] += timeCost; + _tp[this->ops_of_block0_[i]->Type()] += timeCost; } } printf("====================[ profile ]======================\n"); @@ -502,9 +513,8 @@ PMStatus Executor::Predict() { static_cast(p.second) / _ptotal * 100.0); } printf("====================[---------]======================\n"); -#endif - return PMSuccess; } +#endif template void Executor::FeedTensorData(const vector &v) { diff --git a/src/framework/executor.h b/src/framework/executor.h index 78a4bd61dd..57b05dbc6c 100644 --- a/src/framework/executor.h +++ b/src/framework/executor.h @@ -25,6 +25,7 @@ limitations under the License. */ #include "framework/operator.h" #include "framework/program/program.h" #include "framework/tensor.h" +#include "framework/type_trait.h" namespace paddle_mobile { namespace framework { @@ -98,11 +99,15 @@ class Executor { DDim input_dim_last_; #ifdef PADDLE_MOBILE_PROFILE + typedef typename DtypeTensorTrait::gtype ProfileTensorType; + struct ProfInfo { int tid = 0; uint64_t runBegin = 0UL; uint64_t runEnd = 0UL; }; + + void PrintProfile(const vector::ProfInfo> &profile) const; #endif }; diff --git a/src/framework/type_trait.h b/src/framework/type_trait.h new file mode 100644 index 0000000000..d1a8e30522 --- /dev/null +++ b/src/framework/type_trait.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2018 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 +#include + +namespace paddle_mobile { +namespace framework { + +template +struct DtypeTensorTrait { + // This is the type we obtained in variable. + typedef framework::LoDTensor gtype; + // This type will be the parent class type + // or the same type. + typedef framework::Tensor rtype; +}; + +#ifdef PADDLE_MOBILE_CL +template <> +struct DtypeTensorTrait { + // This is the type we obtained in variable. + typedef framework::CLImage gtype; + // This type will be the parent class type + // or the same type. + typedef framework::CLImage rtype; +}; +#endif + +} // namespace framework +} // namespace paddle_mobile diff --git a/src/operators/op_param.h b/src/operators/op_param.h index fc34ea1e27..97dbd091a1 100644 --- a/src/operators/op_param.h +++ b/src/operators/op_param.h @@ -23,6 +23,7 @@ limitations under the License. */ #include "framework/lod_tensor.h" #include "framework/scope.h" #include "framework/tensor.h" +#include "framework/type_trait.h" #include "framework/variable.h" #ifdef PADDLE_MOBILE_FPGA_V1 @@ -53,25 +54,7 @@ using framework::Variable; using std::string; using std::vector; -template -struct DtypeTensorTrait { - // This is the type we obtained in variable. - typedef framework::LoDTensor gtype; - // This type will be the parent class type - // or the same type. - typedef framework::Tensor rtype; -}; - -#ifdef PADDLE_MOBILE_CL -template <> -struct DtypeTensorTrait { - // This is the type we obtained in variable. - typedef framework::CLImage gtype; - // This type will be the parent class type - // or the same type. - typedef framework::CLImage rtype; -}; -#endif +using framework::DtypeTensorTrait; class OpParam { public: -- GitLab