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_1_2.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ArmnnPreparedModel_1_2.cpp') diff --git a/ArmnnPreparedModel_1_2.cpp b/ArmnnPreparedModel_1_2.cpp index e46b5be3..5a10d546 100644 --- a/ArmnnPreparedModel_1_2.cpp +++ b/ArmnnPreparedModel_1_2.cpp @@ -124,6 +124,9 @@ template RequestThread ArmnnPreparedModel_1_2::m_RequestThread; +template +std::unique_ptr ArmnnPreparedModel_1_2::m_Threadpool(nullptr); + template template void ArmnnPreparedModel_1_2::DumpTensorsIfRequired(char const* tensorNamePrefix, @@ -161,7 +164,7 @@ ArmnnPreparedModel_1_2::ArmnnPreparedModel_1_2(armnn::NetworkId netw // 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) @@ -169,8 +172,16 @@ ArmnnPreparedModel_1_2::ArmnnPreparedModel_1_2(armnn::NetworkId netw 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); } } @@ -183,6 +194,12 @@ ArmnnPreparedModel_1_2::~ArmnnPreparedModel_1_2() // 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