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>
Y
Fix CI  
Yu Yang 已提交
18
#include <memory>
19
#include <string>
F
fengjiayi 已提交
20
#include <vector>
W
wanghuancoder 已提交
21

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

namespace paddle {
namespace framework {

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

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

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

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

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

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

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

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

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

55 56
  void Flush();

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

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

61
  proto::OpVersionMap *OpVersionMap();
62

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

65 66
  void SetVersion(const int64_t version);

67 68 69
  // 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.
70
  const std::vector<std::string> GetFeedTargetNames();
71 72 73 74

  // 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.
75
  const std::vector<std::string> GetFetchTargetNames();
76

77 78 79
  // 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.
80
  void SetFeedHolderName(const std::string &feed_holder_name);
81 82 83 84

  // 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.
85 86
  void SetFetchHolderName(const std::string &fetch_holder_name);

F
fengjiayi 已提交
87
 private:
X
Xin Pan 已提交
88 89
  void InitFromProto();

90
  proto::ProgramDesc desc_;
F
fengjiayi 已提交
91

Y
Yu Yang 已提交
92
  std::vector<std::unique_ptr<BlockDesc>> blocks_;
F
fengjiayi 已提交
93
};
F
fengjiayi 已提交
94 95
}  // namespace framework
}  // namespace paddle