op_desc.h 2.0 KB
Newer Older
L
liuruilong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

L
liuruilong 已提交
15 16 17
#pragma once

#include <string>
L
liuruilong 已提交
18
#include <vector>
L
liuruilong 已提交
19 20 21

#include "common/log.h"
#include "common/type_define.h"
L
liuruilong 已提交
22
#include "framework/framework.pb-c.h"
L
liuruilong 已提交
23 24 25 26 27 28 29 30 31 32
#include "framework/paddle_mobile_object.h"

namespace paddle_mobile {
namespace framework {

class OpDesc : PaddleMobileObject {
 public:
  friend class ProgramOptimize;
  friend class FusionOpMatcher;
  friend class Node;
L
liuruilong 已提交
33
  explicit OpDesc(PaddleMobile__Framework__Proto__OpDesc *op_desc);
L
liuruilong 已提交
34
  OpDesc(const OpDesc &op_desc) : type_(op_desc.type_) {
L
liuruilong 已提交
35 36 37 38 39
    this->inputs_ = op_desc.inputs_;
    this->outputs_ = op_desc.outputs_;
    this->attrs_ = op_desc.attrs_;
  }

L
liuruilong 已提交
40
  OpDesc() {}
L
liuruilong 已提交
41 42 43 44 45 46 47 48 49 50 51 52
  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;

  VariableNameMap &GetInputs() { return inputs_; }

  VariableNameMap &GetOutputs() { return outputs_; }

  AttributeMap &GetAttrMap();

  const std::string &Type() { return type_; }

L
liuruilong 已提交
53
  void SetInputs(VariableNameMap inputs) { inputs_ = inputs; }
L
liuruilong 已提交
54

L
liuruilong 已提交
55
  void SetOutputs(VariableNameMap outputs) { outputs_ = outputs; }
L
liuruilong 已提交
56

L
liuruilong 已提交
57
  void SetAttrMap(AttributeMap attrs) { attrs_ = attrs; }
L
liuruilong 已提交
58 59 60 61 62 63 64 65 66 67 68 69

 private:
  std::string type_;
  VariableNameMap inputs_;
  VariableNameMap outputs_;
  AttributeMap attrs_;
};

Print &operator<<(Print &printer, const OpDesc &op_desc);

}  // namespace framework
}  // namespace paddle_mobile