ArmNN
 21.08
AsyncExecutionCallback.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 namespace armnn
9 {
10 
11 namespace experimental
12 {
13 
15 {
16  {
17  std::lock_guard<std::mutex> hold(m_Mutex);
18  // store results and mark as notified
19  m_Status = status;
20  m_StartTime = timeTaken.first;
21  m_EndTime = timeTaken.second;
22  m_NotificationQueue.push(m_InferenceId);
23  }
24  m_Condition.notify_all();
25 }
26 
28 {
29  return m_Status;
30 }
31 
33 {
34  return m_StartTime;
35 }
36 
38 {
39  return m_EndTime;
40 }
41 
42 std::shared_ptr<AsyncExecutionCallback> AsyncCallbackManager::GetNewCallback()
43 {
44  auto cb = std::make_unique<AsyncExecutionCallback>(m_NotificationQueue, m_Mutex, m_Condition);
45  InferenceId id = cb->GetInferenceId();
46  m_Callbacks.insert({id, std::move(cb)});
47 
48  return m_Callbacks.at(id);
49 }
50 
51 std::shared_ptr<AsyncExecutionCallback> AsyncCallbackManager::GetNotifiedCallback()
52 {
53  std::unique_lock<std::mutex> lock(m_Mutex);
54 
55  m_Condition.wait(lock, [this] { return !m_NotificationQueue.empty(); });
56 
57  InferenceId id = m_NotificationQueue.front();
58  m_NotificationQueue.pop();
59 
60  std::shared_ptr<AsyncExecutionCallback> callback = m_Callbacks.at(id);
61  m_Callbacks.erase(id);
62  return callback;
63 }
64 
65 } // namespace experimental
66 
67 } // namespace armnn
std::shared_ptr< AsyncExecutionCallback > GetNewCallback()
std::chrono::high_resolution_clock::time_point HighResolutionClock
Define a timer and associated inference ID for recording execution times.
Definition: Types.hpp:324
void Notify(armnn::Status status, InferenceTimingPair timeTaken)
Copyright (c) 2021 ARM Limited and Contributors.
Status
enumeration
Definition: Types.hpp:29
std::pair< HighResolutionClock, HighResolutionClock > InferenceTimingPair
Definition: Types.hpp:325
std::shared_ptr< AsyncExecutionCallback > GetNotifiedCallback()