提交 cf963d96 编写于 作者: L liuruilong

format files

上级 6018d63c
......@@ -14,6 +14,4 @@ limitations under the License. */
#include "log.h"
namespace paddle_mobile {
}
namespace paddle_mobile {}
......@@ -178,4 +178,4 @@ Print &operator<<(Print &printer, const std::vector<T> &v) {
return printer;
}
} // namespace paddle_mobile
\ No newline at end of file
} // namespace paddle_mobile
......@@ -11,4 +11,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
......@@ -17,32 +17,30 @@ limitations under the License. */
namespace paddle_mobile {
namespace framework {
/*
* Variant<int, float, std::string, std::vector<int>, std::vector<float>,
std::vector<std::string>, bool, std::vector<bool>, BlockDesc *,
int64_t>
* */
struct PrintVistor: Vistor<Print &>{
PrintVistor(Print &printer):printer_(printer){
}
struct PrintVistor : Vistor<Print &> {
PrintVistor(Print &printer) : printer_(printer) {}
template <typename T>
Print &operator()(const T &value){
Print &operator()(const T &value) {
printer_ << value;
return printer_;
}
private:
Print &printer_;
};
Print &operator<<(Print &printer, const Attribute &attr) {
Attribute::ApplyVistor(PrintVistor(printer), attr);
// std::vector<std::string> v = {"1", "2"};
// printer << (v);
// std::vector<std::string> v = {"1", "2"};
// printer << (v);
return printer;
}
}
} // namespace framework
} // namespace paddle_mobile
......@@ -111,15 +111,18 @@ class Attribute {
return vistor(attr.variant_.Get<std::string>());
} else if (attr.variant_.TypeId() == typeid(std::vector<int>).hash_code()) {
return vistor(attr.variant_.Get<std::vector<int>>());
} else if (attr.variant_.TypeId() == typeid(std::vector<float>).hash_code()) {
} else if (attr.variant_.TypeId() ==
typeid(std::vector<float>).hash_code()) {
return vistor(attr.variant_.Get<std::vector<float>>());
} else if (attr.variant_.TypeId() == typeid(std::vector<std::string>).hash_code()) {
} else if (attr.variant_.TypeId() ==
typeid(std::vector<std::string>).hash_code()) {
return vistor(attr.variant_.Get<std::vector<std::string>>());
} else if (attr.variant_.TypeId() == typeid(bool).hash_code()) {
return vistor(attr.variant_.Get<bool>());
} else if (attr.variant_.TypeId() == typeid(std::vector<bool>).hash_code()) {
} else if (attr.variant_.TypeId() ==
typeid(std::vector<bool>).hash_code()) {
return vistor(attr.variant_.Get<std::vector<bool>>());
} else if (attr.variant_.TypeId() == typeid(int64_t).hash_code()) {
} else if (attr.variant_.TypeId() == typeid(int64_t).hash_code()) {
return vistor(attr.variant_.Get<int64_t>());
} else {
throw std::bad_exception();
......@@ -152,9 +155,6 @@ class AttrReader {
const AttributeMap &attrs_;
};
Print &operator<<(Print &printer, const Attribute &op_desc);
} // namespace framework
......
......@@ -18,11 +18,11 @@ limitations under the License. */
#include <string>
#include <vector>
#include "framework/program/block_desc.h"
#include "framework.pb.h"
#include "operator.h"
#include "framework/program/block_desc.h"
#include "framework/program/program.h"
#include "framework/program/program_desc.h"
#include "operator.h"
#include "scope.h"
#include "tensor.h"
#include "variable.h"
......
......@@ -124,7 +124,7 @@ void AddDescriptors();
void InitDefaults();
} // namespace protobuf_framework_2eproto
enum VarType_Type {
enum VarType_Type {
VarType_Type_BOOL = 0,
VarType_Type_INT16 = 1,
VarType_Type_INT32 = 2,
......
......@@ -22,15 +22,15 @@ limitations under the License. */
#include "common/type_define.h"
#include "common/types.h"
#include "common/variant.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/op_info.h"
#include "framework/variable.h"
#include "framework/attribute.h"
#include "framework/op_info.h"
#include "framework/op_kernel_type.h"
#include "framework/program/block_desc.h"
#include "framework/paddle_mobile_object.h"
#include "framework/program/block_desc.h"
#include "framework/program/program-optimize/node.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
namespace paddle_mobile {
namespace framework {
......@@ -104,7 +104,7 @@ class OpKernelBase : PaddleMobileObject {
std::shared_ptr<::paddle_mobile::framework::Scope> scope) \
: parent_cls<Dtype, T>(type, inputs, outputs, attrs, scope) {}
class FusionOpMatcher: PaddleMobileObject{
class FusionOpMatcher : PaddleMobileObject {
public:
FusionOpMatcher() {}
......@@ -112,16 +112,11 @@ class FusionOpMatcher: PaddleMobileObject{
virtual void FolderNodes(Node &node) {
node.Folder(node_.Depth(), Type(), {});
}
virtual Node &BeginNode() {
return node_;
}
virtual Node &BeginNode() { return node_; }
std::string BeginType() {
return node_.BeginType();
}
std::string BeginType() { return node_.BeginType(); }
protected:
Node node_;
......
......@@ -33,8 +33,8 @@ std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const {
return res;
}
BlockDesc::BlockDesc(const proto::BlockDesc &desc):
index_(desc.idx()), parent_index_(desc.parent_idx()) {
BlockDesc::BlockDesc(const proto::BlockDesc &desc)
: index_(desc.idx()), parent_index_(desc.parent_idx()) {
for (const proto::VarDesc &var_desc : desc.vars()) {
vars_[var_desc.name()].reset(new VarDesc(var_desc));
}
......
......@@ -15,10 +15,9 @@ limitations under the License. */
#pragma once
#include "framework/framework.pb.h"
#include "framework/paddle_mobile_object.h"
#include "framework/program/op_desc.h"
#include "framework/program/var_desc.h"
#include "framework/paddle_mobile_object.h"
namespace paddle_mobile {
namespace framework {
......@@ -29,9 +28,8 @@ class BlockDesc : PaddleMobileObject {
friend class ProgramOptimize;
BlockDesc(const proto::BlockDesc &desc);
BlockDesc(const BlockDesc &block_desc):
index_(block_desc.index_),
parent_index_(block_desc.parent_index_) {
BlockDesc(const BlockDesc &block_desc)
: index_(block_desc.index_), parent_index_(block_desc.parent_index_) {
for (auto &op_desc : block_desc.ops_) {
std::shared_ptr<OpDesc> copy_op_desc = std::make_shared<OpDesc>(*op_desc);
ops_.push_back(copy_op_desc);
......@@ -39,7 +37,7 @@ class BlockDesc : PaddleMobileObject {
for (auto &var_desc : block_desc.vars_) {
std::shared_ptr<VarDesc> copy_var_desc =
std::make_shared<VarDesc>(*var_desc.second);
std::make_shared<VarDesc>(*var_desc.second);
vars_[var_desc.first] = copy_var_desc;
}
}
......
......@@ -20,7 +20,7 @@ limitations under the License. */
namespace paddle_mobile {
namespace framework {
OpDesc::OpDesc(const proto::OpDesc &desc):type_(desc.type()) {
OpDesc::OpDesc(const proto::OpDesc &desc) : type_(desc.type()) {
for (int i = 0; i < desc.inputs_size(); ++i) {
const proto::OpDesc::Var &var = desc.inputs(i);
std::vector<std::string> &args = inputs_[var.parameter()];
......@@ -65,7 +65,7 @@ std::unordered_map<std::string, Attribute> &OpDesc::GetAttrMap() {
}
Print &operator<<(Print &printer, const OpDesc &op_desc) {
OpDesc &no_const_op_desc = const_cast<OpDesc &>(op_desc);
OpDesc &no_const_op_desc = const_cast<OpDesc &>(op_desc);
printer << "inputs: \n";
for (const auto &input : no_const_op_desc.GetInputs()) {
printer << input.first << " : " << input.second << "\n";
......
......@@ -14,8 +14,8 @@ limitations under the License. */
#pragma once
#include <vector>
#include <string>
#include <vector>
#include "common/log.h"
#include "common/type_define.h"
......@@ -32,14 +32,13 @@ class OpDesc : PaddleMobileObject {
friend class Node;
explicit OpDesc(const proto::OpDesc &desc);
OpDesc(const OpDesc &op_desc): type_(op_desc.type_) {
OpDesc(const OpDesc &op_desc) : type_(op_desc.type_) {
this->inputs_ = op_desc.inputs_;
this->outputs_ = op_desc.outputs_;
this->attrs_ = op_desc.attrs_;
}
OpDesc() {
}
OpDesc() {}
const std::vector<std::string> &Input(const std::string &name) const;
const std::vector<std::string> &Output(const std::string &name) const;
Attribute GetAttr(const std::string &name) const;
......@@ -52,17 +51,11 @@ class OpDesc : PaddleMobileObject {
const std::string &Type() { return type_; }
void SetInputs(VariableNameMap inputs){
inputs_ = inputs;
}
void SetInputs(VariableNameMap inputs) { inputs_ = inputs; }
void SetOutputs(VariableNameMap outputs){
outputs_ = outputs;
}
void SetOutputs(VariableNameMap outputs) { outputs_ = outputs; }
void SetAttrMap(AttributeMap attrs){
attrs_ = attrs;
}
void SetAttrMap(AttributeMap attrs) { attrs_ = attrs; }
private:
std::string type_;
......
......@@ -25,8 +25,8 @@ namespace framework {
class FusionOpRegister {
public:
static FusionOpRegister *Instance() {
static FusionOpRegister *regist = nullptr;
static FusionOpRegister* Instance() {
static FusionOpRegister* regist = nullptr;
if (regist == nullptr) {
regist = new FusionOpRegister();
}
......@@ -47,9 +47,9 @@ class FusionOpRegister {
FusionOpRegister() {}
};
class FusionOpRegistrar{
class FusionOpRegistrar {
public:
explicit FusionOpRegistrar(FusionOpMatcher* matcher){
explicit FusionOpRegistrar(FusionOpMatcher* matcher) {
FusionOpRegister::Instance()->regist(matcher);
}
};
......
......@@ -72,7 +72,8 @@ void Node::OpDescs(uint index,
}
}
void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc, Node *node) {
void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
Node *node) {
auto iter = std::find(op_desc->begin(), op_desc->end(), this->op_desc_);
if (inputs_.size() > 1 && node != inputs_.back()) {
return;
......
......@@ -20,8 +20,8 @@ limitations under the License. */
#include <vector>
#include "common/log.h"
#include "framework/program/op_desc.h"
#include "framework/paddle_mobile_object.h"
#include "framework/program/op_desc.h"
namespace paddle_mobile {
namespace framework {
......@@ -42,7 +42,8 @@ class Node : PaddleMobileObject {
std::map<std::string, std::pair<std::string, std::string>> change_map);
std::vector<std::shared_ptr<framework::OpDesc>> OpDescs(uint size);
std::vector<std::shared_ptr<framework::OpDesc>> OpDescs();
void OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc, Node *node);
void OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
Node *node);
std::shared_ptr<framework::OpDesc> OpDesc() { return op_desc_; }
std::string BeginType() { return type_; }
void Description();
......
......@@ -23,7 +23,6 @@ std::shared_ptr<ProgramDesc> ProgramOptimize::Optimize() {}
std::shared_ptr<ProgramDesc> ProgramOptimize::FushionOptimize(
std::shared_ptr<ProgramDesc> ori_des) {
ProgramDesc *optimize_program = new ProgramDesc(*ori_des);
for (int i = 0; i < optimize_program->Blocks().size(); ++i) {
......@@ -96,9 +95,8 @@ std::shared_ptr<ProgramDesc> ProgramOptimize::FushionOptimize(
}
}
// DLOG << "node: \n" << *begin_node;
// DLOG << "node: \n" << *begin_node;
block->ops_ = begin_node->OpDescs();
}
std::shared_ptr<ProgramDesc> shared_optimzie(optimize_program);
return shared_optimzie;
......
......@@ -30,6 +30,7 @@ class ProgramOptimize {
std::shared_ptr<ProgramDesc> Optimize();
std::shared_ptr<ProgramDesc> FushionOptimize(
std::shared_ptr<ProgramDesc> ori_des);
private:
// std::shared_ptr<ProgramDesc> ori_desc_;
std::vector<std::unordered_map<std::string, std::shared_ptr<Node>>>
......
......@@ -12,8 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <vector>
#include <string>
#include <vector>
#include "program_desc.h"
......@@ -29,7 +29,7 @@ ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) {
void ProgramDesc::Description(std::string header) {
#ifdef PADDLE_MOBILE_DEBUG
if (header.size()){
if (header.size()) {
LOG(kLOG_INFO) << header;
}
for (const auto &block : this->blocks_) {
......
......@@ -17,8 +17,8 @@ limitations under the License. */
#include <vector>
#include "common/types.h"
#include "framework/program/block_desc.h"
#include "framework/paddle_mobile_object.h"
#include "framework/program/block_desc.h"
namespace paddle_mobile {
namespace framework {
......@@ -33,12 +33,13 @@ class ProgramDesc : PaddleMobileObject {
ProgramDesc(const ProgramDesc &program_desc) {
for (auto &block : program_desc.blocks_) {
std::shared_ptr<BlockDesc> copy_block =
std::make_shared<BlockDesc>(*block);
std::make_shared<BlockDesc>(*block);
blocks_.push_back(copy_block);
}
}
void Description(std::string header = "");
private:
std::vector<std::shared_ptr<BlockDesc>> blocks_;
};
......
......@@ -24,7 +24,7 @@ class VarDesc {
public:
VarDesc(const proto::VarDesc &desc);
VarDesc(const VarDesc &var_desc):desc_(var_desc.desc_) {}
VarDesc(const VarDesc &var_desc) : desc_(var_desc.desc_) {}
std::string Name() const { return desc_.name(); }
......
......@@ -14,13 +14,13 @@ limitations under the License. */
#include <fstream>
#include "io.h"
#include "common/log.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/lod_tensor.h"
#include "framework/framework.pb.h"
#include "framework/lod_tensor.h"
#include "framework/program/program_desc.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "io.h"
namespace paddle_mobile {
......
......@@ -24,17 +24,17 @@ class FushionConvAddReluOpMatcher : public framework::FusionOpMatcher {
public:
FushionConvAddReluOpMatcher() {
node_ = framework::Node("conv2d");
node_ > std::make_shared<framework::Node>("elementwise_add") > std::make_shared<framework::Node>("relu");
node_ > std::make_shared<framework::Node>("elementwise_add") >
std::make_shared<framework::Node>("relu");
}
void FolderNodes(framework::Node &node) {
std::vector<std::shared_ptr<framework::OpDesc>> origin_descs = node.OpDescs(node_.Depth());
node.Folder(node_.Depth(), Type(), {{"elementwise_add" , {"Y", "Z"}}});
std::vector<std::shared_ptr<framework::OpDesc>> origin_descs =
node.OpDescs(node_.Depth());
node.Folder(node_.Depth(), Type(), {{"elementwise_add", {"Y", "Z"}}});
}
std::string Type() {
return "FusionConvAddRelu";
}
std::string Type() { return "FusionConvAddRelu"; }
};
class FusionFcOp {
......@@ -42,7 +42,8 @@ class FusionFcOp {
private:
};
static framework::FusionOpRegistrar fc_registrar(new FushionConvAddReluOpMatcher());
static framework::FusionOpRegistrar fc_registrar(
new FushionConvAddReluOpMatcher());
}
}
} // namespace operators
} // namespace paddle_mobile
......@@ -12,4 +12,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "fusion_fc_op.h"
\ No newline at end of file
#include "fusion_fc_op.h"
......@@ -30,13 +30,12 @@ class FusionFcMatcher : public framework::FusionOpMatcher {
}
void FolderNodes(framework::Node &node) {
std::vector<std::shared_ptr<framework::OpDesc>> origin_descs = node.OpDescs(node_.Depth());
node.Folder(node_.Depth(), Type(), {{"elementwise_add" , {"Y", "Z"}}});
std::vector<std::shared_ptr<framework::OpDesc>> origin_descs =
node.OpDescs(node_.Depth());
node.Folder(node_.Depth(), Type(), {{"elementwise_add", {"Y", "Z"}}});
}
std::string Type() {
return "fc";
}
std::string Type() { return "fc"; }
};
class FusionFcOp {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册