From fdf2eaea1773d066dbb48e3d214ccd5446fa918a Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Thu, 8 Jul 2021 13:07:19 +0100 Subject: IVGCVSW-6062 update ArmnnPreparedModels to have a single static instance of the threadpool Signed-off-by: Finn Williams Change-Id: Ie350a11eab5d677dd6a5571ea4094aa51b23c501 --- ArmnnPreparedModel.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ArmnnPreparedModel.cpp') diff --git a/ArmnnPreparedModel.cpp b/ArmnnPreparedModel.cpp index 388a1116..f14560a1 100644 --- a/ArmnnPreparedModel.cpp +++ b/ArmnnPreparedModel.cpp @@ -89,6 +89,9 @@ template RequestThread ArmnnPreparedModel::m_RequestThread; +template +std::unique_ptr ArmnnPreparedModel::m_Threadpool(nullptr); + template template void ArmnnPreparedModel::DumpTensorsIfRequired(char const* tensorNamePrefix, @@ -126,7 +129,7 @@ ArmnnPreparedModel::ArmnnPreparedModel(armnn::NetworkId networkId, // Enable profiling if required. m_Runtime->GetProfiler(m_NetworkId)->EnableProfiling(m_GpuProfilingEnabled); - if (asyncModelExecutionEnabled) + if (m_AsyncModelExecutionEnabled) { std::vector> memHandles; for (unsigned int i=0; i < numberOfThreads; ++i) @@ -134,8 +137,16 @@ ArmnnPreparedModel::ArmnnPreparedModel(armnn::NetworkId networkId, memHandles.emplace_back(m_Runtime->CreateWorkingMemHandle(networkId)); } + if (!m_Threadpool) + { + m_Threadpool = std::make_unique(numberOfThreads, runtime, memHandles); + } + else + { + m_Threadpool->LoadMemHandles(memHandles); + } + m_WorkingMemHandle = memHandles.back(); - m_Threadpool = std::make_unique(numberOfThreads, runtime, memHandles); } } @@ -148,6 +159,12 @@ ArmnnPreparedModel::~ArmnnPreparedModel() // Unload the network associated with this model. m_Runtime->UnloadNetwork(m_NetworkId); + // Unload the network memhandles from the threadpool + if (m_AsyncModelExecutionEnabled) + { + m_Threadpool->UnloadMemHandles(m_NetworkId); + } + // Dump the profiling info to a file if required. DumpJsonProfilingIfRequired(m_GpuProfilingEnabled, m_RequestInputsAndOutputsDumpDir, m_NetworkId, profiler.get()); } -- cgit v1.2.1