ArmNN
 22.11
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 #if !defined(ARMNN_DISABLE_THREADS)
18  std::lock_guard<std::mutex> hold(m_Mutex);
19 #endif
20  // store results and mark as notified
21  m_Status = status;
22  m_StartTime = timeTaken.first;
23  m_EndTime = timeTaken.second;
24  m_NotificationQueue.push(m_InferenceId);
25  }
26 #if !defined(ARMNN_DISABLE_THREADS)
27  m_Condition.notify_all();
28 #endif
29 }
30 
32 {
33  return m_Status;
34 }
35 
37 {
38  return m_StartTime;
39 }
40 
42 {
43  return m_EndTime;
44 }
45 
46 std::shared_ptr<AsyncExecutionCallback> AsyncCallbackManager::GetNewCallback()
47 {
48  auto cb = std::make_unique<AsyncExecutionCallback>(m_NotificationQueue
49 #if !defined(ARMNN_DISABLE_THREADS)
50  , m_Mutex
51  , m_Condition
52 #endif
53  );
54  InferenceId id = cb->GetInferenceId();
55  m_Callbacks.insert({id, std::move(cb)});
56 
57  return m_Callbacks.at(id);
58 }
59 
60 std::shared_ptr<AsyncExecutionCallback> AsyncCallbackManager::GetNotifiedCallback()
61 {
62 #if !defined(ARMNN_DISABLE_THREADS)
63  std::unique_lock<std::mutex> lock(m_Mutex);
64 
65  m_Condition.wait(lock, [this] { return !m_NotificationQueue.empty(); });
66 #endif
67  InferenceId id = m_NotificationQueue.front();
68  m_NotificationQueue.pop();
69 
70  std::shared_ptr<AsyncExecutionCallback> callback = m_Callbacks.at(id);
71  m_Callbacks.erase(id);
72  return callback;
73 }
74 
75 } // namespace experimental
76 
77 } // 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:382
void Notify(armnn::Status status, InferenceTimingPair timeTaken)
Copyright (c) 2021 ARM Limited and Contributors.
Status
enumeration
Definition: Types.hpp:42
std::pair< HighResolutionClock, HighResolutionClock > InferenceTimingPair
Definition: Types.hpp:383
std::shared_ptr< AsyncExecutionCallback > GetNotifiedCallback()