program_desc.h 2.7 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
F
fengjiayi 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

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. */

#pragma once

17
#include <stdint.h>
18

Y
Fix CI  
Yu Yang 已提交
19
#include <memory>
20
#include <string>
F
fengjiayi 已提交
21
#include <vector>
W
wanghuancoder 已提交
22

Y
Yi Wang 已提交
23 24 25
#include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/framework/proto_desc.h"
#include "paddle/fluid/platform/macros.h"
F
fengjiayi 已提交
26 27 28 29

namespace paddle {
namespace framework {

Y
Yu Yang 已提交
30
class BlockDesc;
F
fengjiayi 已提交
31

Y
Yu Yang 已提交
32
class ProgramDesc {
F
fengjiayi 已提交
33
 public:
Y
Yu Yang 已提交
34
  ProgramDesc();
F
fengjiayi 已提交
35

Y
Yu Yang 已提交
36
  explicit ProgramDesc(const proto::ProgramDesc &desc);
37

Y
Yu Yang 已提交
38
  ProgramDesc(const ProgramDesc &o);
Y
Yu Yang 已提交
39

Y
Yu Yang 已提交
40
  explicit ProgramDesc(const std::string &binary_str);
41

Y
Yu Yang 已提交
42
  BlockDesc *AppendBlock(const BlockDesc &parent);
F
fengjiayi 已提交
43

Y
Yu Yang 已提交
44 45 46 47 48 49 50
  BlockDesc *MutableBlock(size_t idx) {
    if (idx == static_cast<size_t>(kNoneBlockIndex)) {
      return nullptr;
    } else {
      return blocks_[idx].get();
    }
  }
51

Y
Yu Yang 已提交
52
  const BlockDesc &Block(size_t idx) const { return *blocks_[idx]; }
F
fengjiayi 已提交
53 54 55

  size_t Size() const { return blocks_.size(); }

56 57
  void Flush();

X
Xin Pan 已提交
58 59
  void CopyFrom(const proto::ProgramDesc &desc);

60
  proto::ProgramDesc *Proto();
F
fengjiayi 已提交
61

62
  proto::OpVersionMap *OpVersionMap();
63

X
clean  
Xin Pan 已提交
64
  int64_t Version() const;
X
version  
Xin Pan 已提交
65

66 67
  void SetVersion(const int64_t version);

68 69 70
  // The output variable of feed_op is referenced as feed_target.
  // This function is used to collect the output variable's name of all
  // feed_ops.
71
  const std::vector<std::string> GetFeedTargetNames();
72 73 74 75

  // The input variable of fetch_op is referenced as fetch_target.
  // This function is used to collect the input variable's name of all
  // fetch_ops.
76
  const std::vector<std::string> GetFetchTargetNames();
77

78 79 80
  // The input variable of feed_op that holds input Tensor provided by users is
  // referenced as feed_holder.
  // This function is used to change or unify the feed_holder variables' name.
81
  void SetFeedHolderName(const std::string &feed_holder_name);
82 83 84 85

  // The output variable of fetch_op that holds output Tensor needed by users is
  // referenced as fetch_holder.
  // This function is used to change or unify the fetch_holder variables' name.
86 87
  void SetFetchHolderName(const std::string &fetch_holder_name);

L
Leo Chen 已提交
88 89
  bool NeedUpdate() const;

F
fengjiayi 已提交
90
 private:
X
Xin Pan 已提交
91 92
  void InitFromProto();

93
  proto::ProgramDesc desc_;
F
fengjiayi 已提交
94

Y
Yu Yang 已提交
95
  std::vector<std::unique_ptr<BlockDesc>> blocks_;
F
fengjiayi 已提交
96
};
F
fengjiayi 已提交
97 98
}  // namespace framework
}  // namespace paddle