ArmNN
 22.02
ProfilingStateMachine.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include <armnn/Exceptions.hpp>
9 
10 #include <sstream>
11 
12 namespace armnn
13 {
14 
15 namespace profiling
16 {
17 
18 namespace
19 {
20 
21 void ThrowStateTransitionException(ProfilingState expectedState, ProfilingState newState)
22 {
23  std::stringstream ss;
24  ss << "Cannot transition from state [" << GetProfilingStateName(expectedState) << "] "
25  << "to state [" << GetProfilingStateName(newState) << "]";
26  throw armnn::RuntimeException(ss.str());
27 }
28 
29 } // Anonymous namespace
30 
32 {
33  return m_State.load();
34 }
35 
37 {
38  ProfilingState currentState = m_State.load(std::memory_order::memory_order_relaxed);
39 
40  switch (newState)
41  {
43  do
44  {
45  if (!IsOneOfStates(currentState, ProfilingState::Uninitialised))
46  {
47  ThrowStateTransitionException(currentState, newState);
48  }
49  }
50  while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed));
51  break;
53  do
54  {
57  {
58  ThrowStateTransitionException(currentState, newState);
59  }
60  }
61  while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed));
62  break;
64  do
65  {
67  {
68  ThrowStateTransitionException(currentState, newState);
69  }
70  }
71  while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed));
72  break;
74  do
75  {
77  {
78  ThrowStateTransitionException(currentState, newState);
79  }
80  }
81  while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed));
82  break;
83  default:
84  break;
85  }
86 }
87 
89 {
90  m_State.store(ProfilingState::Uninitialised);
91 }
92 
93 } // namespace profiling
94 
95 } // namespace armnn
Copyright (c) 2021 ARM Limited and Contributors.
void TransitionToState(ProfilingState newState)
constexpr char const * GetProfilingStateName(ProfilingState state)