2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "ProfilingStateMachine.hpp"
8 #include <armnn/Exceptions.hpp>
16 ProfilingState ProfilingStateMachine::GetCurrentState() const
21 void ProfilingStateMachine::TransitionToState(ProfilingState newState)
25 case ProfilingState::Uninitialised:
27 ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
29 if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised))
31 throw armnn::Exception(std::string("Cannot transition from state [")
32 + GetProfilingStateName(expectedState)
33 +"] to [" + GetProfilingStateName(newState) + "]");
35 } while (!m_State.compare_exchange_strong(expectedState, newState,
36 std::memory_order::memory_order_relaxed));
40 case ProfilingState::NotConnected:
42 ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
44 if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised, ProfilingState::NotConnected,
45 ProfilingState::Active))
47 throw armnn::Exception(std::string("Cannot transition from state [")
48 + GetProfilingStateName(expectedState)
49 +"] to [" + GetProfilingStateName(newState) + "]");
51 } while (!m_State.compare_exchange_strong(expectedState, newState,
52 std::memory_order::memory_order_relaxed));
56 case ProfilingState::WaitingForAck:
58 ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
60 if (!IsOneOfStates(expectedState, ProfilingState::NotConnected, ProfilingState::WaitingForAck))
62 throw armnn::Exception(std::string("Cannot transition from state [")
63 + GetProfilingStateName(expectedState)
64 +"] to [" + GetProfilingStateName(newState) + "]");
66 } while (!m_State.compare_exchange_strong(expectedState, newState,
67 std::memory_order::memory_order_relaxed));
71 case ProfilingState::Active:
73 ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
75 if (!IsOneOfStates(expectedState, ProfilingState::WaitingForAck, ProfilingState::Active))
77 throw armnn::Exception(std::string("Cannot transition from state [")
78 + GetProfilingStateName(expectedState)
79 +"] to [" + GetProfilingStateName(newState) + "]");
81 } while (!m_State.compare_exchange_strong(expectedState, newState,
82 std::memory_order::memory_order_relaxed));
91 } //namespace profiling