/* 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_dynamic(0); omp_set_num_threads(num); #endif }; template bool PaddleMobile::Load(const std::string &dirname, bool optimize, bool quantification, int batch_size, 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), batch_size, 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, int batch_size, 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), batch_size, 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) { int batch_size = 1; 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), batch_size, 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; } #ifdef PADDLE_MOBILE_FPGA template void PaddleMobile::InjectVariable(const framework::Tensor &t, string var_name) { executor_->InjectVariable(t, var_name); } template void PaddleMobile::FeedData(const framework::Tensor &t) { executor_->FeedData(t); }; template std::shared_ptr PaddleMobile::FetchResult(int id) { return executor_->FetchResult(id); }; template void PaddleMobile::Predict_From_To(int start, int end) { executor_->Predict_From_To(start, end); }; template void PaddleMobile::Predict_From(int start) { executor_->Predict_From(start); }; template void PaddleMobile::Predict_To(int end) { executor_->Predict_To(end); }; #endif template class PaddleMobile; template class PaddleMobile; template class PaddleMobile; template class PaddleMobile; } // namespace paddle_mobile