ie_executor_manager.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @file ie_executor_manager.hpp
7  * @brief A header file for Executor Manager
8  */
9 
10 #pragma once
11 
12 #include <string>
13 #include <unordered_map>
14 #include <vector>
15 #include <utility>
16 #include <mutex>
17 
20 
21 namespace InferenceEngine {
22 
23 /**
24  * @cond
25  */
26 class ExecutorManagerImpl {
27 public:
28  ITaskExecutor::Ptr getExecutor(std::string id);
29 
30  IStreamsExecutor::Ptr getIdleCPUStreamsExecutor(const IStreamsExecutor::Config& config);
31 
32  // for tests purposes
33  size_t getExecutorsNumber();
34 
35  // for tests purposes
36  size_t getIdleCPUStreamsExecutorsNumber();
37 
38  void clear(const std::string& id = {});
39 
40 private:
41  std::unordered_map<std::string, ITaskExecutor::Ptr> executors;
42  std::vector<std::pair<IStreamsExecutor::Config, IStreamsExecutor::Ptr> > cpuStreamsExecutors;
43  std::mutex streamExecutorMutex;
44  std::mutex taskExecutorMutex;
45 };
46 
47 /**
48  * @endcond
49  */
50 
51 /**
52  * @brief This is global point for getting task executor objects by string id.
53  * It's necessary in multiple asynchronous requests for having unique executors to avoid oversubscription.
54  * E.g. There 2 task executors for CPU device: one - in FPGA, another - in MKLDNN. Parallel execution both of them leads
55  * to not optimal CPU usage. More efficient to run the corresponding tasks one by one via single executor.
56  * @ingroup ie_dev_api_threading
57  */
58 class INFERENCE_ENGINE_API_CLASS(ExecutorManager) {
59 public:
60  /**
61  * @brief Returns a global instance of ExecutorManager
62  * @return The instance.
63  */
65 
66  /**
67  * @brief A deleted copy constructor
68  */
69  ExecutorManager(ExecutorManager const&) = delete;
70 
71  /**
72  * @brief A deleted assignment operator.
73  */
74  void operator=(ExecutorManager const&) = delete;
75 
76  /**
77  * @brief Returns executor by unique identificator
78  * @param id An unique identificator of device (Usually string representation of TargetDevice)
79  * @return A shared pointer to existing or newly ITaskExecutor
80  */
82 
83  /// @private
84  IStreamsExecutor::Ptr getIdleCPUStreamsExecutor(const IStreamsExecutor::Config& config);
85 
86  /**
87  * @cond
88  */
89  size_t getExecutorsNumber();
90 
91  size_t getIdleCPUStreamsExecutorsNumber();
92 
93  void clear(const std::string& id = {});
94  /**
95  * @endcond
96  */
97 
98 private:
99  ExecutorManager() {}
100 
101  ExecutorManagerImpl _impl;
102 
103  static std::mutex _mutex;
104  static ExecutorManager *_instance;
105 };
106 
107 } // namespace InferenceEngine
This is global point for getting task executor objects by string id. It's necessary in multiple async...
Definition: ie_executor_manager.hpp:58
static ExecutorManager * getInstance()
Returns a global instance of ExecutorManager.
ITaskExecutor::Ptr getExecutor(std::string id)
Returns executor by unique identificator.
ExecutorManager(ExecutorManager const &)=delete
A deleted copy constructor.
void operator=(ExecutorManager const &)=delete
A deleted assignment operator.
std::shared_ptr< IStreamsExecutor > Ptr
Definition: ie_istreams_executor.hpp:36
std::shared_ptr< ITaskExecutor > Ptr
Definition: ie_itask_executor.hpp:51
A header file for Inference Engine Streams-based Executor Interface.
A header file for Inference Engine Task Executor Interface.
Inference Engine Plugin API namespace.
Defines IStreamsExecutor configuration.
Definition: ie_istreams_executor.hpp:52