1 // Copyright (C) 2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
12 #include "inference_engine.hpp"
14 typedef std::chrono::high_resolution_clock Time;
15 typedef std::chrono::nanoseconds ns;
17 /// @brief Wrapper class for InferenceEngine::InferRequest. Handles asynchronous callbacks and calculates execution time.
20 using Ptr = std::shared_ptr<InferReqWrap>;
22 explicit InferReqWrap(InferenceEngine::ExecutableNetwork& net) : _request(net.CreateInferRequest()) {
23 _request.SetCompletionCallback(
25 _endTime = Time::now();
30 _startTime = Time::now();
31 _request.StartAsync();
35 _startTime = Time::now();
37 _endTime = Time::now();
40 std::map<std::string, InferenceEngine::InferenceEngineProfileInfo> getPerformanceCounts() {
41 return _request.GetPerformanceCounts();
45 InferenceEngine::StatusCode code = _request.Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY);
46 if (code != InferenceEngine::StatusCode::OK) {
47 throw std::logic_error("Wait");
51 InferenceEngine::Blob::Ptr getBlob(const std::string &name) {
52 return _request.GetBlob(name);
55 double getExecTime() const {
56 auto execTime = std::chrono::duration_cast<ns>(_endTime - _startTime);
57 return static_cast<double>(execTime.count()) * 0.000001;
61 InferenceEngine::InferRequest _request;
62 Time::time_point _startTime;
63 Time::time_point _endTime;