1 /** 2 * Copyright 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 #include "backend/session/executor_manager.h" 17 #include "common/thread_pool.h" 18 namespace mindspore { 19 namespace session { GetExecutor(const std::string & device_name,uint32_t device_id)20std::shared_ptr<Executor> ExecutorManager::GetExecutor(const std::string &device_name, uint32_t device_id) { 21 std::string device_key = device_name + "_" + std::to_string(device_id); 22 auto iter = executors_.find(device_key); 23 if (iter != executors_.end()) { 24 return iter->second; 25 } 26 auto executor = std::make_shared<Executor>(device_name, device_id); 27 executors_[device_key] = executor; 28 return executor; 29 } 30 OnEvent(const ExecutorEvent & event)31void ExecutorManager::OnEvent(const ExecutorEvent &event) { 32 for (auto &item : executors_) { 33 auto &executor = item.second; 34 if (executor != nullptr) { 35 executor->OnEvent(event); 36 } 37 } 38 } 39 Clear()40void ExecutorManager::Clear() { 41 OnEvent(ExecutorEvent::kClear); 42 executors_.clear(); 43 common::ThreadPool::GetInstance().ClearThreadPool(); 44 } 45 } // namespace session 46 } // namespace mindspore 47