Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / hetero_plugin / hetero_async_infer_request.cpp
1 //
2 // Copyright 2017-2018 Intel Corporation.
3 //
4 // This software and the related documents are Intel copyrighted materials,
5 // and your use of them is governed by the express license under which they
6 // were provided to you (End User License Agreement for the Intel(R) Software
7 // Development Products (Version May 2017)). Unless the License provides
8 // otherwise, you may not use, modify, copy, publish, distribute, disclose or
9 // transmit this software or the related documents without Intel's prior
10 // written permission.
11 //
12 // This software and the related documents are provided as is, with no
13 // express or implied warranties, other than those that are expressly
14 // stated in the License.
15 //
16
17 #include "hetero_async_infer_request.h"
18 #include <assert.h>
19 #include <ie_util_internal.hpp>
20 #include <ie_profiling.hpp>
21
22 using namespace HeteroPlugin;
23 using namespace InferenceEngine;
24
25 HeteroAsyncInferRequest::HeteroAsyncInferRequest(HeteroInferRequest::Ptr request,
26                                                  const ITaskExecutor::Ptr &taskExecutor,
27                                                  const TaskSynchronizer::Ptr &taskSynchronizer,
28                                                  const ITaskExecutor::Ptr &callbackExecutor)
29         : AsyncInferRequestThreadSafeDefault(request, taskExecutor, taskSynchronizer, callbackExecutor),
30           _heteroInferRequest(request) {
31     _heteroInferRequest->setCallbackSequence();
32
33     std::function<void(InferRequest, StatusCode)> f =
34         [&](InferRequest /*request*/, StatusCode /*sts*/) {
35             setIsRequestBusy(false);
36         };
37
38     _heteroInferRequest->setCallbackForLastRequest(f);
39 }
40
41 void HeteroAsyncInferRequest::StartAsync() {
42     IE_PROFILING_AUTO_SCOPE(Hetero_Async)
43     if (isRequestBusy()) THROW_IE_EXCEPTION << REQUEST_BUSY_str;
44     setIsRequestBusy(true);
45     _heteroInferRequest->updateInOutIfNeeded();
46     _heteroInferRequest->startFirstAsyncRequest();
47 }
48
49 InferenceEngine::StatusCode HeteroAsyncInferRequest::Wait(int64_t millis_timeout) {
50     auto sts = _heteroInferRequest->waitAllRequests(millis_timeout);
51     if (sts != StatusCode::RESULT_NOT_READY && sts != StatusCode::REQUEST_BUSY) {
52         setIsRequestBusy(false);
53     }
54     return sts;
55 }
56
57 void HeteroAsyncInferRequest::SetCompletionCallback(IInferRequest::CompletionCallback callback) {
58     AsyncInferRequestThreadSafeDefault::SetCompletionCallback(callback);
59
60     std::function<void(InferRequest, StatusCode)> f =
61             [&](InferRequest /*request*/, StatusCode sts) {
62                 setIsRequestBusy(false);
63                 _callbackManager.set_requestStatus(sts);
64                 _callbackManager.runCallback();
65             };
66
67     _heteroInferRequest->setCallbackForLastRequest(f);
68 }