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

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

F
fengjiayi 已提交
15 16
#include "paddle/framework/program_desc.h"
#include "paddle/framework/block_desc.h"
F
fengjiayi 已提交
17 18 19 20 21

namespace paddle {
namespace framework {

BlockDescBind *ProgramDescBind::AppendBlock(const BlockDescBind &parent) {
22
  auto *b = prog_.add_blocks();
F
fengjiayi 已提交
23
  b->set_parent_idx(parent.ID());
24
  b->set_idx(prog_.blocks_size() - 1);
F
fengjiayi 已提交
25 26 27 28 29 30
  blocks_.emplace_back(new BlockDescBind(this, b));
  return blocks_.back().get();
}

ProgramDesc *ProgramDescBind::Proto() {
  for (auto &block : blocks_) {
31
    block->Flush();
F
fengjiayi 已提交
32
  }
33
  return &prog_;
F
fengjiayi 已提交
34 35
}

36 37
ProgramDescBind::ProgramDescBind() {
  auto *block = prog_.mutable_blocks()->Add();
38 39
  block->set_idx(kRootBlockIndex);
  block->set_parent_idx(kNoneBlockIndex);
40
  blocks_.emplace_back(new BlockDescBind(this, block));
F
fengjiayi 已提交
41
}
Y
Yu Yang 已提交
42 43 44 45 46 47 48 49 50

ProgramDescBind::ProgramDescBind(const ProgramDescBind &o) {
  prog_ = o.prog_;

  for (int i = 0; i < prog_.blocks_size(); ++i) {
    auto *block = prog_.mutable_blocks(i);
    blocks_.emplace_back(new BlockDescBind(*o.blocks_[i], block, this));
  }
}
F
fengjiayi 已提交
51 52
}  // namespace framework
}  // namespace paddle