Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / cpp_interfaces / impl / ie_executable_network_thread_safe_default.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <vector>
8 #include <memory>
9 #include <map>
10 #include <string>
11 #include "cpp_interfaces/base/ie_infer_async_request_base.hpp"
12 #include "cpp_interfaces/impl/ie_executable_network_internal.hpp"
13 #include "cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp"
14 #include "cpp_interfaces/impl/ie_infer_request_internal.hpp"
15 #include "cpp_interfaces/ie_task_executor.hpp"
16
17 namespace InferenceEngine {
18
19 class ExecutableNetworkThreadSafeDefault
20         : public ExecutableNetworkInternal, public std::enable_shared_from_this<ExecutableNetworkThreadSafeDefault> {
21 public:
22     typedef std::shared_ptr<ExecutableNetworkThreadSafeDefault> Ptr;
23
24     ExecutableNetworkThreadSafeDefault() {
25         _taskSynchronizer = std::make_shared<TaskSynchronizer>();
26         _taskExecutor = std::make_shared<TaskExecutor>();
27         _callbackExecutor = std::make_shared<TaskExecutor>();
28     }
29
30     /**
31      * @brief Create a synchronous inference request object used to infer the network
32      */
33     virtual InferRequestInternal::Ptr
34     CreateInferRequestImpl(InputsDataMap networkInputs, OutputsDataMap networkOutputs) = 0;
35
36     /**
37      * @brief Given optional implementation of creating async infer request to avoid need for it to be implemented by plugin
38      * @param asyncRequest - shared_ptr for the created async request
39      */
40     void CreateInferRequest(IInferRequest::Ptr &asyncRequest) override {
41         auto syncRequestImpl = this->CreateInferRequestImpl(_networkInputs, _networkOutputs);
42         syncRequestImpl->setPointerToExecutableNetworkInternal(shared_from_this());
43         auto asyncTreadSafeImpl = std::make_shared<AsyncInferRequestThreadSafeDefault>(
44                 syncRequestImpl, _taskExecutor, _taskSynchronizer, _callbackExecutor);
45         asyncRequest.reset(new InferRequestBase<AsyncInferRequestThreadSafeDefault>(asyncTreadSafeImpl),
46                            [](IInferRequest *p) { p->Release(); });
47         asyncTreadSafeImpl->SetPointerToPublicInterface(asyncRequest);
48     }
49
50 protected:
51     TaskSynchronizer::Ptr _taskSynchronizer;
52     ITaskExecutor::Ptr _taskExecutor = nullptr;
53     ITaskExecutor::Ptr _callbackExecutor = nullptr;
54 };
55
56 }  // namespace InferenceEngine