program_desc.h 2.8 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

64 65
  bool HasOpVersionMap() const;

X
clean  
Xin Pan 已提交
66
  int64_t Version() const;
X
version  
Xin Pan 已提交
67

68 69
  bool HasVersion() const;

70 71
  void SetVersion(const int64_t version);

72 73 74
  // 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.
75
  const std::vector<std::string> GetFeedTargetNames();
76 77 78 79

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

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

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

L
Leo Chen 已提交
92 93
  std::string CachedHashString();

L
Leo Chen 已提交
94 95
  bool NeedUpdate() const;

F
fengjiayi 已提交
96
 private:
X
Xin Pan 已提交
97 98
  void InitFromProto();

99
  proto::ProgramDesc desc_;
F
fengjiayi 已提交
100

Y
Yu Yang 已提交
101
  std::vector<std::unique_ptr<BlockDesc>> blocks_;
L
Leo Chen 已提交
102 103

  std::string cached_hash_str_;
F
fengjiayi 已提交
104
};
F
fengjiayi 已提交
105 106
}  // namespace framework
}  // namespace paddle