/* Copyright (c) 2018 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. */ #include "io/paddle_mobile.h" namespace paddle_mobile { template void PaddleMobile::SetThreadNum(int num) { #ifdef _OPENMP omp_set_num_threads(num); #endif }; template bool PaddleMobile::Load(const std::string &dirname, bool optimize, bool quantification, bool loddable) { if (loader_.get() == nullptr) { loader_ = std::make_shared>(); } else { LOG(kLOG_INFO) << "loader inited"; } if (executor_.get() == nullptr) { executor_ = std::make_shared>( loader_->Load(dirname, optimize, quantification), optimize, loddable); } else { LOG(kLOG_INFO) << "executor inited"; } return true; } template bool PaddleMobile::Load(const std::string &model_path, const std::string ¶_path, bool optimize, bool quantification, bool loddable) { if (loader_.get() == nullptr) { loader_ = std::make_shared>(); } else { LOG(kLOG_INFO) << "loader inited"; } if (executor_.get() == nullptr) { executor_ = std::make_shared>( loader_->Load(model_path, para_path, optimize, quantification), optimize, loddable); } else { LOG(kLOG_INFO) << "executor inited"; } return true; } template bool PaddleMobile::LoadCombinedMemory( size_t model_len, const uint8_t *model_buf, size_t combined_params_len, const uint8_t *combined_params_buf) { bool optimise = true; bool quantification = false; if (loader_.get() == nullptr) { loader_ = std::make_shared>(); } else { LOG(kLOG_INFO) << "loader inited"; } if (executor_.get() == nullptr) { executor_ = std::make_shared>( loader_->LoadCombinedMemory(model_len, model_buf, combined_params_len, combined_params_buf, optimise, quantification), optimise); } else { LOG(kLOG_INFO) << "executor inited"; } return true; } template std::shared_ptr PaddleMobile::Predict( const framework::Tensor &t) { return executor_->Predict(t); } template std::shared_ptr PaddleMobile::PredictLod( const framework::LoDTensor &t) { return executor_->PredictLod(t); } template std::vector::Ptype> PaddleMobile::Predict(const std::vector &input, const std::vector &dims) { return executor_->Predict(input, dims); } template void PaddleMobile::Clear() { executor_ = nullptr; loader_ = nullptr; } template PaddleMobile::~PaddleMobile() { executor_ = nullptr; loader_ = nullptr; } template class PaddleMobile; template class PaddleMobile; template class PaddleMobile; template class PaddleMobile; } // namespace paddle_mobile