From e48bdff741568236d3c0747ad3d18a8eba5b36dd Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Mon, 3 Sep 2018 13:50:50 +0100 Subject: IVGCVSW-1806 Refactored Android-NN-Driver, added common "getCapabilities", "getSupportedOperations" and "prepareModel" implementations * Added common base ArmnnDriverImpl class * Added common template implementation of the driver's "getCapabilities", "getSupportedOperations" and "prepareModel" methods * Refactored ArmnnPreparedModel and RequestThread to support HAL v1.1 models * Moved "getStatus" to the common base class, as it is shared by both HAL implementations * Refactored the code where necessary Change-Id: I747334730026d63b4002662523fb93608f67c899 --- RequestThread.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'RequestThread.cpp') diff --git a/RequestThread.cpp b/RequestThread.cpp index abaee90c..8e44d8d2 100644 --- a/RequestThread.cpp +++ b/RequestThread.cpp @@ -17,13 +17,15 @@ using namespace android; namespace armnn_driver { -RequestThread::RequestThread() +template +RequestThread::RequestThread() { ALOGV("RequestThread::RequestThread()"); m_Thread = std::make_unique(&RequestThread::Process, this); } -RequestThread::~RequestThread() +template +RequestThread::~RequestThread() { ALOGV("RequestThread::~RequestThread()"); @@ -48,11 +50,12 @@ RequestThread::~RequestThread() catch (const std::exception&) { } // Swallow any exception. } -void RequestThread::PostMsg(ArmnnPreparedModel* model, - std::shared_ptr>& memPools, - std::shared_ptr& inputTensors, - std::shared_ptr& outputTensors, - const ::android::sp& callback) +template +void RequestThread::PostMsg(ArmnnPreparedModel* model, + std::shared_ptr>& memPools, + std::shared_ptr& inputTensors, + std::shared_ptr& outputTensors, + const ::android::sp& callback) { ALOGV("RequestThread::PostMsg(...)"); auto data = std::make_shared(model, @@ -64,7 +67,8 @@ void RequestThread::PostMsg(ArmnnPreparedModel* model, PostMsg(pMsg); } -void RequestThread::PostMsg(std::shared_ptr& pMsg) +template +void RequestThread::PostMsg(std::shared_ptr& pMsg) { ALOGV("RequestThread::PostMsg(pMsg)"); // Add a message to the queue and notify the request thread @@ -73,7 +77,8 @@ void RequestThread::PostMsg(std::shared_ptr& pMsg) m_Cv.notify_one(); } -void RequestThread::Process() +template +void RequestThread::Process() { ALOGV("RequestThread::Process()"); while (true) @@ -98,7 +103,7 @@ void RequestThread::Process() { ALOGV("RequestThread::Process() - request"); // invoke the asynchronous execution method - ArmnnPreparedModel* model = pMsg->data->m_Model; + ArmnnPreparedModel* model = pMsg->data->m_Model; model->ExecuteGraph(pMsg->data->m_MemPools, pMsg->data->m_InputTensors, pMsg->data->m_OutputTensors, @@ -126,5 +131,12 @@ void RequestThread::Process() } } +// Class template specializations +template class RequestThread; + +#ifdef ARMNN_ANDROID_NN_V1_1 // Using ::android::hardware::neuralnetworks::V1_1. +template class RequestThread; +#endif + } // namespace armnn_driver -- cgit v1.2.1