From 5307bc10ac488261e84ac76b2dede6039ea3fe96 Mon Sep 17 00:00:00 2001 From: telsoa01 Date: Fri, 9 Mar 2018 13:51:08 +0000 Subject: Release 18.02 Change-Id: I41a89c149534a7c354a58e2c66a32cba572fc0c1 --- RequestThread.hpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 RequestThread.hpp (limited to 'RequestThread.hpp') diff --git a/RequestThread.hpp b/RequestThread.hpp new file mode 100644 index 00000000..0983793e --- /dev/null +++ b/RequestThread.hpp @@ -0,0 +1,104 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#pragma once + +#include +#include +#include +#include + +#include "CpuExecutor.h" +#include "HalInterfaces.h" +#include + +namespace armnn_driver +{ + +class ArmnnPreparedModel; + +class RequestThread +{ +public: + /// Constructor creates the thread + RequestThread(); + + /// Destructor terminates the thread + ~RequestThread(); + + /// Add a message to the thread queue. + /// @param[in] model pointer to the prepared model handling the request + /// @param[in] memPools pointer to the memory pools vector for the tensors + /// @param[in] inputTensors pointer to the input tensors for the request + /// @param[in] outputTensors pointer to the output tensors for the request + /// @param[in] callback the android notification callback + void PostMsg(armnn_driver::ArmnnPreparedModel* model, + std::shared_ptr>& memPools, + std::shared_ptr& inputTensors, + std::shared_ptr& outputTensors, + const ::android::sp& callback); + +private: + RequestThread(const RequestThread&) = delete; + RequestThread& operator=(const RequestThread&) = delete; + + /// storage for a prepared model and args for the asyncExecute call + struct AsyncExecuteData + { + AsyncExecuteData(ArmnnPreparedModel* model, + std::shared_ptr>& memPools, + std::shared_ptr& inputTensors, + std::shared_ptr& outputTensors, + const ::android::sp& cb) + : m_Model(model) + , m_MemPools(memPools) + , m_InputTensors(inputTensors) + , m_OutputTensors(outputTensors) + , m_callback(cb) + { + } + + armnn_driver::ArmnnPreparedModel* m_Model; + std::shared_ptr> m_MemPools; + std::shared_ptr m_InputTensors; + std::shared_ptr m_OutputTensors; + const ::android::sp m_callback; + }; + + enum class ThreadMsgType + { + EXIT, // exit the thread + REQUEST // user request to process + }; + + /// storage for the thread message type and data + struct ThreadMsg + { + ThreadMsg(ThreadMsgType msgType, + std::shared_ptr& msgData) + : type(msgType) + , data(msgData) + { + } + + ThreadMsgType type; + std::shared_ptr data; + }; + + /// Add a prepared thread message to the thread queue. + /// @param[in] threadMsg the message to add to the queue + void PostMsg(std::shared_ptr& pThreadMsg); + + /// Entry point for the request thread + void Process(); + + std::unique_ptr m_Thread; + std::queue> m_Queue; + std::mutex m_Mutex; + std::condition_variable m_Cv; +}; + +} // namespace armnn_driver + -- cgit v1.2.1