program_desc.h 1.9 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
#include "lite/model_parser/base/apis.h"
#include "lite/model_parser/general/block_desc.h"
Y
Yan Chunwei 已提交
19 20 21

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

/*
25 26
 * The general::ProgramDesc is the internal representation for Op. All the
 * internal
Y
Yan Chunwei 已提交
27 28 29 30 31 32
 * imprementation should use it, not the pb::ProgramDesc.
 */
class ProgramDesc : public ProgramDescAPI {
 public:
  ProgramDesc() = default;

33 34 35 36 37 38 39
  void CopyFrom(const ProgramDesc& other) {
    version_ = other.Version();
    blocks_ = other.blocks();
  }

  const std::vector<BlockDesc>& blocks() const { return blocks_; }

Y
Yan Chunwei 已提交
40 41 42 43 44 45 46
  size_t BlocksSize() const override { return blocks_.size(); }

  void ClearBlocks() override { blocks_.clear(); }

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

47
  template <typename T>
48 49 50
  T const* GetBlock(int32_t idx) const;

  std::vector<BlockDesc>& GetBlocks() { return blocks_; }
51

Y
Yan Chunwei 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  template <typename T>
  T* AddBlock();

  // Just return default versoin
  // TODO(sangoly): refine this
  bool HasVersion() const override { return true; }

  int64_t Version() const override { return version_; }

  void SetVersion(int64_t version) override { version_ = version; }

 private:
  int64_t version_;
  std::vector<BlockDesc> blocks_;
};

68
}  // namespace general
Y
Yan Chunwei 已提交
69 70
}  // namespace lite
}  // namespace paddle