block_desc.h 2.2 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2019 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.

#pragma once
#include <vector>
17 18 19
#include "lite/model_parser/base/apis.h"
#include "lite/model_parser/general/op_desc.h"
#include "lite/model_parser/general/var_desc.h"
Y
Yan Chunwei 已提交
20 21 22

namespace paddle {
namespace lite {
23
namespace general {
Y
Yan Chunwei 已提交
24 25

/*
26 27
 * The general::BlockDesc is the internal representation for Op. All the
 * internal
Y
Yan Chunwei 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * imprementation should use it, not the pb::BlockDesc.
 */
class BlockDesc : public BlockDescAPI {
 public:
  BlockDesc() = default;

  int32_t Idx() const override { return idx_; }

  void SetIdx(int32_t idx) override { idx_ = idx; }

  int32_t ParentIdx() const override { return parent_idx_; }

  void SetParentIdx(int32_t idx) override { parent_idx_ = idx; }

  size_t VarsSize() const override { return vars_.size(); }

  void ClearVars() override { vars_.clear(); }

  template <typename T>
  T* GetVar(int32_t idx);

49 50
  std::vector<VarDesc>& GetVars() { return vars_; }

51 52 53 54 55
  template <typename T>
  T const* GetVar(int32_t idx) const {
    return GetVar<T>(idx);
  }

Y
Yan Chunwei 已提交
56 57 58 59 60 61 62 63 64 65
  template <typename T>
  T* AddVar();

  size_t OpsSize() const override { return ops_.size(); }

  void ClearOps() override { ops_.clear(); }

  template <typename T>
  T* GetOp(int32_t idx);

66 67 68 69 70
  template <typename T>
  T const* GetOp(int32_t idx) const {
    return GetOp<T>(idx);
  }

Y
Yan Chunwei 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  template <typename T>
  T* AddOp();

  int32_t ForwardBlockIdx() const override { return forward_block_idx_; }

  void SetForwardBlockIdx(int32_t idx) override { forward_block_idx_ = idx; }

 private:
  int32_t idx_;
  int32_t parent_idx_;
  std::vector<OpDesc> ops_;
  std::vector<VarDesc> vars_;
  int32_t forward_block_idx_;
};

86
}  // namespace general
Y
Yan Chunwei 已提交
87 88
}  // namespace lite
}  // namespace paddle