#pragma once #include "framework/framework.pb.h" #include "framework/program/op_desc.h" #include "framework/program/var_desc.h" #include "framework/paddle_mobile_object.h" namespace paddle_mobile { namespace framework { class BlockDesc : PaddleMobileObject { public: friend class Node; friend class ProgramOptimize; BlockDesc(const proto::BlockDesc &desc); 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 copy_op_desc = std::make_shared(*op_desc); ops_.push_back(copy_op_desc); } for (auto &var_desc : block_desc.vars_) { std::shared_ptr copy_var_desc = std::make_shared(*var_desc.second); vars_[var_desc.first] = copy_var_desc; } } const int &ID() const { return index_; } const int &Parent() const { return parent_index_; } bool operator==(const paddle_mobile::framework::BlockDesc &in_block) const { return this->ID() == in_block.ID() && this->Parent() == in_block.Parent(); } bool operator<(const paddle_mobile::framework::BlockDesc &in_block) const { return this->ID() < in_block.ID() && this->Parent() < in_block.Parent(); } std::vector> Vars() const; std::vector> Ops() const; private: int index_; int parent_index_; std::vector> ops_; std::unordered_map> vars_; }; } // namespace framework } // namespace paddle_mobile namespace std { template <> struct hash { typedef paddle_mobile::framework::BlockDesc argument_type; typedef std::size_t result_type; result_type operator()(argument_type const &s) const noexcept { result_type const h1(std::hash{}(s.ID())); result_type const h2(std::hash{}(s.ID())); return h1 ^ (h2 << 1); } }; } // namespace std