// 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 #include #include #include #include "core/cube/cube-api/include/cube_api.h" #include "core/kvdb/include/kvdb/paddle_rocksdb.h" #include "core/predictor/common/inner_common.h" #include "core/predictor/framework/infer.h" #include "core/predictor/framework/memory.h" namespace baidu { namespace paddle_serving { namespace predictor { class PaddleGeneralModelConfig { public: PaddleGeneralModelConfig() {} ~PaddleGeneralModelConfig() {} public: std::vector _feed_name; std::vector _feed_alias_name; std::vector _feed_type; // 0 int64, 1 float std::vector _is_lod_feed; // true lod tensor std::vector _is_lod_fetch; // whether a fetch var is lod_tensor std::vector _capacity; // capacity for each tensor /* feed_shape_ for feeded variable feed_shape_[i][j] represents the jth dim for ith input Tensor if is_lod_feed_[i] == False, feed_shape_[i][0] = -1 */ std::vector> _feed_shape; std::vector _fetch_name; std::vector _fetch_alias_name; std::vector> _fetch_shape; std::map _fetch_name_to_index; std::map _fetch_alias_name_to_index; }; class BaseRdDict; struct DynamicResource { DynamicResource(); ~DynamicResource(); int initialize(); int clear(); }; class Resource { public: Resource() { // Reference InferManager::instance() explicitly, to make sure static // instance of InferManager is constructed before that of Resource, and // destruct after that of Resource // See https://stackoverflow.com/a/335746/1513460 InferManager::instance(); } ~Resource() { finalize(); } static Resource& instance() { static Resource ins; return ins; } int initialize(const std::string& path, const std::string& file); int cube_initialize(const std::string& path, const std::string& file); int general_model_initialize(const std::string& path, const std::string& file); int thread_initialize(); int thread_clear(); int reload(); int finalize(); std::shared_ptr get_general_model_config(); void print_general_model_config( const std::shared_ptr& config); std::shared_ptr getDB(); DynamicResource* get_dynamic_resource() { return reinterpret_cast( THREAD_GETSPECIFIC(_tls_bspec_key)); } private: int thread_finalize() { return 0; } std::shared_ptr db; std::shared_ptr _config; THREAD_KEY_T _tls_bspec_key; }; } // namespace predictor } // namespace paddle_serving } // namespace baidu