Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 5 | |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 6 | #pragma once |
| 7 | |
| 8 | #include <atomic> |
| 9 | |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 10 | #include <armnn/utility/IgnoreUnused.hpp> |
Derek Lamberti | 1dd75b3 | 2019-12-10 21:23:23 +0000 | [diff] [blame] | 11 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 12 | namespace arm |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 13 | { |
| 14 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 15 | namespace pipe |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 16 | { |
| 17 | |
| 18 | enum class ProfilingState |
| 19 | { |
| 20 | Uninitialised, |
| 21 | NotConnected, |
| 22 | WaitingForAck, |
| 23 | Active |
| 24 | }; |
| 25 | |
| 26 | class ProfilingStateMachine |
| 27 | { |
| 28 | public: |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 29 | ProfilingStateMachine() : m_State(ProfilingState::Uninitialised) {} |
| 30 | ProfilingStateMachine(ProfilingState state) : m_State(state) {} |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 31 | |
| 32 | ProfilingState GetCurrentState() const; |
| 33 | void TransitionToState(ProfilingState newState); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 34 | void Reset(); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 35 | |
| 36 | bool IsOneOfStates(ProfilingState state1) |
| 37 | { |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 38 | armnn::IgnoreUnused(state1); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 39 | return false; |
| 40 | } |
| 41 | |
| 42 | template<typename T, typename... Args > |
| 43 | bool IsOneOfStates(T state1, T state2, Args... args) |
| 44 | { |
| 45 | if (state1 == state2) |
| 46 | { |
| 47 | return true; |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | return IsOneOfStates(state1, args...); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | std::atomic<ProfilingState> m_State; |
| 57 | }; |
| 58 | |
| 59 | constexpr char const* GetProfilingStateName(ProfilingState state) |
| 60 | { |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 61 | switch (state) |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 62 | { |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 63 | case ProfilingState::Uninitialised: return "Uninitialised"; |
| 64 | case ProfilingState::NotConnected: return "NotConnected"; |
| 65 | case ProfilingState::WaitingForAck: return "WaitingForAck"; |
| 66 | case ProfilingState::Active: return "Active"; |
| 67 | default: return "Unknown"; |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 71 | } // namespace pipe |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 72 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 73 | } // namespace arm |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 74 | |