/* 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. */ #pragma once #include #include #include #include #include #include "common/types.h" #include "common/util.h" #include "framework/lod_tensor.h" #include "framework/operator.h" #include "framework/program/program.h" #include "framework/tensor.h" namespace paddle_mobile { namespace framework { template class Executor { public: Executor(const Program &program, paddle_mobile::PaddleMobileConfigInternal config, int batch_size = 1, const bool use_optimize = true, const bool lod_mode = false); void SetThreadNum(int threads); PMStatus Predict(const std::vector> &inputs); PMStatus Predict( const std::vector> &inputs); std::vector Predict(const std::vector &input, const std::vector &dims); PMStatus Predict(); void SetInput(const Tensor &input, const std::string &var_name); void SetInput(const LoDTensor &input, const std::string &var_name); std::shared_ptr GetOutput(const std::string &var_name); void FeedTensorData(const std::vector &v); void GetTensorResults(std::vector *v); #ifdef PADDLE_MOBILE_FPGA void InjectVariable(const Tensor &t, std::string var_name); void FeedData(const Tensor &t); void FeedData(const std::vector &v); void GetResults(std::vector *v); framework::Tensor *GetTensorByName(const std::string &name); std::shared_ptr FetchResult(int id = -1); void Predict_From_To(int start = 0, int end = -1); void Predict_From(int start); void Predict_To(int end); #endif protected: Executor() = default; bool varInputMemory(const std::shared_ptr &var_desc, Variable *var) const; void InitFeedFetchList(); void InitMemory(); void InitCombineMemory(); void InitNoPersistableMemory(const Tensor &input_tensor); void LoadMemory(void **data, const std::shared_ptr var_desc, LoDTensor *tensor); #ifdef PADDLE_MOBILE_CL void LoadMemory(const VarDesc var_desc, float *tensorInput, char **data); #endif int batch_size_; bool use_optimize_; bool lod_mode_; PaddleMobileConfigInternal config_; Program program_; std::shared_ptr program_desc_; std::vector>> ops_of_block0_; std::unordered_map feed_indices_; std::unordered_map fetch_indices_; // for super resoltion DDim input_dim_last_; #ifdef PADDLE_MOBILE_PROFILE struct ProfInfo { int tid = 0; uint64_t runBegin = 0UL; uint64_t runEnd = 0UL; }; #endif }; } // namespace framework } // namespace paddle_mobile