提交 276ec6f9 编写于 作者: H hjchen2

Implement while op, fix feed/fetch and fix code style

上级 9d499955
...@@ -37,8 +37,7 @@ template <typename Dtype> ...@@ -37,8 +37,7 @@ template <typename Dtype>
using OpCreator = std::function<framework::OperatorBase<Dtype> *( using OpCreator = std::function<framework::OperatorBase<Dtype> *(
const std::string & /*type*/, const VariableNameMap & /*inputs*/, const std::string & /*type*/, const VariableNameMap & /*inputs*/,
const VariableNameMap & /*outputs*/, const VariableNameMap & /*outputs*/,
const framework::AttributeMap & /*attrs*/, const framework::AttributeMap & /*attrs*/, framework::Scope * /*scope*/)>;
std::shared_ptr<framework::Scope> /*scope*/)>;
using InferVarTypeFN = std::function<void(const framework::OpDesc & /*op_desc*/, using InferVarTypeFN = std::function<void(const framework::OpDesc & /*op_desc*/,
framework::BlockDesc * /*block*/)>; framework::BlockDesc * /*block*/)>;
......
...@@ -66,7 +66,7 @@ Executor<Device, T>::Executor(const Program<Device> &program, ...@@ -66,7 +66,7 @@ Executor<Device, T>::Executor(const Program<Device> &program,
auto op_handler = OpRegistry<Device>::CreateOp( auto op_handler = OpRegistry<Device>::CreateOp(
op_desc->Type(), op_desc->GetInputs(), op_desc->GetOutputs(), op_desc->Type(), op_desc->GetInputs(), op_desc->GetOutputs(),
op_desc->GetAttrMap(), program_.scope); op_desc->GetAttrMap(), program_.scope.get());
// infer shape to reshape inputs and outputs before predict, // infer shape to reshape inputs and outputs before predict,
// but for lod mode, it still need to infer shape in runtime // but for lod mode, it still need to infer shape in runtime
if (!lod_mode) { if (!lod_mode) {
...@@ -80,6 +80,8 @@ Executor<Device, T>::Executor(const Program<Device> &program, ...@@ -80,6 +80,8 @@ Executor<Device, T>::Executor(const Program<Device> &program,
} else { } else {
InitMemory(); InitMemory();
} }
// resize feed and fetch list
InitFeedFetchList();
int count = 0; int count = 0;
for (auto &op_handler : ops_of_block0_) { for (auto &op_handler : ops_of_block0_) {
...@@ -88,6 +90,33 @@ Executor<Device, T>::Executor(const Program<Device> &program, ...@@ -88,6 +90,33 @@ Executor<Device, T>::Executor(const Program<Device> &program,
} }
} }
template <typename Device, typename T>
void Executor<Device, T>::InitFeedFetchList() {
std::unordered_map<std::string, int> feed_indices, fetch_indices;
for (const auto &block : program_desc_->Blocks()) {
for (const auto &op_desc : block->Ops()) {
if (op_desc->Type() == "feed") {
std::string name = op_desc->Output("Out")[0];
feed_indices[name] = op_desc->GetAttr("col").Get<int>();
} else if (op_desc->Type() == "fetch") {
std::string name = op_desc->Input("X")[0];
fetch_indices[name] = op_desc->GetAttr("col").Get<int>();
}
}
}
feed_indices_.swap(feed_indices);
fetch_indices_.swap(fetch_indices);
auto *feed_var = program_.scope->Var("feed");
auto *feed_list = feed_var->template GetMutable<framework::LoDTensorArray>();
feed_list->resize(feed_indices_.size());
auto *fetch_var = program_.scope->Var("fetch");
auto *fetch_list =
fetch_var->template GetMutable<framework::LoDTensorArray>();
fetch_list->resize(fetch_indices_.size());
}
template <typename T> template <typename T>
static void LoadMemInternal(void **data, LoDTensor *tensor, static void LoadMemInternal(void **data, LoDTensor *tensor,
bool quant_uint8 = false) { bool quant_uint8 = false) {
...@@ -182,6 +211,7 @@ void Executor<Device, T>::InitMemory() { ...@@ -182,6 +211,7 @@ void Executor<Device, T>::InitMemory() {
LoadMemory(reinterpret_cast<void **>(&data), var_desc, tensor); LoadMemory(reinterpret_cast<void **>(&data), var_desc, tensor);
delete[] origin_data; delete[] origin_data;
} else { } else {
DLOG << "init no persistable var: " << var_desc->Name();
varInputMemory(var_desc, var); varInputMemory(var_desc, var);
} }
} }
...@@ -319,11 +349,19 @@ PMStatus Executor<Device, T>::Predict( ...@@ -319,11 +349,19 @@ PMStatus Executor<Device, T>::Predict(
template <typename Device, typename T> template <typename Device, typename T>
std::vector<T> Executor<Device, T>::Predict(const std::vector<T> &input, std::vector<T> Executor<Device, T>::Predict(const std::vector<T> &input,
const std::vector<int64_t> &dims) { const std::vector<int64_t> &dims) {
PADDLE_MOBILE_ENFORCE(feed_indices_.size() != 0,
"We don't know which tensor should be assign, since no "
"feed op found in this model");
PADDLE_MOBILE_ENFORCE(fetch_indices_.size() != 0,
"We don't know which tensor should be fetch out, since "
"no fetch op found in this model");
std::string input_name = feed_indices_.begin()->first;
Tensor feed_tensor(input, make_ddim(dims)); Tensor feed_tensor(input, make_ddim(dims));
SetInput(feed_tensor, "feed"); SetInput(feed_tensor, input_name);
std::vector<T> output; std::vector<T> output;
if (this->Predict() == PMSuccess) { if (this->Predict() == PMSuccess) {
const auto output_tensor = GetOutput("fetch"); std::string output_name = fetch_indices_.begin()->first;
const auto output_tensor = GetOutput(output_name);
output.resize(output_tensor->numel()); output.resize(output_tensor->numel());
memcpy(output.data(), output_tensor->template data<T>(), memcpy(output.data(), output_tensor->template data<T>(),
output.size() * sizeof(T)); output.size() * sizeof(T));
...@@ -334,12 +372,18 @@ std::vector<T> Executor<Device, T>::Predict(const std::vector<T> &input, ...@@ -334,12 +372,18 @@ std::vector<T> Executor<Device, T>::Predict(const std::vector<T> &input,
template <typename Device, typename T> template <typename Device, typename T>
void Executor<Device, T>::SetInput(const Tensor &input, void Executor<Device, T>::SetInput(const Tensor &input,
const std::string &var_name) { const std::string &var_name) {
auto *target_var = program_.scope->FindVar(var_name); framework::LoDTensor *target = nullptr;
PADDLE_MOBILE_ENFORCE(target_var != nullptr, "Variable %s is not exist", if (feed_indices_.find(var_name) != feed_indices_.end()) {
var_name.c_str()); int index = feed_indices_.find(var_name)->second;
auto *feed_var = program_.scope->Var("feed");
auto *target_tensor = target_var->template GetMutable<LoDTensor>(); target = &(
feed_var->template GetMutable<framework::LoDTensorArray>()->at(index));
} else {
auto *target_var = program_.scope->FindVar(var_name);
PADDLE_MOBILE_ENFORCE(target_var != nullptr, "Variable %s is not exist",
var_name.c_str());
target = target_var->template GetMutable<LoDTensor>();
}
if (config_.load_when_predict) { if (config_.load_when_predict) {
if (input_dim_last_ != input.dims()) { if (input_dim_last_ != input.dims()) {
InitNoPersistableMemory(input); InitNoPersistableMemory(input);
...@@ -347,28 +391,53 @@ void Executor<Device, T>::SetInput(const Tensor &input, ...@@ -347,28 +391,53 @@ void Executor<Device, T>::SetInput(const Tensor &input,
} }
} }
target_tensor->Resize(input.dims()); target->Resize(input.dims());
target_tensor->ShareDataWith(input); target->ShareDataWith(input);
} }
template <typename Device, typename T> template <typename Device, typename T>
void Executor<Device, T>::SetInput(const LoDTensor &input, void Executor<Device, T>::SetInput(const LoDTensor &input,
const std::string &var_name) { const std::string &var_name) {
auto *target_var = program_.scope->FindVar(var_name); framework::LoDTensor *target = nullptr;
PADDLE_MOBILE_ENFORCE(target_var != nullptr, "Variable %s is not exist", if (feed_indices_.find(var_name) != feed_indices_.end()) {
var_name.c_str()); int index = feed_indices_.find(var_name)->second;
auto *target_tensor = target_var->template GetMutable<LoDTensor>(); auto *feed_var = program_.scope->Var("feed");
target = &(
feed_var->template GetMutable<framework::LoDTensorArray>()->at(index));
} else {
auto *target_var = program_.scope->FindVar(var_name);
PADDLE_MOBILE_ENFORCE(target_var != nullptr, "Variable %s is not exist",
var_name.c_str());
target = target_var->template GetMutable<LoDTensor>();
}
if (config_.load_when_predict) { if (config_.load_when_predict) {
if (input_dim_last_ != input.dims()) { if (input_dim_last_ != input.dims()) {
InitNoPersistableMemory(*target_tensor); InitNoPersistableMemory(input);
input_dim_last_ = input.dims(); input_dim_last_ = input.dims();
} }
} }
target_tensor->Resize(input.dims()); target->Resize(input.dims());
target_tensor->ShareDataWith(input); target->ShareDataWith(input);
target_tensor->set_lod(input.lod()); target->set_lod(input.lod());
}
template <typename Device, typename T>
std::shared_ptr<LoDTensor> Executor<Device, T>::GetOutput(
const std::string &var_name) {
framework::LoDTensor *target = nullptr;
if (fetch_indices_.find(var_name) != fetch_indices_.end()) {
int index = fetch_indices_.find(var_name)->second;
auto *fetch_var = program_.scope->Var("fetch");
target = &(
fetch_var->template GetMutable<framework::LoDTensorArray>()->at(index));
} else {
auto *target_var = program_.scope->FindVar(var_name);
PADDLE_MOBILE_ENFORCE(target_var != nullptr, "Variable %s is not exist",
var_name.c_str());
target = target_var->template GetMutable<LoDTensor>();
}
return std::make_shared<LoDTensor>(*target);
} }
template <typename Device, typename T> template <typename Device, typename T>
...@@ -432,16 +501,6 @@ PMStatus Executor<Device, T>::Predict() { ...@@ -432,16 +501,6 @@ PMStatus Executor<Device, T>::Predict() {
return PMSuccess; return PMSuccess;
} }
template <typename Device, typename T>
std::shared_ptr<LoDTensor> Executor<Device, T>::GetOutput(
const std::string &var_name) {
auto *target_var = program_.scope->FindVar(var_name);
PADDLE_MOBILE_ENFORCE(target_var != nullptr, "Variable %s is not exist",
var_name.c_str());
auto *output_tensor = target_var->template GetMutable<LoDTensor>();
return std::make_shared<LoDTensor>(*output_tensor);
}
#ifdef PADDLE_MOBILE_FPGA #ifdef PADDLE_MOBILE_FPGA
template <typename Device, typename T> template <typename Device, typename T>
void Executor<Device, T>::InjectVariable(const Tensor &t, void Executor<Device, T>::InjectVariable(const Tensor &t,
......
...@@ -63,6 +63,7 @@ class Executor { ...@@ -63,6 +63,7 @@ class Executor {
bool varInputMemory(const std::shared_ptr<VarDesc> &var_desc, bool varInputMemory(const std::shared_ptr<VarDesc> &var_desc,
Variable *var) const; Variable *var) const;
void InitFeedFetchList();
void InitMemory(); void InitMemory();
void InitCombineMemory(); void InitCombineMemory();
void InitNoPersistableMemory(const Tensor &input_tensor); void InitNoPersistableMemory(const Tensor &input_tensor);
...@@ -79,6 +80,8 @@ class Executor { ...@@ -79,6 +80,8 @@ class Executor {
Program<Device> program_; Program<Device> program_;
std::shared_ptr<ProgramDesc> program_desc_; std::shared_ptr<ProgramDesc> program_desc_;
std::vector<std::shared_ptr<OperatorBase<Device>>> ops_of_block0_; std::vector<std::shared_ptr<OperatorBase<Device>>> ops_of_block0_;
std::unordered_map<std::string, int> feed_indices_;
std::unordered_map<std::string, int> fetch_indices_;
// for super resoltion // for super resoltion
DDim input_dim_last_; DDim input_dim_last_;
......
...@@ -221,6 +221,8 @@ inline Print &operator<<(Print &printer, const LoDTensor &tensor) { ...@@ -221,6 +221,8 @@ inline Print &operator<<(Print &printer, const LoDTensor &tensor) {
printer << static_cast<int>(tensor.data<int8_t>()[i]) << " "; printer << static_cast<int>(tensor.data<int8_t>()[i]) << " ";
} else if (tensor.type() == typeid(int32_t)) { } else if (tensor.type() == typeid(int32_t)) {
printer << tensor.data<int32_t>()[i] << " "; printer << tensor.data<int32_t>()[i] << " ";
} else if (tensor.type() == typeid(bool)) {
printer << tensor.data<bool>()[i] << " ";
} }
} }
#endif // PADDLE_MOBILE_FPGA #endif // PADDLE_MOBILE_FPGA
......
...@@ -58,8 +58,7 @@ struct OpInfoFiller { ...@@ -58,8 +58,7 @@ struct OpInfoFiller {
void operator()(const std::string& op_type, OpInfo<Dtype>* info) const { void operator()(const std::string& op_type, OpInfo<Dtype>* info) const {
info->creator_ = [](const std::string& type, const VariableNameMap& inputs, info->creator_ = [](const std::string& type, const VariableNameMap& inputs,
const VariableNameMap& outputs, const VariableNameMap& outputs,
const AttributeMap& attrs, const AttributeMap& attrs, framework::Scope* scope) {
std::shared_ptr<Scope> scope) {
return new T(type, inputs, outputs, attrs, scope); return new T(type, inputs, outputs, attrs, scope);
}; };
} }
...@@ -91,7 +90,7 @@ class OpRegistry { ...@@ -91,7 +90,7 @@ class OpRegistry {
static std::shared_ptr<OperatorBase<Dtype>> CreateOp( static std::shared_ptr<OperatorBase<Dtype>> CreateOp(
const std::string& type, const VariableNameMap& inputs, const std::string& type, const VariableNameMap& inputs,
const VariableNameMap& outputs, const AttributeMap attrs, const VariableNameMap& outputs, const AttributeMap attrs,
std::shared_ptr<paddle_mobile::framework::Scope> scope) { paddle_mobile::framework::Scope* scope) {
auto& info = OpInfoMap<Dtype>::Instance()->Get(type); auto& info = OpInfoMap<Dtype>::Instance()->Get(type);
auto op = info.Creator()(type, inputs, outputs, attrs, scope); auto op = info.Creator()(type, inputs, outputs, attrs, scope);
return std::shared_ptr<OperatorBase<Dtype>>(op); return std::shared_ptr<OperatorBase<Dtype>>(op);
......
...@@ -43,7 +43,7 @@ OperatorBase<Dtype>::OperatorBase(const std::string &type, ...@@ -43,7 +43,7 @@ OperatorBase<Dtype>::OperatorBase(const std::string &type,
const VariableNameMap &inputs, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const AttributeMap &attrs, const AttributeMap &attrs,
std::shared_ptr<Scope> scope) framework::Scope *scope)
: type_(type), : type_(type),
inputs_(inputs), inputs_(inputs),
outputs_(outputs), outputs_(outputs),
......
...@@ -57,7 +57,7 @@ class OperatorBase { ...@@ -57,7 +57,7 @@ class OperatorBase {
public: public:
OperatorBase(const std::string &type, const VariableNameMap &inputs, OperatorBase(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const AttributeMap &attrs, const VariableNameMap &outputs, const AttributeMap &attrs,
std::shared_ptr<Scope> scope); framework::Scope *scope);
virtual ~OperatorBase() {} virtual ~OperatorBase() {}
virtual void Init() = 0; virtual void Init() = 0;
...@@ -80,7 +80,7 @@ class OperatorBase { ...@@ -80,7 +80,7 @@ class OperatorBase {
} }
protected: protected:
std::shared_ptr<Scope> scope_; framework::Scope *scope_;
std::string type_; std::string type_;
VariableNameMap inputs_; VariableNameMap inputs_;
VariableNameMap outputs_; VariableNameMap outputs_;
...@@ -95,7 +95,7 @@ class OperatorWithKernel : public OperatorBase<Dtype> { ...@@ -95,7 +95,7 @@ class OperatorWithKernel : public OperatorBase<Dtype> {
public: public:
OperatorWithKernel(const std::string &type, const VariableNameMap &inputs, OperatorWithKernel(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const AttributeMap &attrs, const VariableNameMap &outputs, const AttributeMap &attrs,
std::shared_ptr<Scope> scope) framework::Scope *scope)
: OperatorBase<Dtype>(type, inputs, outputs, attrs, scope), : OperatorBase<Dtype>(type, inputs, outputs, attrs, scope),
param_(inputs, outputs, attrs, *scope) { param_(inputs, outputs, attrs, *scope) {
#ifdef PADDLE_MOBILE_CL #ifdef PADDLE_MOBILE_CL
...@@ -174,21 +174,20 @@ class FusionOpMatcher { ...@@ -174,21 +174,20 @@ class FusionOpMatcher {
std::shared_ptr<OpDesc> new_opdesc_; std::shared_ptr<OpDesc> new_opdesc_;
}; };
#define DECLARE_OPERATOR(OpName, OpParam, OpKernel) \ #define DECLARE_OPERATOR(OpName, OpParam, OpKernel) \
template <typename DeviceType, typename T> \ template <typename DeviceType, typename T> \
class OpName##Op : public framework::OperatorWithKernel< \ class OpName##Op : public framework::OperatorWithKernel< \
DeviceType, OpParam<DeviceType>, \ DeviceType, OpParam<DeviceType>, \
operators::OpKernel<DeviceType, T>> { \ operators::OpKernel<DeviceType, T>> { \
public: \ public: \
OpName##Op(const std::string &type, const VariableNameMap &inputs, \ OpName##Op(const std::string &type, const VariableNameMap &inputs, \
const VariableNameMap &outputs, \ const VariableNameMap &outputs, \
const framework::AttributeMap &attrs, \ const framework::AttributeMap &attrs, framework::Scope *scope) \
std::shared_ptr<framework::Scope> scope) \ : framework::OperatorWithKernel<DeviceType, OpParam<DeviceType>, \
: framework::OperatorWithKernel<DeviceType, OpParam<DeviceType>, \ operators::OpKernel<DeviceType, T>>( \
operators::OpKernel<DeviceType, T>>( \ type, inputs, outputs, attrs, scope) {} \
type, inputs, outputs, attrs, scope) {} \ \
\ void InferShape() const override; \
void InferShape() const override; \
}; };
#define DECLARE_KERNEL(OpName, OpParam) \ #define DECLARE_KERNEL(OpName, OpParam) \
...@@ -204,7 +203,7 @@ class FusionOpMatcher { ...@@ -204,7 +203,7 @@ class FusionOpMatcher {
cls(const std::string &type, const ::paddle_mobile::VariableNameMap &inputs, \ cls(const std::string &type, const ::paddle_mobile::VariableNameMap &inputs, \
const ::paddle_mobile::VariableNameMap &outputs, \ const ::paddle_mobile::VariableNameMap &outputs, \
const ::paddle_mobile::framework::AttributeMap &attrs, \ const ::paddle_mobile::framework::AttributeMap &attrs, \
std::shared_ptr<::paddle_mobile::framework::Scope> scope) \ ::paddle_mobile::framework::Scope *scope) \
: parent_cls<Dtype, T>(type, inputs, outputs, attrs, scope) {} : parent_cls<Dtype, T>(type, inputs, outputs, attrs, scope) {}
} // namespace framework } // namespace framework
......
...@@ -32,15 +32,7 @@ class Scope { ...@@ -32,15 +32,7 @@ class Scope {
Scope() = default; Scope() = default;
~Scope() { ~Scope() {
for (auto &var : vars_) { DropKids();
delete var.second;
}
vars_.clear();
for (auto kid : kids_) {
delete kid;
}
kids_.clear();
#ifdef PADDLE_MOBILE_CL #ifdef PADDLE_MOBILE_CL
delete cl_scope_; delete cl_scope_;
#endif #endif
......
...@@ -32,8 +32,7 @@ class BatchNormOp ...@@ -32,8 +32,7 @@ class BatchNormOp
public: public:
BatchNormOp(const string &type, const VariableNameMap &inputs, BatchNormOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, BatchNormParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, BatchNormParam<DeviceType>,
BatchNormKernel<DeviceType, T>>( BatchNormKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,8 +34,7 @@ class BilinearOp : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class BilinearOp : public framework::OperatorWithKernel<
public: public:
BilinearOp(const std::string &type, const VariableNameMap &inputs, BilinearOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, BilinearInterpParam<DeviceType>, DeviceType, BilinearInterpParam<DeviceType>,
operators::BilinearInterpKernel<DeviceType, T>>( operators::BilinearInterpKernel<DeviceType, T>>(
......
...@@ -34,8 +34,7 @@ class BoxCoderOp : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class BoxCoderOp : public framework::OperatorWithKernel<
public: public:
BoxCoderOp(const std::string &type, const VariableNameMap &inputs, BoxCoderOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, BoxCoderParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, BoxCoderParam<DeviceType>,
operators::BoxCoderKernel<DeviceType, T>>( operators::BoxCoderKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -31,7 +31,7 @@ class CastOp : public framework::OperatorWithKernel< ...@@ -31,7 +31,7 @@ class CastOp : public framework::OperatorWithKernel<
public: public:
CastOp(const std::string &type, const VariableNameMap &inputs, CastOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, CastParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, CastParam<DeviceType>,
operators::CastKernel<DeviceType, T>>( operators::CastKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -30,7 +30,7 @@ class ConcatOp : public framework::OperatorWithKernel< ...@@ -30,7 +30,7 @@ class ConcatOp : public framework::OperatorWithKernel<
public: public:
ConcatOp(const string &type, const VariableNameMap &inputs, ConcatOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, ConcatParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, ConcatParam<DeviceType>,
operators::ConcatKernel<DeviceType, T>>( operators::ConcatKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -30,7 +30,7 @@ class ConvOp : public framework::OperatorWithKernel< ...@@ -30,7 +30,7 @@ class ConvOp : public framework::OperatorWithKernel<
public: public:
ConvOp(const std::string &type, const VariableNameMap &inputs, ConvOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, ConvParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, ConvParam<DeviceType>,
operators::ConvKernel<DeviceType, T>>( operators::ConvKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -31,8 +31,7 @@ class ConvOpTranspose : public framework::OperatorWithKernel< ...@@ -31,8 +31,7 @@ class ConvOpTranspose : public framework::OperatorWithKernel<
public: public:
ConvOpTranspose(const std::string &type, const VariableNameMap &inputs, ConvOpTranspose(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, ConvTransposeParam<DeviceType>, DeviceType, ConvTransposeParam<DeviceType>,
operators::ConvTransposeKernel<DeviceType, T>>( operators::ConvTransposeKernel<DeviceType, T>>(
......
...@@ -33,7 +33,7 @@ class CrfOp : public framework::OperatorWithKernel< ...@@ -33,7 +33,7 @@ class CrfOp : public framework::OperatorWithKernel<
public: public:
CrfOp(const std::string &type, const VariableNameMap &inputs, CrfOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, CrfParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, CrfParam<DeviceType>,
operators::CrfKernel<DeviceType, T>>( operators::CrfKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -30,8 +30,7 @@ class DepthwiseConvOp : public framework::OperatorWithKernel< ...@@ -30,8 +30,7 @@ class DepthwiseConvOp : public framework::OperatorWithKernel<
public: public:
DepthwiseConvOp(const std::string &type, const VariableNameMap &inputs, DepthwiseConvOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, ConvParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, ConvParam<DeviceType>,
operators::ConvKernel<DeviceType, T>>( operators::ConvKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -32,8 +32,7 @@ class DequantizeOp ...@@ -32,8 +32,7 @@ class DequantizeOp
public: public:
DequantizeOp(const std::string &type, const VariableNameMap &inputs, DequantizeOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, DequantizeParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, DequantizeParam<DeviceType>,
DequantizeKernel<DeviceType, T>>( DequantizeKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,7 +34,7 @@ class DropoutOp : public framework::OperatorWithKernel< ...@@ -34,7 +34,7 @@ class DropoutOp : public framework::OperatorWithKernel<
public: public:
DropoutOp(const std::string &type, const VariableNameMap &inputs, DropoutOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap attrs, const VariableNameMap &outputs, const framework::AttributeMap attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, DropoutParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, DropoutParam<DeviceType>,
operators::DropoutKernel<DeviceType, T>>( operators::DropoutKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -32,7 +32,7 @@ class ElementwiseAddOp : public framework::OperatorWithKernel< ...@@ -32,7 +32,7 @@ class ElementwiseAddOp : public framework::OperatorWithKernel<
ElementwiseAddOp(const string &type, const VariableNameMap &inputs, ElementwiseAddOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, ElementwiseAddParam<DeviceType>, DeviceType, ElementwiseAddParam<DeviceType>,
operators::ElementwiseAddKernel<DeviceType, T>>( operators::ElementwiseAddKernel<DeviceType, T>>(
......
...@@ -32,7 +32,7 @@ class ElementwiseMulOp : public framework::OperatorWithKernel< ...@@ -32,7 +32,7 @@ class ElementwiseMulOp : public framework::OperatorWithKernel<
ElementwiseMulOp(const string &type, const VariableNameMap &inputs, ElementwiseMulOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, ElementwiseMulParam<DeviceType>, DeviceType, ElementwiseMulParam<DeviceType>,
operators::ElementwiseMulKernel<DeviceType, T>>( operators::ElementwiseMulKernel<DeviceType, T>>(
......
...@@ -32,7 +32,7 @@ class ElementwiseSubOp : public framework::OperatorWithKernel< ...@@ -32,7 +32,7 @@ class ElementwiseSubOp : public framework::OperatorWithKernel<
ElementwiseSubOp(const string &type, const VariableNameMap &inputs, ElementwiseSubOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, ElementwiseSubParam<DeviceType>, DeviceType, ElementwiseSubParam<DeviceType>,
operators::ElementwiseSubKernel<DeviceType, T>>( operators::ElementwiseSubKernel<DeviceType, T>>(
......
...@@ -31,7 +31,7 @@ class FeedOp ...@@ -31,7 +31,7 @@ class FeedOp
public: public:
FeedOp(const std::string &type, const VariableNameMap &inputs, FeedOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap attrs, const VariableNameMap &outputs, const framework::AttributeMap attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, FeedParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, FeedParam<DeviceType>,
FeedKernel<DeviceType, T>>( FeedKernel<DeviceType, T>>(
......
...@@ -18,8 +18,9 @@ namespace operators { ...@@ -18,8 +18,9 @@ namespace operators {
template <typename DeviceType, typename T> template <typename DeviceType, typename T>
void FetchOp<DeviceType, T>::InferShape() const { void FetchOp<DeviceType, T>::InferShape() const {
int col = this->param_.Col();
auto x_dims = this->param_.InputX()->dims(); auto x_dims = this->param_.InputX()->dims();
this->param_.Out()->Resize(x_dims); this->param_.Out()->at(col).Resize(x_dims);
} }
} // namespace operators } // namespace operators
......
...@@ -30,7 +30,7 @@ class FetchOp ...@@ -30,7 +30,7 @@ class FetchOp
public: public:
FetchOp(const string &type, const VariableNameMap &inputs, FetchOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap attrs, const VariableNameMap &outputs, const framework::AttributeMap attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, FetchParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, FetchParam<DeviceType>,
FetchKernel<DeviceType, T>>( FetchKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -31,8 +31,7 @@ class FillConstantOp : public framework::OperatorBase<DeviceType> { ...@@ -31,8 +31,7 @@ class FillConstantOp : public framework::OperatorBase<DeviceType> {
public: public:
FillConstantOp(const std::string &type, const VariableNameMap &inputs, FillConstantOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap attrs, const framework::AttributeMap attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorBase<DeviceType>(type, inputs, outputs, attrs, : framework::OperatorBase<DeviceType>(type, inputs, outputs, attrs,
scope), scope),
param_(inputs, outputs, attrs, *scope) {} param_(inputs, outputs, attrs, *scope) {}
......
...@@ -49,8 +49,7 @@ class FlattenOp : public framework::OperatorWithKernel< ...@@ -49,8 +49,7 @@ class FlattenOp : public framework::OperatorWithKernel<
public: public:
FlattenOp(const std::string &type, const VariableNameMap &inputs, FlattenOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, FlattenParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, FlattenParam<DeviceType>,
operators::FlattenKernel<DeviceType, T>>( operators::FlattenKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -63,7 +63,7 @@ class FusionConvAddAddPReluOp ...@@ -63,7 +63,7 @@ class FusionConvAddAddPReluOp
FusionConvAddAddPReluOp(const string &type, const VariableNameMap &inputs, FusionConvAddAddPReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionConvAddAddPReluParam<DeviceType>, DeviceType, FusionConvAddAddPReluParam<DeviceType>,
operators::ConvAddAddPReluKernel<DeviceType, T>>( operators::ConvAddAddPReluKernel<DeviceType, T>>(
......
...@@ -20,8 +20,8 @@ limitations under the License. */ ...@@ -20,8 +20,8 @@ limitations under the License. */
#include <vector> #include <vector>
#include "framework/operator.h" #include "framework/operator.h"
#include "framework/program/program-optimize/fusion_op_register.h" #include "framework/program/program-optimize/fusion_op_register.h"
#include "op_param.h"
#include "operators/kernel/conv_add_bn_kernel.h" #include "operators/kernel/conv_add_bn_kernel.h"
#include "operators/op_param.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace operators { namespace operators {
...@@ -59,7 +59,7 @@ class FusionConvAddBNOp : public framework::OperatorWithKernel< ...@@ -59,7 +59,7 @@ class FusionConvAddBNOp : public framework::OperatorWithKernel<
FusionConvAddBNOp(const string &type, const VariableNameMap &inputs, FusionConvAddBNOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionConvAddBNParam<DeviceType>, DeviceType, FusionConvAddBNParam<DeviceType>,
operators::ConvAddBNKernel<DeviceType, T>>(type, inputs, outputs, operators::ConvAddBNKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -61,7 +61,7 @@ class FusionConvAddBNReluOp ...@@ -61,7 +61,7 @@ class FusionConvAddBNReluOp
FusionConvAddBNReluOp(const string &type, const VariableNameMap &inputs, FusionConvAddBNReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionConvAddBNReluParam<DeviceType>, DeviceType, FusionConvAddBNReluParam<DeviceType>,
operators::ConvAddBNReluKernel<DeviceType, T>>( operators::ConvAddBNReluKernel<DeviceType, T>>(
......
...@@ -50,8 +50,7 @@ class FusionConvAddOp : public framework::OperatorWithKernel< ...@@ -50,8 +50,7 @@ class FusionConvAddOp : public framework::OperatorWithKernel<
public: public:
FusionConvAddOp(const string &type, const VariableNameMap &inputs, FusionConvAddOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, : framework::OperatorWithKernel<DeviceType,
FusionConvAddParam<DeviceType>, FusionConvAddParam<DeviceType>,
operators::ConvAddKernel<DeviceType, T>>( operators::ConvAddKernel<DeviceType, T>>(
......
...@@ -54,7 +54,7 @@ class FusionConvAddPReluOp ...@@ -54,7 +54,7 @@ class FusionConvAddPReluOp
FusionConvAddPReluOp(const string &type, const VariableNameMap &inputs, FusionConvAddPReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionConvAddPReluParam<DeviceType>, DeviceType, FusionConvAddPReluParam<DeviceType>,
operators::ConvAddPReluKernel<DeviceType, T>>(type, inputs, outputs, operators::ConvAddPReluKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -51,7 +51,7 @@ class FusionConvAddReluOp : public framework::OperatorWithKernel< ...@@ -51,7 +51,7 @@ class FusionConvAddReluOp : public framework::OperatorWithKernel<
FusionConvAddReluOp(const string &type, const VariableNameMap &inputs, FusionConvAddReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionConvAddReluParam<DeviceType>, DeviceType, FusionConvAddReluParam<DeviceType>,
operators::ConvAddReluKernel<DeviceType, T>>(type, inputs, outputs, operators::ConvAddReluKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -67,7 +67,7 @@ class FusionConvBNAddReluOp ...@@ -67,7 +67,7 @@ class FusionConvBNAddReluOp
FusionConvBNAddReluOp(const string &type, const VariableNameMap &inputs, FusionConvBNAddReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionConvBNAddReluParam<DeviceType>, DeviceType, FusionConvBNAddReluParam<DeviceType>,
operators::ConvBNAddReluKernel<DeviceType, T>>( operators::ConvBNAddReluKernel<DeviceType, T>>(
......
...@@ -56,8 +56,7 @@ class FusionConvBNOp : public framework::OperatorWithKernel< ...@@ -56,8 +56,7 @@ class FusionConvBNOp : public framework::OperatorWithKernel<
public: public:
FusionConvBNOp(const string &type, const VariableNameMap &inputs, FusionConvBNOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, FusionConvBNParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, FusionConvBNParam<DeviceType>,
operators::ConvBNKernel<DeviceType, T>>( operators::ConvBNKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -58,7 +58,7 @@ class FusionConvBNReluOp : public framework::OperatorWithKernel< ...@@ -58,7 +58,7 @@ class FusionConvBNReluOp : public framework::OperatorWithKernel<
FusionConvBNReluOp(const string &type, const VariableNameMap &inputs, FusionConvBNReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionConvBNReluParam<DeviceType>, DeviceType, FusionConvBNReluParam<DeviceType>,
operators::ConvBNReluKernel<DeviceType, T>>(type, inputs, outputs, operators::ConvBNReluKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -49,7 +49,7 @@ class FusionDeconvAddOp : public framework::OperatorWithKernel< ...@@ -49,7 +49,7 @@ class FusionDeconvAddOp : public framework::OperatorWithKernel<
FusionDeconvAddOp(const string &type, const VariableNameMap &inputs, FusionDeconvAddOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDeconvAddParam<DeviceType>, DeviceType, FusionDeconvAddParam<DeviceType>,
operators::DeconvAddKernel<DeviceType, T>>(type, inputs, outputs, operators::DeconvAddKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -51,7 +51,7 @@ class FusionDeconvAddReluOp ...@@ -51,7 +51,7 @@ class FusionDeconvAddReluOp
FusionDeconvAddReluOp(const string &type, const VariableNameMap &inputs, FusionDeconvAddReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDeconvAddReluParam<DeviceType>, DeviceType, FusionDeconvAddReluParam<DeviceType>,
operators::DeconvAddReluKernel<DeviceType, T>>( operators::DeconvAddReluKernel<DeviceType, T>>(
......
...@@ -48,7 +48,7 @@ class FusionDeconvReluOp : public framework::OperatorWithKernel< ...@@ -48,7 +48,7 @@ class FusionDeconvReluOp : public framework::OperatorWithKernel<
FusionDeconvReluOp(const string &type, const VariableNameMap &inputs, FusionDeconvReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDeconvReluParam<DeviceType>, DeviceType, FusionDeconvReluParam<DeviceType>,
operators::DeconvReluKernel<DeviceType, T>>(type, inputs, outputs, operators::DeconvReluKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -60,7 +60,7 @@ class FusionDequantAddBNOp ...@@ -60,7 +60,7 @@ class FusionDequantAddBNOp
FusionDequantAddBNOp(const std::string &type, const VariableNameMap &inputs, FusionDequantAddBNOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDequantAddBNParam<DeviceType>, DeviceType, FusionDequantAddBNParam<DeviceType>,
operators::FusionDequantAddBNKernel<DeviceType, T>>( operators::FusionDequantAddBNKernel<DeviceType, T>>(
......
...@@ -62,7 +62,7 @@ class FusionDequantAddBNReluOp ...@@ -62,7 +62,7 @@ class FusionDequantAddBNReluOp
const VariableNameMap &inputs, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDequantAddBNParam<DeviceType>, DeviceType, FusionDequantAddBNParam<DeviceType>,
operators::FusionDequantAddBNReluKernel<DeviceType, T>>( operators::FusionDequantAddBNReluKernel<DeviceType, T>>(
......
...@@ -62,7 +62,7 @@ class FusionDequantAddBNReluQuantOp ...@@ -62,7 +62,7 @@ class FusionDequantAddBNReluQuantOp
const VariableNameMap &inputs, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDequantAddBNReluQuantParam<DeviceType>, DeviceType, FusionDequantAddBNReluQuantParam<DeviceType>,
operators::FusionDequantAddBNReluQuantKernel<DeviceType, T>>( operators::FusionDequantAddBNReluQuantKernel<DeviceType, T>>(
...@@ -109,7 +109,7 @@ class FusionDequantAddBNQuantOp ...@@ -109,7 +109,7 @@ class FusionDequantAddBNQuantOp
const VariableNameMap &inputs, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDequantAddBNQuantParam<DeviceType>, DeviceType, FusionDequantAddBNQuantParam<DeviceType>,
operators::FusionDequantAddBNQuantKernel<DeviceType, T>>( operators::FusionDequantAddBNQuantKernel<DeviceType, T>>(
......
...@@ -58,7 +58,7 @@ class FusionDequantBNOp : public framework::OperatorWithKernel< ...@@ -58,7 +58,7 @@ class FusionDequantBNOp : public framework::OperatorWithKernel<
FusionDequantBNOp(const std::string &type, const VariableNameMap &inputs, FusionDequantBNOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDequantBNParam<DeviceType>, DeviceType, FusionDequantBNParam<DeviceType>,
operators::FusionDequantBNKernel<DeviceType, T>>( operators::FusionDequantBNKernel<DeviceType, T>>(
...@@ -87,7 +87,7 @@ class FusionDequantBNReluOp ...@@ -87,7 +87,7 @@ class FusionDequantBNReluOp
FusionDequantBNReluOp(const std::string &type, const VariableNameMap &inputs, FusionDequantBNReluOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDequantBNParam<DeviceType>, DeviceType, FusionDequantBNParam<DeviceType>,
operators::FusionDequantBNReluKernel<DeviceType, T>>( operators::FusionDequantBNReluKernel<DeviceType, T>>(
......
...@@ -59,7 +59,7 @@ class FusionDequantBNReluOp ...@@ -59,7 +59,7 @@ class FusionDequantBNReluOp
FusionDequantBNReluOp(const std::string &type, const VariableNameMap &inputs, FusionDequantBNReluOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDequantBNReluParam<DeviceType>, DeviceType, FusionDequantBNReluParam<DeviceType>,
operators::FusionDequantBNReluKernel<DeviceType, T>>( operators::FusionDequantBNReluKernel<DeviceType, T>>(
......
...@@ -59,7 +59,7 @@ class FusionDWConvBNReluOp ...@@ -59,7 +59,7 @@ class FusionDWConvBNReluOp
FusionDWConvBNReluOp(const string &type, const VariableNameMap &inputs, FusionDWConvBNReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionDWConvBNReluParam<DeviceType>, DeviceType, FusionDWConvBNReluParam<DeviceType>,
operators::DWConvBNReluKernel<DeviceType, T>>(type, inputs, outputs, operators::DWConvBNReluKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -17,6 +17,7 @@ limitations under the License. */ ...@@ -17,6 +17,7 @@ limitations under the License. */
#pragma once #pragma once
#include <string> #include <string>
#include <vector>
#include "framework/operator.h" #include "framework/operator.h"
#include "framework/program/program-optimize/fusion_op_register.h" #include "framework/program/program-optimize/fusion_op_register.h"
#include "operators/kernel/elementwise_add_relu_kernel.h" #include "operators/kernel/elementwise_add_relu_kernel.h"
...@@ -50,7 +51,7 @@ class FusionElementwiseAddReluOp ...@@ -50,7 +51,7 @@ class FusionElementwiseAddReluOp
FusionElementwiseAddReluOp(const string &type, const VariableNameMap &inputs, FusionElementwiseAddReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, ElementwiseAddReluParam<DeviceType>, DeviceType, ElementwiseAddReluParam<DeviceType>,
operators::ElementwiseAddReluKernel<DeviceType, T>>( operators::ElementwiseAddReluKernel<DeviceType, T>>(
......
...@@ -50,8 +50,7 @@ class FusionFcOp : public framework::OperatorWithKernel< ...@@ -50,8 +50,7 @@ class FusionFcOp : public framework::OperatorWithKernel<
public: public:
FusionFcOp(const std::string &type, const VariableNameMap &inputs, FusionFcOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, FusionFcParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, FusionFcParam<DeviceType>,
operators::FusionFcKernel<DeviceType, T>>( operators::FusionFcKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -49,8 +49,7 @@ class FusionFcReluOp : public framework::OperatorWithKernel< ...@@ -49,8 +49,7 @@ class FusionFcReluOp : public framework::OperatorWithKernel<
public: public:
FusionFcReluOp(const string &type, const VariableNameMap &inputs, FusionFcReluOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, FusionFcReluParam<DeviceType>, DeviceType, FusionFcReluParam<DeviceType>,
operators::FusionFcReluKernel<DeviceType, T>>(type, inputs, outputs, operators::FusionFcReluKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -33,7 +33,7 @@ class GruOp : public framework::OperatorWithKernel< ...@@ -33,7 +33,7 @@ class GruOp : public framework::OperatorWithKernel<
public: public:
GruOp(const std::string &type, const VariableNameMap &inputs, GruOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, GruParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, GruParam<DeviceType>,
operators::GruKernel<DeviceType, T>>( operators::GruKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -16,6 +16,7 @@ limitations under the License. */ ...@@ -16,6 +16,7 @@ limitations under the License. */
#pragma once #pragma once
#include <string>
#include "framework/operator.h" #include "framework/operator.h"
#include "operators/kernel/gru_unit_kernel.h" #include "operators/kernel/gru_unit_kernel.h"
#include "operators/op_param.h" #include "operators/op_param.h"
...@@ -30,10 +31,10 @@ class GruUnitOp : public framework::OperatorWithKernel< ...@@ -30,10 +31,10 @@ class GruUnitOp : public framework::OperatorWithKernel<
public: public:
GruUnitOp(const std::string &type, const VariableNameMap &inputs, GruUnitOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const AttributeMap &attrs, const VariableNameMap &outputs, const AttributeMap &attrs,
std::shared_ptr<Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, GruUnitParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, GruUnitParam<DeviceType>,
operators::GruUnitKernel<DeviceType, T>>( operators::GruUnitKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope){}; type, inputs, outputs, attrs, scope) {}
void InferShape() const override; void InferShape() const override;
}; };
......
...@@ -31,8 +31,7 @@ class Im2SequenceOp : public framework::OperatorWithKernel< ...@@ -31,8 +31,7 @@ class Im2SequenceOp : public framework::OperatorWithKernel<
public: public:
Im2SequenceOp(const std::string &type, const VariableNameMap &inputs, Im2SequenceOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, Im2SequenceParam<DeviceType>, DeviceType, Im2SequenceParam<DeviceType>,
operators::Im2SequenceKernel<DeviceType, T>>(type, inputs, outputs, operators::Im2SequenceKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -32,8 +32,7 @@ class IncrementOp ...@@ -32,8 +32,7 @@ class IncrementOp
public: public:
IncrementOp(const string &type, const VariableNameMap &inputs, IncrementOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, IncrementParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, IncrementParam<DeviceType>,
IncrementKernel<DeviceType, T>>( IncrementKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -31,8 +31,7 @@ class IsEmptyOp ...@@ -31,8 +31,7 @@ class IsEmptyOp
public: public:
IsEmptyOp(const string &type, const VariableNameMap &inputs, IsEmptyOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, IsEmptyParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, IsEmptyParam<DeviceType>,
IsEmptyKernel<DeviceType, T>>( IsEmptyKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -29,6 +29,13 @@ template <> ...@@ -29,6 +29,13 @@ template <>
void BeamSearchDecodeKernel<CPU, float>::Compute( void BeamSearchDecodeKernel<CPU, float>::Compute(
const BeamSearchDecodeParam<CPU> &param) { const BeamSearchDecodeParam<CPU> &param) {
// TODO(hjchen2) // TODO(hjchen2)
DLOG << "BeamSearchDecodeKernel";
param.sentence_scores_->Resize(framework::make_ddim({10}));
param.sentence_scores_->mutable_data<float>();
DLOG << "BeamSearchDecodeKernel";
param.sentence_ids_->Resize(framework::make_ddim({10}));
param.sentence_ids_->mutable_data<int64_t>();
} }
} // namespace operators } // namespace operators
......
...@@ -8,17 +8,24 @@ distributed under the License is distributed on an "AS IS" BASIS, ...@@ -8,17 +8,24 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "operators/kernel/fetch_kernel.h" #include "operators/kernel/fetch_kernel.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace operators { namespace operators {
template <> template <>
bool FetchKernel<CPU, float>::Init(FetchParam<CPU> *param) { bool FetchKernel<CPU, float>::Init(FetchParam<CPU> *param) {
return true; return true;
} }
template <> template <>
void FetchKernel<CPU, float>::Compute(const FetchParam<CPU> &param) { void FetchKernel<CPU, float>::Compute(const FetchParam<CPU> &param) {
param.Out()->ShareDataWith(*(param.InputX())); int col = param.Col();
param.Out()->at(col).ShareDataWith(*(param.InputX()));
} }
template class FetchKernel<CPU, float>; template class FetchKernel<CPU, float>;
} // namespace operators } // namespace operators
} // namespace paddle_mobile } // namespace paddle_mobile
...@@ -100,8 +100,8 @@ class SequenceExpandKernel<CPU, T> ...@@ -100,8 +100,8 @@ class SequenceExpandKernel<CPU, T>
out_lod.push_back(out_lod.back() + x_seq_len); out_lod.push_back(out_lod.back() + x_seq_len);
} }
} }
output->set_lod({out_lod});
} }
output->set_lod({out_lod});
SequenceExpandImpl<T>(*input_x, y_lod[ref_level], output); SequenceExpandImpl<T>(*input_x, y_lod[ref_level], output);
} }
}; };
......
...@@ -28,10 +28,13 @@ class SequenceSoftmaxKernel<CPU, T> ...@@ -28,10 +28,13 @@ class SequenceSoftmaxKernel<CPU, T>
bool Init(SoftmaxParam<CPU> *param) { return true; } bool Init(SoftmaxParam<CPU> *param) { return true; }
void Compute(const SoftmaxParam<CPU> &param) { void Compute(const SoftmaxParam<CPU> &param) {
const framework::LoDTensor *input = param.InputX(); param.Out()->mutable_data<float>();
framework::LoDTensor *output = param.Out(); /*
math::SequenceSoftmaxFuntor<CPU, T> sequence_softmax; const framework::LoDTensor *input = param.InputX();
sequence_softmax(input, output); framework::LoDTensor *output = param.Out();
math::SequenceSoftmaxFuntor<CPU, T> sequence_softmax;
sequence_softmax(input, output);
*/
} }
}; };
......
...@@ -51,6 +51,11 @@ void ReadFromArrayKernel<CPU, float>::Compute( ...@@ -51,6 +51,11 @@ void ReadFromArrayKernel<CPU, float>::Compute(
int64_t offset = param.index_->data<int64_t>()[0]; int64_t offset = param.index_->data<int64_t>()[0];
if (offset < param.input_->size()) { if (offset < param.input_->size()) {
TensorCopy(param.input_->at(offset), param.output_); TensorCopy(param.input_->at(offset), param.output_);
param.output_->set_lod(param.input_->at(offset).lod());
} else {
PADDLE_MOBILE_THROW_EXCEPTION(
"Can not read tensor which index is `%d` since it only has `%d` inputs",
offset, param.input_->size());
} }
} }
#endif // READ_FROM_ARRAY_OP #endif // READ_FROM_ARRAY_OP
......
...@@ -26,11 +26,12 @@ class StepExecutor { ...@@ -26,11 +26,12 @@ class StepExecutor {
public: public:
StepExecutor(const framework::BlockDesc *block, framework::Scope *scope) StepExecutor(const framework::BlockDesc *block, framework::Scope *scope)
: scope_(std::shared_ptr<framework::Scope>(scope)) { : scope_(scope) {
std::vector<std::shared_ptr<framework::OpDesc>> ops = block->Ops(); std::vector<std::shared_ptr<framework::OpDesc>> ops = block->Ops();
ops_of_block_.resize(ops.size()); ops_of_block_.resize(ops.size());
for (int i = 0; i < ops.size(); ++i) { for (int i = 0; i < ops.size(); ++i) {
std::shared_ptr<framework::OpDesc> op_desc = ops[i]; std::shared_ptr<framework::OpDesc> op_desc = ops[i];
DLOG << "create op: " << op_desc->Type();
auto op_handler = framework::OpRegistry<CPU>::CreateOp( auto op_handler = framework::OpRegistry<CPU>::CreateOp(
op_desc->Type(), op_desc->GetInputs(), op_desc->GetOutputs(), op_desc->Type(), op_desc->GetInputs(), op_desc->GetOutputs(),
op_desc->GetAttrMap(), scope_); op_desc->GetAttrMap(), scope_);
...@@ -40,15 +41,13 @@ class StepExecutor { ...@@ -40,15 +41,13 @@ class StepExecutor {
void Run() { void Run() {
for (auto &op_handler : ops_of_block_) { for (auto &op_handler : ops_of_block_) {
DLOG << "run op: " << op_handler->Type();
op_handler->InferShape(); op_handler->InferShape();
op_handler->Run(); op_handler->Run();
DLOG << "run op finish";
} }
} }
private: private:
std::shared_ptr<framework::Scope> scope_; framework::Scope *scope_;
std::vector<OperatorPtr> ops_of_block_; std::vector<OperatorPtr> ops_of_block_;
}; };
...@@ -59,7 +58,6 @@ bool WhileKernel<CPU, float>::Init(WhileParam<CPU> *param) { ...@@ -59,7 +58,6 @@ bool WhileKernel<CPU, float>::Init(WhileParam<CPU> *param) {
template <> template <>
void WhileKernel<CPU, float>::Compute(const WhileParam<CPU> &param) { void WhileKernel<CPU, float>::Compute(const WhileParam<CPU> &param) {
// TODO(hjchen2)
auto &current_scope = param.scope_->NewScope(); auto &current_scope = param.scope_->NewScope();
StepExecutor executor(param.sub_block_, &current_scope); StepExecutor executor(param.sub_block_, &current_scope);
while (param.cond_->data<bool>()[0]) { while (param.cond_->data<bool>()[0]) {
......
...@@ -25,11 +25,11 @@ template <typename P> ...@@ -25,11 +25,11 @@ template <typename P>
void IncrementCompute(const IncrementParam<CPU> &param) { void IncrementCompute(const IncrementParam<CPU> &param) {
const framework::Tensor *input = param.InputX(); const framework::Tensor *input = param.InputX();
framework::Tensor *out = param.Out(); framework::Tensor *out = param.Out();
int step = param.Step(); float step = param.Step();
out->mutable_data<P>(); out->mutable_data<int64_t>();
const P *input_data = input->data<P>(); const int64_t *input_data = input->data<int64_t>();
P *out_data = out->data<P>(); int64_t *out_data = out->data<int64_t>();
*out_data = *input_data + step; *out_data = *input_data + step;
} }
......
...@@ -33,7 +33,7 @@ class LookupOp : public framework::OperatorWithKernel< ...@@ -33,7 +33,7 @@ class LookupOp : public framework::OperatorWithKernel<
public: public:
LookupOp(const std::string &type, const VariableNameMap &inputs, LookupOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, LookupParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, LookupParam<DeviceType>,
operators::LookupKernel<DeviceType, T>>( operators::LookupKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -31,7 +31,7 @@ class LrnOp : public framework::OperatorWithKernel< ...@@ -31,7 +31,7 @@ class LrnOp : public framework::OperatorWithKernel<
public: public:
LrnOp(const string &type, const VariableNameMap &inputs, LrnOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, LrnParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, LrnParam<DeviceType>,
operators::LrnKernel<DeviceType, T>>( operators::LrnKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -47,26 +47,27 @@ void DepthwiseConv3x3(const framework::Tensor *input, ...@@ -47,26 +47,27 @@ void DepthwiseConv3x3(const framework::Tensor *input,
const int output_channel_stride = output_height * output_width; const int output_channel_stride = output_height * output_width;
const int filter_channel_stride = 9; const int filter_channel_stride = 9;
const float *input_data = input->data<float>(); const float *input_ptr = input->data<float>();
const float *filter_data = filter->data<float>(); const float *filter_ptr = filter->data<float>();
if (if_bias) { if (if_bias) {
math::expand_bias(*bias, 1, output->dims()); math::expand_bias(*bias, 1, output->dims());
output->ShareDataWith(*bias); output->ShareDataWith(*bias);
} }
float *output_data = output->mutable_data<float>(); float *output_ptr = output->mutable_data<float>();
const int input_batch_stride = output_channels * input_channel_stride; const float *pos1, *pos2, *pos3, *filter1, *filter2, *filter3, *output_ptr2;
const int output_batch_stride = output_channels * output_channel_stride;
const int filter_batch_stride = output_channels * output_channel_stride;
const float *pos1, *pos2, *pos3, *filter1, *filter2, *filter3, *output_ptr;
int hstart, wstart, hend, wend; int hstart, wstart, hend, wend;
float result; float result;
for (int i = 0; i < batch_size; ++i) { for (int i = 0; i < batch_size; ++i) {
#pragma omp parallel for
for (int c = 0; c < output_channels; ++c) { for (int c = 0; c < output_channels; ++c) {
filter1 = filter_data; const float *input_data =
input_ptr + (i * output_channels + c) * input_channel_stride;
float *output_data =
output_ptr + (i * output_channels + c) * output_channel_stride;
filter1 = filter_ptr + c * filter_channel_stride;
filter2 = filter1 + 3; filter2 = filter1 + 3;
filter3 = filter2 + 3; filter3 = filter2 + 3;
for (int ph = 0; ph < output_height; ph++) { for (int ph = 0; ph < output_height; ph++) {
for (int pw = 0; pw < output_width; pw++) { for (int pw = 0; pw < output_width; pw++) {
hstart = ph * stride_height - padding_height; hstart = ph * stride_height - padding_height;
...@@ -80,7 +81,7 @@ void DepthwiseConv3x3(const framework::Tensor *input, ...@@ -80,7 +81,7 @@ void DepthwiseConv3x3(const framework::Tensor *input,
pos1 = input_data + hstart * input_width + wstart; pos1 = input_data + hstart * input_width + wstart;
pos2 = input_data + (hstart + 1) * input_width + wstart; pos2 = input_data + (hstart + 1) * input_width + wstart;
pos3 = input_data + (hstart + 2) * input_width + wstart; pos3 = input_data + (hstart + 2) * input_width + wstart;
output_ptr = output_data + ph * output_width + pw; output_ptr2 = output_data + ph * output_width + pw;
if (hend - hstart != 3 || wend - wstart != 3) { if (hend - hstart != 3 || wend - wstart != 3) {
result = 0; result = 0;
...@@ -230,7 +231,7 @@ void DepthwiseConv3x3(const framework::Tensor *input, ...@@ -230,7 +231,7 @@ void DepthwiseConv3x3(const framework::Tensor *input,
: [input_data] "r"(input_data), [pos1] "r"(pos1), : [input_data] "r"(input_data), [pos1] "r"(pos1),
[pos2] "r"(pos2), [pos3] "r"(pos3), [filter1] "r"(filter1), [pos2] "r"(pos2), [pos3] "r"(pos3), [filter1] "r"(filter1),
[filter2] "r"(filter2), [filter3] "r"(filter3), [filter2] "r"(filter2), [filter3] "r"(filter3),
[output_ptr] "r"(output_ptr), [zero] "r"(zero) [output_ptr] "r"(output_ptr2), [zero] "r"(zero)
: "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6"); : "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6");
#endif // __aarch64__ #endif // __aarch64__
#else #else
...@@ -239,12 +240,7 @@ void DepthwiseConv3x3(const framework::Tensor *input, ...@@ -239,12 +240,7 @@ void DepthwiseConv3x3(const framework::Tensor *input,
} }
} }
} }
input_data += input_channel_stride;
output_data += output_channel_stride;
filter_data += filter_channel_stride;
} }
input_data += input_batch_stride;
output_data += output_batch_stride;
} }
} }
......
...@@ -31,7 +31,7 @@ class MulOp : public framework::OperatorWithKernel< ...@@ -31,7 +31,7 @@ class MulOp : public framework::OperatorWithKernel<
public: public:
MulOp(const std::string &type, const VariableNameMap &inputs, MulOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, MulParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, MulParam<DeviceType>,
operators::MulKernel<DeviceType, T>>( operators::MulKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,8 +34,7 @@ class MultiClassNMSOp : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class MultiClassNMSOp : public framework::OperatorWithKernel<
public: public:
MultiClassNMSOp(const std::string &type, const VariableNameMap &inputs, MultiClassNMSOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, MultiClassNMSParam<DeviceType>, DeviceType, MultiClassNMSParam<DeviceType>,
operators::MultiClassNMSKernel<DeviceType, T>>( operators::MultiClassNMSKernel<DeviceType, T>>(
......
...@@ -31,7 +31,7 @@ class NormOp ...@@ -31,7 +31,7 @@ class NormOp
public: public:
NormOp(const string &type, const VariableNameMap &inputs, NormOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, NormParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, NormParam<DeviceType>,
NormKernel<DeviceType, T>>( NormKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -1198,20 +1198,19 @@ class FetchParam : public OpParam { ...@@ -1198,20 +1198,19 @@ class FetchParam : public OpParam {
public: public:
FetchParam(const VariableNameMap &inputs, const VariableNameMap &outputs, FetchParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
const AttributeMap &attrs, const Scope &scope) { const AttributeMap &attrs, const Scope &scope) {
input_x_ = InputXFrom<GType>(inputs, scope); input_x_ = InputXFrom<framework::LoDTensor>(inputs, scope);
out_ = OutFrom(outputs, scope); out_ = OutFrom<framework::LoDTensorArray>(outputs, scope);
col_ = GetAttr<int>("col", attrs);
} }
const RType *InputX() const { return input_x_; } const framework::LoDTensor *InputX() const { return input_x_; }
Tensor *Out() const { return out_; } framework::LoDTensorArray *Out() const { return out_; }
const int Col() const { return col_; }
static Tensor *OutFrom(const VariableNameMap &outputs, const Scope &scope) {
return GetVarValue<LoDTensor>("Out", outputs, scope);
}
private: private:
RType *input_x_; framework::LoDTensor *input_x_;
Tensor *out_; framework::LoDTensorArray *out_;
int col_;
#ifdef PADDLE_MOBILE_FPGA #ifdef PADDLE_MOBILE_FPGA
private: private:
...@@ -2664,9 +2663,9 @@ class TopKParam : public OpParam { ...@@ -2664,9 +2663,9 @@ class TopKParam : public OpParam {
} }
public: public:
RType *input_; GType *input_;
RType *output_; GType *output_;
RType *indices_; GType *indices_;
int k_; int k_;
}; };
#endif // TOP_K_OP #endif // TOP_K_OP
......
...@@ -36,7 +36,7 @@ class PolygonBoxTransformOp ...@@ -36,7 +36,7 @@ class PolygonBoxTransformOp
PolygonBoxTransformOp(const std::string &type, const VariableNameMap &inputs, PolygonBoxTransformOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, PolygonBoxTransformParam<DeviceType>, DeviceType, PolygonBoxTransformParam<DeviceType>,
operators::PolygonBoxTransformKernel<DeviceType, T>>( operators::PolygonBoxTransformKernel<DeviceType, T>>(
......
...@@ -24,19 +24,17 @@ limitations under the License. */ ...@@ -24,19 +24,17 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace operators { namespace operators {
using framework::AttributeMap;
using framework::OperatorWithKernel;
using framework::Scope;
using std::string;
template <typename DeviceType, typename T> template <typename DeviceType, typename T>
class PoolOp : public OperatorWithKernel<DeviceType, PoolParam<DeviceType>, class PoolOp : public framework::OperatorWithKernel<
operators::PoolKernel<DeviceType, T>> { DeviceType, PoolParam<DeviceType>,
operators::PoolKernel<DeviceType, T>> {
public: public:
PoolOp(const string &type, const VariableNameMap &inputs, PoolOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const AttributeMap &attrs, const VariableNameMap &outputs, const AttributeMap &attrs,
std::shared_ptr<Scope> scope) framework::Scope *scope)
: OperatorWithKernel<DeviceType, PoolParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, PoolParam<DeviceType>,
operators::PoolKernel<DeviceType, T>>( operators::PoolKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
void InferShape() const override; void InferShape() const override;
......
...@@ -34,7 +34,7 @@ class PReluOp : public framework::OperatorWithKernel< ...@@ -34,7 +34,7 @@ class PReluOp : public framework::OperatorWithKernel<
public: public:
PReluOp(const std::string &type, const VariableNameMap &inputs, PReluOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, PReluParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, PReluParam<DeviceType>,
operators::PReluKernel<DeviceType, T>>( operators::PReluKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,8 +34,7 @@ class PriorBoxOp : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class PriorBoxOp : public framework::OperatorWithKernel<
public: public:
PriorBoxOp(const std::string &type, const VariableNameMap &inputs, PriorBoxOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, PriorBoxParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, PriorBoxParam<DeviceType>,
operators::PriorBoxKernel<DeviceType, T>>( operators::PriorBoxKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -31,8 +31,7 @@ class QuantizeOp : public framework::OperatorWithKernel< ...@@ -31,8 +31,7 @@ class QuantizeOp : public framework::OperatorWithKernel<
public: public:
QuantizeOp(const std::string &type, const VariableNameMap &inputs, QuantizeOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, QuantizeParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, QuantizeParam<DeviceType>,
operators::QuantizeKernel<DeviceType, T>>( operators::QuantizeKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,8 +34,7 @@ class Reshape2Op : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class Reshape2Op : public framework::OperatorWithKernel<
public: public:
Reshape2Op(const std::string &type, const VariableNameMap &inputs, Reshape2Op(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, Reshape2Param<DeviceType>, : framework::OperatorWithKernel<DeviceType, Reshape2Param<DeviceType>,
operators::Reshape2Kernel<DeviceType, T>>( operators::Reshape2Kernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,8 +34,7 @@ class ReshapeOp : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class ReshapeOp : public framework::OperatorWithKernel<
public: public:
ReshapeOp(const std::string &type, const VariableNameMap &inputs, ReshapeOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, ReshapeParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, ReshapeParam<DeviceType>,
operators::ReshapeKernel<DeviceType, T>>( operators::ReshapeKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,7 +34,7 @@ class ResizeOp : public framework::OperatorWithKernel< ...@@ -34,7 +34,7 @@ class ResizeOp : public framework::OperatorWithKernel<
public: public:
ResizeOp(const std::string &type, const VariableNameMap &inputs, ResizeOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, ResizeParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, ResizeParam<DeviceType>,
operators::ResizeKernel<DeviceType, T>>( operators::ResizeKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,7 +34,7 @@ class ScaleOp : public framework::OperatorWithKernel< ...@@ -34,7 +34,7 @@ class ScaleOp : public framework::OperatorWithKernel<
public: public:
ScaleOp(const std::string &type, const VariableNameMap &inputs, ScaleOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, ScaleParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, ScaleParam<DeviceType>,
operators::ScaleKernel<DeviceType, T>>( operators::ScaleKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -32,7 +32,7 @@ class SequenceExpandOp : public framework::OperatorWithKernel< ...@@ -32,7 +32,7 @@ class SequenceExpandOp : public framework::OperatorWithKernel<
SequenceExpandOp(const std::string &type, const VariableNameMap &inputs, SequenceExpandOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, SequenceExpandParam<DeviceType>, DeviceType, SequenceExpandParam<DeviceType>,
operators::SequenceExpandKernel<DeviceType, T>>( operators::SequenceExpandKernel<DeviceType, T>>(
......
...@@ -31,8 +31,7 @@ class SequencePoolOp : public framework::OperatorWithKernel< ...@@ -31,8 +31,7 @@ class SequencePoolOp : public framework::OperatorWithKernel<
public: public:
SequencePoolOp(const std::string &type, const VariableNameMap &inputs, SequencePoolOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, SequencePoolParam<DeviceType>, DeviceType, SequencePoolParam<DeviceType>,
operators::SequencePoolKernel<DeviceType, T>>(type, inputs, outputs, operators::SequencePoolKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -32,7 +32,7 @@ class SequenceSoftmaxOp : public framework::OperatorWithKernel< ...@@ -32,7 +32,7 @@ class SequenceSoftmaxOp : public framework::OperatorWithKernel<
SequenceSoftmaxOp(const std::string &type, const VariableNameMap &inputs, SequenceSoftmaxOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, SoftmaxParam<DeviceType>, DeviceType, SoftmaxParam<DeviceType>,
operators::SequenceSoftmaxKernel<DeviceType, T>>( operators::SequenceSoftmaxKernel<DeviceType, T>>(
......
...@@ -34,7 +34,7 @@ class ShapeOp : public framework::OperatorWithKernel< ...@@ -34,7 +34,7 @@ class ShapeOp : public framework::OperatorWithKernel<
public: public:
ShapeOp(const std::string &type, const VariableNameMap &inputs, ShapeOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, ShapeParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, ShapeParam<DeviceType>,
operators::ShapeKernel<DeviceType, T>>( operators::ShapeKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,7 +34,7 @@ class SliceOp : public framework::OperatorWithKernel< ...@@ -34,7 +34,7 @@ class SliceOp : public framework::OperatorWithKernel<
public: public:
SliceOp(const std::string &type, const VariableNameMap &inputs, SliceOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, SliceParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, SliceParam<DeviceType>,
operators::SliceKernel<DeviceType, T>>( operators::SliceKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -31,8 +31,7 @@ class SoftmaxOp : public framework::OperatorWithKernel< ...@@ -31,8 +31,7 @@ class SoftmaxOp : public framework::OperatorWithKernel<
public: public:
SoftmaxOp(const std::string &type, const VariableNameMap &inputs, SoftmaxOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel<DeviceType, SoftmaxParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, SoftmaxParam<DeviceType>,
operators::SoftmaxKernel<DeviceType, T>>( operators::SoftmaxKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,7 +34,7 @@ class SplitOp : public framework::OperatorWithKernel< ...@@ -34,7 +34,7 @@ class SplitOp : public framework::OperatorWithKernel<
public: public:
SplitOp(const std::string &type, const VariableNameMap &inputs, SplitOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, SplitParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, SplitParam<DeviceType>,
operators::SplitKernel<DeviceType, T>>( operators::SplitKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -30,7 +30,7 @@ class SumOp : public framework::OperatorWithKernel< ...@@ -30,7 +30,7 @@ class SumOp : public framework::OperatorWithKernel<
public: public:
SumOp(const string &type, const VariableNameMap &inputs, SumOp(const string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, SumParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, SumParam<DeviceType>,
operators::SumKernel<DeviceType, T>>( operators::SumKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -26,7 +26,11 @@ void TopKOp<DeviceType, T>::InferShape() const { ...@@ -26,7 +26,11 @@ void TopKOp<DeviceType, T>::InferShape() const {
// should check k <= dims[-1] && k >= 1 // should check k <= dims[-1] && k >= 1
dims[dims.size() - 1] = k; dims[dims.size() - 1] = k;
this->param_.output_->Resize(dims); this->param_.output_->Resize(dims);
// this->param_.output_->set_lod(this->param_.input_->lod());
this->param_.output_->set_lod({{0, 1}});
this->param_.indices_->Resize(dims); this->param_.indices_->Resize(dims);
// this->param_.indices_->set_lod(this->param_.input_->lod());
this->param_.indices_->set_lod({{0, 1}});
} }
} // namespace operators } // namespace operators
......
...@@ -31,7 +31,7 @@ class TopKOp : public framework::OperatorWithKernel< ...@@ -31,7 +31,7 @@ class TopKOp : public framework::OperatorWithKernel<
public: public:
TopKOp(const std::string &type, const VariableNameMap &inputs, TopKOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const framework::AttributeMap &attrs, const VariableNameMap &outputs, const framework::AttributeMap &attrs,
std::shared_ptr<framework::Scope> scope) framework::Scope *scope)
: framework::OperatorWithKernel<DeviceType, TopKParam<DeviceType>, : framework::OperatorWithKernel<DeviceType, TopKParam<DeviceType>,
operators::TopKKernel<DeviceType, T>>( operators::TopKKernel<DeviceType, T>>(
type, inputs, outputs, attrs, scope) {} type, inputs, outputs, attrs, scope) {}
......
...@@ -34,8 +34,7 @@ class Transpose2Op : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class Transpose2Op : public framework::OperatorWithKernel<
public: public:
Transpose2Op(const std::string &type, const VariableNameMap &inputs, Transpose2Op(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, Transpose2Param<DeviceType>, DeviceType, Transpose2Param<DeviceType>,
operators::Transpose2Kernel<DeviceType, T>>(type, inputs, outputs, operators::Transpose2Kernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -34,8 +34,7 @@ class TransposeOp : public framework::OperatorWithKernel< ...@@ -34,8 +34,7 @@ class TransposeOp : public framework::OperatorWithKernel<
public: public:
TransposeOp(const std::string &type, const VariableNameMap &inputs, TransposeOp(const std::string &type, const VariableNameMap &inputs,
const VariableNameMap &outputs, const VariableNameMap &outputs,
const framework::AttributeMap &attrs, const framework::AttributeMap &attrs, framework::Scope *scope)
std::shared_ptr<framework::Scope> scope)
: framework::OperatorWithKernel< : framework::OperatorWithKernel<
DeviceType, TransposeParam<DeviceType>, DeviceType, TransposeParam<DeviceType>,
operators::TransposeKernel<DeviceType, T>>(type, inputs, outputs, operators::TransposeKernel<DeviceType, T>>(type, inputs, outputs,
......
...@@ -69,7 +69,7 @@ class Executor4Test : public Executor<DeviceType> { ...@@ -69,7 +69,7 @@ class Executor4Test : public Executor<DeviceType> {
std::shared_ptr<paddle_mobile::framework::OperatorBase<DeviceType>> std::shared_ptr<paddle_mobile::framework::OperatorBase<DeviceType>>
op_ptr = paddle_mobile::framework::OpRegistry<DeviceType>::CreateOp( op_ptr = paddle_mobile::framework::OpRegistry<DeviceType>::CreateOp(
op->Type(), op->GetInputs(), op->GetOutputs(), op->GetAttrMap(), op->Type(), op->GetInputs(), op->GetOutputs(), op->GetAttrMap(),
this->program_.scope); this->program_.scope.get());
this->ops_of_block0_.push_back(op_ptr); this->ops_of_block0_.push_back(op_ptr);
break; break;
} }
...@@ -86,7 +86,7 @@ class Executor4Test : public Executor<DeviceType> { ...@@ -86,7 +86,7 @@ class Executor4Test : public Executor<DeviceType> {
const vector<string> &input_names, const vector<string> &input_names,
const vector<string> &output_names, const vector<string> &output_names,
const vector<DDim> &ddims) { const vector<DDim> &ddims) {
auto scope = this->program_.scope; auto scope = this->program_.scope.get();
size_t input_size = input_names.size(); size_t input_size = input_names.size();
size_t out_size = output_names.size(); size_t out_size = output_names.size();
...@@ -119,7 +119,7 @@ class Executor4Test : public Executor<DeviceType> { ...@@ -119,7 +119,7 @@ class Executor4Test : public Executor<DeviceType> {
std::shared_ptr<Tensor> Predict(const Tensor &t, string input, string output, std::shared_ptr<Tensor> Predict(const Tensor &t, string input, string output,
const DDim &dDim) { const DDim &dDim) {
auto scope = this->program_.scope; auto scope = this->program_.scope.get();
Variable *g_feed_value = scope->Var(input); Variable *g_feed_value = scope->Var(input);
auto tensor = g_feed_value->GetMutable<LoDTensor>(); auto tensor = g_feed_value->GetMutable<LoDTensor>();
tensor->ShareDataWith(t); tensor->ShareDataWith(t);
......
...@@ -88,8 +88,8 @@ int TestBatchNormOp(const std::vector<int> input_shape) { ...@@ -88,8 +88,8 @@ int TestBatchNormOp(const std::vector<int> input_shape) {
attrs["epsilon"].Set<float>(eps); attrs["epsilon"].Set<float>(eps);
attrs["momentum"].Set<float>(0.f); attrs["momentum"].Set<float>(0.f);
auto *op = new operators::BatchNormOp<CPU, float>("batch_norm", inputs, auto *op = new operators::BatchNormOp<CPU, float>(
outputs, attrs, scope); "batch_norm", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -49,7 +49,7 @@ class TestBoxCoderOp { ...@@ -49,7 +49,7 @@ class TestBoxCoderOp {
std::shared_ptr<operators::BoxCoderOp<Dtype, float>> boxcoder = std::shared_ptr<operators::BoxCoderOp<Dtype, float>> boxcoder =
std::make_shared<operators::BoxCoderOp<Dtype, float>>( std::make_shared<operators::BoxCoderOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(boxcoder); ops_of_block_[*block_desc.get()].push_back(boxcoder);
} }
} }
...@@ -59,7 +59,7 @@ class TestBoxCoderOp { ...@@ -59,7 +59,7 @@ class TestBoxCoderOp {
std::shared_ptr<Tensor> predict_boxcoder(const Tensor &t1, const Tensor &t2, std::shared_ptr<Tensor> predict_boxcoder(const Tensor &t1, const Tensor &t2,
const Tensor &t3) { const Tensor &t3) {
// feed // feed
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *prior_box = scope->Var("concat_0.tmp_0"); Variable *prior_box = scope->Var("concat_0.tmp_0");
auto tensor_x1 = prior_box->GetMutable<LoDTensor>(); auto tensor_x1 = prior_box->GetMutable<LoDTensor>();
tensor_x1->ShareDataWith(t1); tensor_x1->ShareDataWith(t1);
......
...@@ -81,8 +81,8 @@ int TestCastOp(const std::vector<int> input_shape) { ...@@ -81,8 +81,8 @@ int TestCastOp(const std::vector<int> input_shape) {
framework::AttributeMap attrs; framework::AttributeMap attrs;
attrs["in_dtype"].Set<int>(TypeInt<Itype>()); attrs["in_dtype"].Set<int>(TypeInt<Itype>());
attrs["out_dtype"].Set<int>(TypeInt<Otype>()); attrs["out_dtype"].Set<int>(TypeInt<Otype>());
auto *op = auto *op = new operators::CastOp<CPU, float>("cast", inputs, outputs, attrs,
new operators::CastOp<CPU, float>("cast", inputs, outputs, attrs, scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -27,7 +27,7 @@ using framework::Scope; ...@@ -27,7 +27,7 @@ using framework::Scope;
using framework::make_ddim; using framework::make_ddim;
template <typename T> template <typename T>
void concat(const std::vector<LoDTensor> &input, LoDTensor &output, int axis) { void concat(const std::vector<LoDTensor> &input, LoDTensor *output, int axis) {
int num = input.size(); int num = input.size();
int rows = 1; int rows = 1;
...@@ -45,7 +45,7 @@ void concat(const std::vector<LoDTensor> &input, LoDTensor &output, int axis) { ...@@ -45,7 +45,7 @@ void concat(const std::vector<LoDTensor> &input, LoDTensor &output, int axis) {
} }
// computation // computation
auto output_data = output.data<T>(); auto output_data = output->data<T>();
int col_idx = 0; int col_idx = 0;
for (int j = 0; j < num; ++j) { for (int j = 0; j < num; ++j) {
int col_len = input_cols[j]; int col_len = input_cols[j];
...@@ -99,14 +99,14 @@ int TestConcatOP() { ...@@ -99,14 +99,14 @@ int TestConcatOP() {
attrs["axis"].Set<int>(axis_v); attrs["axis"].Set<int>(axis_v);
auto *op = new operators::ConcatOp<CPU, float>("concat", inputs, outputs, auto *op = new operators::ConcatOp<CPU, float>("concat", inputs, outputs,
attrs, scope); attrs, scope.get());
op->InferShape(); op->InferShape();
op->Run(); op->Run();
auto output = output_var->template Get<framework::LoDTensor>(); auto output = output_var->template Get<framework::LoDTensor>();
const T *output_data = output->data<T>(); const T *output_data = output->data<T>();
LoDTensor output_cmp; LoDTensor output_cmp;
output_cmp.mutable_data<T>(output_shape); output_cmp.mutable_data<T>(output_shape);
concat<T>(input_tensors, output_cmp, axis_v); concat<T>(input_tensors, &output_cmp, axis_v);
const T *output_cmp_data = output_cmp.data<T>(); const T *output_cmp_data = output_cmp.data<T>();
// compare // compare
int eq = 0; int eq = 0;
......
...@@ -84,7 +84,7 @@ int TestConvBnReluOp(int in_channels, int in_height, int in_width, ...@@ -84,7 +84,7 @@ int TestConvBnReluOp(int in_channels, int in_height, int in_width,
attrs["epsilon"].Set<float>(1e-6); attrs["epsilon"].Set<float>(1e-6);
attrs["momentum"].Set<float>(0.f); attrs["momentum"].Set<float>(0.f);
auto *op = new operators::FusionConvBNReluOp<CPU, float>( auto *op = new operators::FusionConvBNReluOp<CPU, float>(
"fusion_conv_bn_relu", inputs, outputs, attrs, scope); "fusion_conv_bn_relu", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
......
...@@ -182,7 +182,7 @@ int TestConvOp(int in_channels, int in_height, int in_width, int out_channels, ...@@ -182,7 +182,7 @@ int TestConvOp(int in_channels, int in_height, int in_width, int out_channels,
attrs["groups"].Set<int>(groups); attrs["groups"].Set<int>(groups);
auto *op = new operators::ConvOp<CPU, float>("conv2d", inputs, outputs, attrs, auto *op = new operators::ConvOp<CPU, float>("conv2d", inputs, outputs, attrs,
scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
// struct timespec ts_begin, ts_end; // struct timespec ts_begin, ts_end;
......
...@@ -50,8 +50,8 @@ int TestDequqntizeOp() { ...@@ -50,8 +50,8 @@ int TestDequqntizeOp() {
framework::AttributeMap attrs; framework::AttributeMap attrs;
attrs["weight_scale"].Set<float>(1.74); attrs["weight_scale"].Set<float>(1.74);
auto* op = new operators::DequantizeOp<CPU, float>("dequantize", inputs, auto* op = new operators::DequantizeOp<CPU, float>(
outputs, attrs, scope); "dequantize", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Run(); op->Run();
auto output = output_var->template Get<framework::LoDTensor>(); auto output = output_var->template Get<framework::LoDTensor>();
......
...@@ -87,7 +87,7 @@ int TestDWConvAddBnReluOp(int in_channels, int in_height, int in_width, ...@@ -87,7 +87,7 @@ int TestDWConvAddBnReluOp(int in_channels, int in_height, int in_width,
attrs["momentum"].Set<float>(0.f); attrs["momentum"].Set<float>(0.f);
auto *op = new operators::FusionDWConvBNReluOp<CPU, float>( auto *op = new operators::FusionDWConvBNReluOp<CPU, float>(
"fusion_dwconv_bn_relu", inputs, outputs, attrs, scope); "fusion_dwconv_bn_relu", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
......
...@@ -47,7 +47,7 @@ class TestElementwiseSubOp { ...@@ -47,7 +47,7 @@ class TestElementwiseSubOp {
std::shared_ptr<operators::ElementwiseSubOp<Dtype, float>> lrn = std::shared_ptr<operators::ElementwiseSubOp<Dtype, float>> lrn =
std::make_shared<operators::ElementwiseSubOp<Dtype, float>>( std::make_shared<operators::ElementwiseSubOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(lrn); ops_of_block_[*block_desc.get()].push_back(lrn);
} }
} }
...@@ -56,7 +56,7 @@ class TestElementwiseSubOp { ...@@ -56,7 +56,7 @@ class TestElementwiseSubOp {
std::shared_ptr<Tensor> predict_bn(const Tensor &t1, const Tensor &t2) { std::shared_ptr<Tensor> predict_bn(const Tensor &t1, const Tensor &t2) {
// feed // feed
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *x1_feed_value = scope->Var("tmp_0"); Variable *x1_feed_value = scope->Var("tmp_0");
auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>(); auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>();
tensor_x1->ShareDataWith(t1); tensor_x1->ShareDataWith(t1);
......
...@@ -47,7 +47,7 @@ class TestFillConstantOp { ...@@ -47,7 +47,7 @@ class TestFillConstantOp {
std::shared_ptr<operators::FillConstantOp<Dtype, float>> op_ptr = std::shared_ptr<operators::FillConstantOp<Dtype, float>> op_ptr =
std::make_shared<operators::FillConstantOp<Dtype, float>>( std::make_shared<operators::FillConstantOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(op_ptr); ops_of_block_[*block_desc.get()].push_back(op_ptr);
} }
} }
...@@ -55,7 +55,7 @@ class TestFillConstantOp { ...@@ -55,7 +55,7 @@ class TestFillConstantOp {
} }
std::shared_ptr<Tensor> predict() { std::shared_ptr<Tensor> predict() {
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *output = scope->Var(output_var_name); Variable *output = scope->Var(output_var_name);
auto *output_tensor = output->GetMutable<LoDTensor>(); auto *output_tensor = output->GetMutable<LoDTensor>();
......
...@@ -103,7 +103,7 @@ int TestFcOP() { ...@@ -103,7 +103,7 @@ int TestFcOP() {
attrs["axis"].Set<int>(1); attrs["axis"].Set<int>(1);
operators::OperatorBase<CPU> *op = nullptr; operators::OperatorBase<CPU> *op = nullptr;
op = new operators::FusionFcOp<CPU, T>("fusion_fc", inputs, outputs, attrs, op = new operators::FusionFcOp<CPU, T>("fusion_fc", inputs, outputs, attrs,
scope); scope.get());
op->InferShape(); op->InferShape();
op->Run(); op->Run();
auto output = output_var->template Get<framework::LoDTensor>(); auto output = output_var->template Get<framework::LoDTensor>();
......
...@@ -71,8 +71,8 @@ int TestGruOp(int in_channels, int out_channels, std::string opname) { ...@@ -71,8 +71,8 @@ int TestGruOp(int in_channels, int out_channels, std::string opname) {
attrs["gate_activation"].SetString(std::string("sigmoid")); attrs["gate_activation"].SetString(std::string("sigmoid"));
attrs["is_reverse"].Set<bool>(false); attrs["is_reverse"].Set<bool>(false);
auto *op = auto *op = new operators::GruOp<CPU, float>("gru", inputs, outputs, attrs,
new operators::GruOp<CPU, float>("gru", inputs, outputs, attrs, scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
......
...@@ -47,7 +47,7 @@ class TestIm2SequenceOp { ...@@ -47,7 +47,7 @@ class TestIm2SequenceOp {
std::shared_ptr<operators::Im2SequenceOp<Dtype, float>> lrn = std::shared_ptr<operators::Im2SequenceOp<Dtype, float>> lrn =
std::make_shared<operators::Im2SequenceOp<Dtype, float>>( std::make_shared<operators::Im2SequenceOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(lrn); ops_of_block_[*block_desc.get()].push_back(lrn);
} }
} }
...@@ -56,7 +56,7 @@ class TestIm2SequenceOp { ...@@ -56,7 +56,7 @@ class TestIm2SequenceOp {
std::shared_ptr<Tensor> predict_bn(const Tensor &t1) { std::shared_ptr<Tensor> predict_bn(const Tensor &t1) {
// feed // feed
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *x1_feed_value = scope->Var("conv2d_19.tmp_1"); Variable *x1_feed_value = scope->Var("conv2d_19.tmp_1");
auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>(); auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>();
tensor_x1->ShareDataWith(t1); tensor_x1->ShareDataWith(t1);
......
...@@ -41,8 +41,8 @@ int TestIncrementOp(const std::vector<int> input_shape, int step) { ...@@ -41,8 +41,8 @@ int TestIncrementOp(const std::vector<int> input_shape, int step) {
framework::AttributeMap attrs; framework::AttributeMap attrs;
attrs["step"].Set<int>(step); attrs["step"].Set<int>(step);
auto *op = new operators::IncrementOp<CPU, float>("increment", inputs, auto *op = new operators::IncrementOp<CPU, float>(
outputs, attrs, scope); "increment", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -37,7 +37,7 @@ int TestIsEmptyOp(const std::vector<int> input_shape) { ...@@ -37,7 +37,7 @@ int TestIsEmptyOp(const std::vector<int> input_shape) {
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::IsEmptyOp<CPU, float>("is_empty", inputs, outputs, auto *op = new operators::IsEmptyOp<CPU, float>("is_empty", inputs, outputs,
attrs, scope); attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -77,7 +77,7 @@ int TestLessThanOp(const std::vector<int> &x_shape, ...@@ -77,7 +77,7 @@ int TestLessThanOp(const std::vector<int> &x_shape,
framework::AttributeMap attrs; framework::AttributeMap attrs;
attrs["axis"].Set<int>(axis); attrs["axis"].Set<int>(axis);
auto *op = new operators::LessThanOp<CPU, float>("less_than", inputs, outputs, auto *op = new operators::LessThanOp<CPU, float>("less_than", inputs, outputs,
attrs, scope); attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -43,8 +43,8 @@ int TestLogOp(const std::vector<int> input_shape) { ...@@ -43,8 +43,8 @@ int TestLogOp(const std::vector<int> input_shape) {
auto output_var = scope.get()->Var("output"); auto output_var = scope.get()->Var("output");
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = auto *op = new operators::LogOp<CPU, float>("log", inputs, outputs, attrs,
new operators::LogOp<CPU, float>("log", inputs, outputs, attrs, scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -50,8 +50,8 @@ int TestLogicalAndOp(const std::vector<int> input_shape) { ...@@ -50,8 +50,8 @@ int TestLogicalAndOp(const std::vector<int> input_shape) {
auto output_var = scope.get()->Var("output"); auto output_var = scope.get()->Var("output");
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::LogicalAndOp<CPU, float>("logical_and", inputs, auto *op = new operators::LogicalAndOp<CPU, float>(
outputs, attrs, scope); "logical_and", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -42,8 +42,8 @@ int TestLogicalNotOp(const std::vector<int> input_shape) { ...@@ -42,8 +42,8 @@ int TestLogicalNotOp(const std::vector<int> input_shape) {
auto output_var = scope.get()->Var("output"); auto output_var = scope.get()->Var("output");
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::LogicalNotOp<CPU, float>("logical_not", inputs, auto *op = new operators::LogicalNotOp<CPU, float>(
outputs, attrs, scope); "logical_not", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -50,8 +50,8 @@ int TestLogicalOrOp(const std::vector<int> input_shape) { ...@@ -50,8 +50,8 @@ int TestLogicalOrOp(const std::vector<int> input_shape) {
auto output_var = scope.get()->Var("output"); auto output_var = scope.get()->Var("output");
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::LogicalOrOp<CPU, float>("logical_or", inputs, auto *op = new operators::LogicalOrOp<CPU, float>(
outputs, attrs, scope); "logical_or", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -52,8 +52,8 @@ int TestLogicalXorOp(const std::vector<int> input_shape) { ...@@ -52,8 +52,8 @@ int TestLogicalXorOp(const std::vector<int> input_shape) {
auto output_var = scope.get()->Var("output"); auto output_var = scope.get()->Var("output");
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::LogicalXorOp<CPU, float>("logical_xor", inputs, auto *op = new operators::LogicalXorOp<CPU, float>(
outputs, attrs, scope); "logical_xor", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -54,8 +54,8 @@ int TestMulOP() { ...@@ -54,8 +54,8 @@ int TestMulOP() {
AttributeMap attrs; AttributeMap attrs;
attrs["x_num_col_dims"].Set<int>(1); attrs["x_num_col_dims"].Set<int>(1);
attrs["y_num_col_dims"].Set<int>(1); attrs["y_num_col_dims"].Set<int>(1);
auto *op = auto *op = new operators::MulOp<CPU, float>("mul", inputs, outputs, attrs,
new operators::MulOp<CPU, float>("mul", inputs, outputs, attrs, scope); scope.get());
op->InferShape(); op->InferShape();
op->Run(); op->Run();
auto output = output_var->template Get<framework::LoDTensor>(); auto output = output_var->template Get<framework::LoDTensor>();
......
...@@ -55,7 +55,7 @@ class TestMultiClassNMSOp { ...@@ -55,7 +55,7 @@ class TestMultiClassNMSOp {
std::shared_ptr<operators::MultiClassNMSOp<Dtype, float>> priorbox = std::shared_ptr<operators::MultiClassNMSOp<Dtype, float>> priorbox =
std::make_shared<operators::MultiClassNMSOp<Dtype, float>>( std::make_shared<operators::MultiClassNMSOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(priorbox); ops_of_block_[*block_desc.get()].push_back(priorbox);
} }
} }
...@@ -64,7 +64,7 @@ class TestMultiClassNMSOp { ...@@ -64,7 +64,7 @@ class TestMultiClassNMSOp {
std::shared_ptr<Tensor> predict(const Tensor &t1, const Tensor &t2) { std::shared_ptr<Tensor> predict(const Tensor &t1, const Tensor &t2) {
// feed // feed
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *x1_feed_value = scope->Var("box_coder_0.tmp_0"); Variable *x1_feed_value = scope->Var("box_coder_0.tmp_0");
auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>(); auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>();
tensor_x1->ShareDataWith(t1); tensor_x1->ShareDataWith(t1);
......
...@@ -44,7 +44,7 @@ class TestPolygonBoxTransformOp { ...@@ -44,7 +44,7 @@ class TestPolygonBoxTransformOp {
op_ptr = std::make_shared< op_ptr = std::make_shared<
operators::PolygonBoxTransformOp<Dtype, float>>( operators::PolygonBoxTransformOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(op_ptr); ops_of_block_[*block_desc.get()].push_back(op_ptr);
return; return;
} }
...@@ -53,7 +53,7 @@ class TestPolygonBoxTransformOp { ...@@ -53,7 +53,7 @@ class TestPolygonBoxTransformOp {
} }
std::shared_ptr<Tensor> predict(const Tensor &t) { std::shared_ptr<Tensor> predict(const Tensor &t) {
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *input_feed_value = scope->Var(input_var_name); Variable *input_feed_value = scope->Var(input_var_name);
auto tensor_input = input_feed_value->GetMutable<LoDTensor>(); auto tensor_input = input_feed_value->GetMutable<LoDTensor>();
tensor_input->ShareDataWith(t); tensor_input->ShareDataWith(t);
......
...@@ -64,7 +64,7 @@ int TestPoolOp(int in_channels, int in_height, int in_width) { ...@@ -64,7 +64,7 @@ int TestPoolOp(int in_channels, int in_height, int in_width) {
attrs["global_pooling"].Set<bool>(false); attrs["global_pooling"].Set<bool>(false);
auto *op = new operators::PoolOp<CPU, float>("pool2d", inputs, outputs, attrs, auto *op = new operators::PoolOp<CPU, float>("pool2d", inputs, outputs, attrs,
scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -60,7 +60,7 @@ class TestPriorBoxOp { ...@@ -60,7 +60,7 @@ class TestPriorBoxOp {
std::shared_ptr<operators::PriorBoxOp<Dtype, float>> priorbox = std::shared_ptr<operators::PriorBoxOp<Dtype, float>> priorbox =
std::make_shared<operators::PriorBoxOp<Dtype, float>>( std::make_shared<operators::PriorBoxOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(priorbox); ops_of_block_[*block_desc.get()].push_back(priorbox);
} }
} }
...@@ -69,7 +69,7 @@ class TestPriorBoxOp { ...@@ -69,7 +69,7 @@ class TestPriorBoxOp {
std::shared_ptr<Tensor> predict_priorbox(const Tensor &t1, const Tensor &t2) { std::shared_ptr<Tensor> predict_priorbox(const Tensor &t1, const Tensor &t2) {
// feed // feed
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *x1_feed_value = scope->Var("image"); Variable *x1_feed_value = scope->Var("image");
auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>(); auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>();
tensor_x1->ShareDataWith(t1); tensor_x1->ShareDataWith(t1);
......
...@@ -115,7 +115,7 @@ int TestQuqntizeOp(const int batch_size, const int channel, const int height, ...@@ -115,7 +115,7 @@ int TestQuqntizeOp(const int batch_size, const int channel, const int height,
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::QuantizeOp<CPU, float>("quantize", inputs, outputs, auto *op = new operators::QuantizeOp<CPU, float>("quantize", inputs, outputs,
attrs, scope); attrs, scope.get());
op->InferShape(); op->InferShape();
op->Run(); op->Run();
......
...@@ -45,7 +45,7 @@ int TestRelu6Op(const std::vector<int> input_shape) { ...@@ -45,7 +45,7 @@ int TestRelu6Op(const std::vector<int> input_shape) {
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::Relu6Op<CPU, float>("relu6", inputs, outputs, attrs, auto *op = new operators::Relu6Op<CPU, float>("relu6", inputs, outputs, attrs,
scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -44,8 +44,8 @@ int TestReluOp(const std::vector<int> input_shape) { ...@@ -44,8 +44,8 @@ int TestReluOp(const std::vector<int> input_shape) {
auto output_var = scope.get()->Var("output"); auto output_var = scope.get()->Var("output");
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = auto *op = new operators::ReluOp<CPU, float>("relu", inputs, outputs, attrs,
new operators::ReluOp<CPU, float>("relu", inputs, outputs, attrs, scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -60,7 +60,7 @@ class TestReshape2Op { ...@@ -60,7 +60,7 @@ class TestReshape2Op {
std::shared_ptr<operators::Reshape2Op<Dtype, float>> op_ptr = std::shared_ptr<operators::Reshape2Op<Dtype, float>> op_ptr =
std::make_shared<operators::Reshape2Op<Dtype, float>>( std::make_shared<operators::Reshape2Op<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(op_ptr); ops_of_block_[*block_desc.get()].push_back(op_ptr);
return; return;
} }
...@@ -69,7 +69,7 @@ class TestReshape2Op { ...@@ -69,7 +69,7 @@ class TestReshape2Op {
} }
std::shared_ptr<Tensor> predict(const Tensor &t) { std::shared_ptr<Tensor> predict(const Tensor &t) {
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *input_feed_value = scope->Var(input_var_name); Variable *input_feed_value = scope->Var(input_var_name);
auto tensor_input = input_feed_value->GetMutable<LoDTensor>(); auto tensor_input = input_feed_value->GetMutable<LoDTensor>();
tensor_input->ShareDataWith(t); tensor_input->ShareDataWith(t);
......
...@@ -45,7 +45,7 @@ int TestSequenceExpandOp(const framework::LoDTensor &input_x, ...@@ -45,7 +45,7 @@ int TestSequenceExpandOp(const framework::LoDTensor &input_x,
attrs["ref_level"].Set<int>(0); attrs["ref_level"].Set<int>(0);
auto *op = new operators::SequenceExpandOp<CPU, float>( auto *op = new operators::SequenceExpandOp<CPU, float>(
"sequence_expand", inputs, outputs, attrs, scope); "sequence_expand", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -38,8 +38,8 @@ int TestSequencePoolOp(const framework::LoDTensor &input_x, ...@@ -38,8 +38,8 @@ int TestSequencePoolOp(const framework::LoDTensor &input_x,
framework::AttributeMap attrs; framework::AttributeMap attrs;
attrs["pooltype"].SetString(pool_type); attrs["pooltype"].SetString(pool_type);
auto *op = new operators::SequencePoolOp<CPU, float>("sequence_pool", inputs, auto *op = new operators::SequencePoolOp<CPU, float>(
outputs, attrs, scope); "sequence_pool", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -63,7 +63,7 @@ int TestSequenceSoftmaxOp(const std::vector<int> &input_shape, ...@@ -63,7 +63,7 @@ int TestSequenceSoftmaxOp(const std::vector<int> &input_shape,
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::SequenceSoftmaxOp<CPU, float>( auto *op = new operators::SequenceSoftmaxOp<CPU, float>(
"sequence_softmax", inputs, outputs, attrs, scope); "sequence_softmax", inputs, outputs, attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
......
...@@ -44,7 +44,7 @@ int TestSigmoidOp(const std::vector<int> input_shape) { ...@@ -44,7 +44,7 @@ int TestSigmoidOp(const std::vector<int> input_shape) {
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::SigmoidOp<CPU, float>("sigmoid", inputs, outputs, auto *op = new operators::SigmoidOp<CPU, float>("sigmoid", inputs, outputs,
attrs, scope); attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -65,7 +65,7 @@ int TestSoftmaxOp(const std::vector<int> input_shape) { ...@@ -65,7 +65,7 @@ int TestSoftmaxOp(const std::vector<int> input_shape) {
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = new operators::SoftmaxOp<CPU, float>("softmax", inputs, outputs, auto *op = new operators::SoftmaxOp<CPU, float>("softmax", inputs, outputs,
attrs, scope); attrs, scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -46,7 +46,7 @@ class TestSumOp { ...@@ -46,7 +46,7 @@ class TestSumOp {
std::shared_ptr<operators::SumOp<Dtype, float>> lrn = std::shared_ptr<operators::SumOp<Dtype, float>> lrn =
std::make_shared<operators::SumOp<Dtype, float>>( std::make_shared<operators::SumOp<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(lrn); ops_of_block_[*block_desc.get()].push_back(lrn);
} }
} }
...@@ -55,7 +55,7 @@ class TestSumOp { ...@@ -55,7 +55,7 @@ class TestSumOp {
std::shared_ptr<Tensor> predict_bn(const Tensor &t1, const Tensor &t2) { std::shared_ptr<Tensor> predict_bn(const Tensor &t1, const Tensor &t2) {
// feed // feed
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *x1_feed_value = scope->Var("fc_2.tmp_0"); Variable *x1_feed_value = scope->Var("fc_2.tmp_0");
auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>(); auto tensor_x1 = x1_feed_value->GetMutable<LoDTensor>();
tensor_x1->ShareDataWith(t1); tensor_x1->ShareDataWith(t1);
......
...@@ -43,8 +43,8 @@ int TestTanhOp(const std::vector<int> input_shape) { ...@@ -43,8 +43,8 @@ int TestTanhOp(const std::vector<int> input_shape) {
auto output_var = scope.get()->Var("output"); auto output_var = scope.get()->Var("output");
framework::AttributeMap attrs; framework::AttributeMap attrs;
auto *op = auto *op = new operators::TanhOp<CPU, float>("tanh", inputs, outputs, attrs,
new operators::TanhOp<CPU, float>("tanh", inputs, outputs, attrs, scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -71,8 +71,8 @@ int TestTopKOp(const std::vector<int> input_shape, const int K) { ...@@ -71,8 +71,8 @@ int TestTopKOp(const std::vector<int> input_shape, const int K) {
framework::AttributeMap attrs; framework::AttributeMap attrs;
attrs["k"].Set<int>(K); attrs["k"].Set<int>(K);
auto *op = auto *op = new operators::TopKOp<CPU, float>("top_k", inputs, outputs, attrs,
new operators::TopKOp<CPU, float>("top_k", inputs, outputs, attrs, scope); scope.get());
op->InferShape(); op->InferShape();
op->Init(); op->Init();
op->Run(); op->Run();
......
...@@ -60,7 +60,7 @@ class TestTranspose2Op { ...@@ -60,7 +60,7 @@ class TestTranspose2Op {
std::shared_ptr<operators::Transpose2Op<Dtype, float>> op_ptr = std::shared_ptr<operators::Transpose2Op<Dtype, float>> op_ptr =
std::make_shared<operators::Transpose2Op<Dtype, float>>( std::make_shared<operators::Transpose2Op<Dtype, float>>(
op->Type(), op->GetInputs(), op->GetOutputs(), op->Type(), op->GetInputs(), op->GetOutputs(),
op->GetAttrMap(), program_.scope); op->GetAttrMap(), program_.scope.get());
ops_of_block_[*block_desc.get()].push_back(op_ptr); ops_of_block_[*block_desc.get()].push_back(op_ptr);
return; return;
} }
...@@ -69,7 +69,7 @@ class TestTranspose2Op { ...@@ -69,7 +69,7 @@ class TestTranspose2Op {
} }
std::shared_ptr<Tensor> predict(const Tensor &t) { std::shared_ptr<Tensor> predict(const Tensor &t) {
auto scope = program_.scope; auto scope = program_.scope.get();
Variable *input_feed_value = scope->Var(input_var_name); Variable *input_feed_value = scope->Var(input_var_name);
auto tensor_input = input_feed_value->GetMutable<LoDTensor>(); auto tensor_input = input_feed_value->GetMutable<LoDTensor>();
tensor_input->ShareDataWith(t); tensor_input->ShareDataWith(t);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册