op_desc.h 1.9 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 22 23 24 25 26 27 28 29 30 31 32 33 34

#include "common/log.h"
#include "common/type_define.h"
#include "framework/framework.pb.h"
#include "framework/paddle_mobile_object.h"

namespace paddle_mobile {
namespace framework {

class OpDesc : PaddleMobileObject {
 public:
  friend class ProgramOptimize;
  friend class FusionOpMatcher;
  friend class Node;
  explicit OpDesc(const proto::OpDesc &desc);

L
liuruilong 已提交
35
  OpDesc(const OpDesc &op_desc) : type_(op_desc.type_) {
L
liuruilong 已提交
36 37 38 39 40
    this->inputs_ = op_desc.inputs_;
    this->outputs_ = op_desc.outputs_;
    this->attrs_ = op_desc.attrs_;
  }

L
liuruilong 已提交
41
  OpDesc() {}
L
liuruilong 已提交
42 43 44 45 46 47 48 49 50 51 52 53
  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 已提交
54
  void SetInputs(VariableNameMap inputs) { inputs_ = inputs; }
L
liuruilong 已提交
55

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

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

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

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

}  // namespace framework
}  // namespace paddle_mobile