compatibility.h 1.7 KB
Newer Older
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

17
#include <set>
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <string>
#include "lite/api/paddle_place.h"
#include "lite/model_parser/desc_apis.h"

namespace paddle {
namespace lite {

template <typename T>
class CompatibleChecker {
 public:
  explicit CompatibleChecker(const T& program,
                             const int64_t mini_version = 1005000)
      : program_(program), mini_version_(mini_version) {}

  bool operator()(const lite_api::Place& place) {
    bool status = true;
34
    const std::set<std::string>& ops_type = OpsType(&program_);
35 36 37 38 39 40 41 42 43 44 45 46
    if (ops_type.empty()) {
      VLOG(3) << "You are checking the compatibility of an empty program.";
    }
    for (const auto& type : ops_type) {
      bool ret = CheckKernelVersion(type, place);
      VLOG(3) << "Kernel version is supported: " << type << ", " << ret;
      status = status && ret;
    }
    return status;
  }

 private:
47
  std::set<std::string> OpsType(T* program);
48 49 50 51 52 53 54 55
  bool CheckKernelVersion(const std::string& type,
                          const lite_api::Place& place);
  T program_;
  int64_t mini_version_;
};

}  // namespace lite
}  // namespace paddle