1 /** 2 * Copyright 2021 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 #ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_GE_RUNTIME_TASK_LABEL_MANAGER_H_ 17 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_GE_RUNTIME_TASK_LABEL_MANAGER_H_ 18 19 #include <vector> 20 #include <memory> 21 #include <mutex> 22 #include <map> 23 #include <string> 24 #include "runtime/base.h" 25 26 namespace mindspore::ge::model_runner { 27 class LabelGuard { 28 public: LabelGuard(void * label_info)29 explicit LabelGuard(void *label_info) : label_info_(reinterpret_cast<uintptr_t>(label_info)) {} 30 ~LabelGuard(); GetLabelInfo()31 void *GetLabelInfo() noexcept { return reinterpret_cast<void *>(label_info_); } 32 33 private: 34 uintptr_t label_info_; 35 }; 36 37 class LabelManager { 38 public: 39 static std::shared_ptr<LabelManager> GetInstance(); 40 std::shared_ptr<LabelGuard> GetLabelInfo(rtModel_t model, const std::vector<uint32_t> &label_ids, 41 const std::vector<void *> &all_label); 42 43 private: 44 std::mutex model_info_mapping_mutex_; 45 std::map<rtModel_t, std::map<std::string, std::weak_ptr<LabelGuard>>> model_info_mapping_; 46 47 static std::weak_ptr<LabelManager> instance_; 48 static std::mutex instance_mutex_; 49 }; 50 } // namespace mindspore::ge::model_runner 51 #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_GE_RUNTIME_TASK_LABEL_MANAGER_H_ 52