You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

executor_manager.cc 1.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 {
  20. std::shared_ptr<Executor> ExecutorManager::GetExecutor(const std::string &device_name, int 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. void ExecutorManager::OnEvent(const ExecutorEvent &event) {
  31. for (auto &item : executors_) {
  32. auto &executor = item.second;
  33. if (executor != nullptr) {
  34. executor->OnEvent(event);
  35. }
  36. }
  37. }
  38. void ExecutorManager::Clear() {
  39. OnEvent(ExecutorEvent::kClear);
  40. executors_.clear();
  41. common::ThreadPool::GetInstance().ClearThreadPool();
  42. }
  43. } // namespace session
  44. } // namespace mindspore