// // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once #include #include #include "INetwork.hpp" #include "IRuntime.hpp" #include #include #include #include #include namespace armnn { namespace experimental { class Threadpool { public: Threadpool(std::size_t numThreads, IRuntime* runtimePtr, std::vector> memHandles); ~Threadpool() { TerminateThreadPool(); } void LoadMemHandles(std::vector> memHandles); void UnloadMemHandles(NetworkId networkId); /// Schedule an asynchronous execution on the loaded network void Schedule(NetworkId networkId, const InputTensors &inputTensors, const OutputTensors &outputTensors, const QosExecPriority priority, std::shared_ptr cb); void TerminateThreadPool() noexcept; private: using ExecutionTuple = std::tuple>; using ExecutionQueue = std::queue>; void ProcessExecPriorities(uint32_t index); IRuntime* m_RuntimePtr; ExecutionQueue m_HighPriorityQueue; ExecutionQueue m_MediumPriorityQueue; ExecutionQueue m_LowPriorityQueue; // Condition Variables require mutex which will guard the shared state. // Has an event happened? Stop signal for example std::condition_variable m_ThreadPoolEvent; std::mutex m_ThreadPoolMutex; // The shared state for conditional variable bool m_TerminatePool = false; std::unordered_map>> m_WorkingMemHandleMap; std::vector> m_Threads; }; } // namespace experimental } // namespace armnn