提交 7deff6de 编写于 作者: X xiebaiyuan

fix crash when close optimise in gpu test close #1626

上级 43e040dc
......@@ -467,21 +467,32 @@ PMStatus Executor<Device, T>::Predict() {
++op_index;
#endif
}
#ifdef PADDLE_MOBILE_PROFILE
PrintProfile(profile);
#endif
return PMSuccess;
}
#ifdef PADDLE_MOBILE_PROFILE
template <typename Device, typename T>
void Executor<Device, T>::PrintProfile(
const vector<Executor<Device, T>::ProfInfo> &profile) const {
std::unordered_map<std::string, uint64_t> _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<LoDTensor>("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<ProfileTensorType>("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<Device, T>::Predict() {
static_cast<float>(p.second) / _ptotal * 100.0);
}
printf("====================[---------]======================\n");
#endif
return PMSuccess;
}
#endif
template <typename Device, typename T>
void Executor<Device, T>::FeedTensorData(const vector<framework::Tensor> &v) {
......
......@@ -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<Device>::gtype ProfileTensorType;
struct ProfInfo {
int tid = 0;
uint64_t runBegin = 0UL;
uint64_t runEnd = 0UL;
};
void PrintProfile(const vector<Executor<Device, T>::ProfInfo> &profile) const;
#endif
};
......
/* 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 <common/types.h>
#include <string>
namespace paddle_mobile {
namespace framework {
template <typename Dtype>
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<GPU_CL> {
// 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
......@@ -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 <typename Dtype>
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<GPU_CL> {
// 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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册