1 /** 2 * Copyright 2019-2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_GE_RUNTIME_MODEL_RUNNER_H_ 18 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_GE_RUNTIME_MODEL_RUNNER_H_ 19 20 #include <memory> 21 #include <map> 22 #include <vector> 23 #include <tuple> 24 #include <string> 25 #include "runtime/device/ascend/ge_runtime/davinci_model.h" 26 27 namespace mindspore::ge::model_runner { 28 class RuntimeModel; 29 using RuntimeInfo = std::tuple<uint32_t, uint32_t, void *>; 30 class ModelRunner { 31 public: 32 static ModelRunner &Instance(); 33 34 void LoadDavinciModel(uint32_t device_id, uint64_t session_id, uint32_t model_id, 35 const std::shared_ptr<DavinciModel> &davinci_model); 36 37 void DistributeTask(uint32_t model_id); 38 39 void LoadModelComplete(uint32_t model_id); 40 41 const std::vector<uint32_t> &GetTaskIdList(uint32_t model_id) const; 42 43 const std::vector<uint32_t> &GetStreamIdList(uint32_t model_id) const; 44 45 const std::map<std::string, std::shared_ptr<RuntimeInfo>> &GetRuntimeInfoMap(uint32_t model_id) const; 46 47 void *GetModelHandle(uint32_t model_id) const; 48 49 void *GetModelStream(uint32_t model_id) const; 50 51 void UnloadModel(uint32_t model_id); 52 53 void RunModel(uint32_t model_id); 54 55 private: 56 ModelRunner() = default; 57 ~ModelRunner() = default; 58 59 std::map<uint32_t, std::shared_ptr<RuntimeModel>> runtime_models_; 60 }; 61 } // namespace mindspore::ge::model_runner 62 #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_GE_RUNTIME_MODEL_RUNNER_H_ 63