From b1aad4270fa8ad5c4aa62e27d564baf723b2cee5 Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Thu, 28 Oct 2021 19:07:32 +0100 Subject: IVGCVSW-6527 Support the new memory API in loaded network * enable external memory management for neon and ref backends * change m_TensorMemoryVector to hold shared pointers * change input layer backend Id to match backend id of connected layer Signed-off-by: Finn Williams Change-Id: I2216a724028312eb101b290df3f224177826b1a0 --- .../backendsCommon/test/CompatibilityTests.cpp | 6 ++-- .../backendsCommon/test/MemoryManagerTests.cpp | 40 ++++++++++++---------- .../backendsCommon/test/OptimizedNetworkTests.cpp | 4 +-- 3 files changed, 26 insertions(+), 24 deletions(-) (limited to 'src/backends/backendsCommon/test') diff --git a/src/backends/backendsCommon/test/CompatibilityTests.cpp b/src/backends/backendsCommon/test/CompatibilityTests.cpp index d18a8fbb6c..3685f75986 100644 --- a/src/backends/backendsCommon/test/CompatibilityTests.cpp +++ b/src/backends/backendsCommon/test/CompatibilityTests.cpp @@ -181,7 +181,7 @@ TEST_CASE ("Ref_Backends_Capability_Test") {"ProtectedContentAllocation", false}, {"ConstantTensorsAsInputs", true}, {"PreImportIOTensors", true}, - {"ExternallyManagedMemory", false}, + {"ExternallyManagedMemory", true}, {"MultiAxisPacking", false}}); } @@ -200,7 +200,7 @@ TEST_CASE ("Neon_Backends_Capability_Test") {"ProtectedContentAllocation", false}, {"ConstantTensorsAsInputs", false}, {"PreImportIOTensors", false}, - {"ExternallyManagedMemory", false}, + {"ExternallyManagedMemory", true}, {"MultiAxisPacking", false}}); } @@ -219,7 +219,7 @@ TEST_CASE ("Cl_Backends_Capability_Test") {"ProtectedContentAllocation", true}, {"ConstantTensorsAsInputs", false}, {"PreImportIOTensors", false}, - {"ExternallyManagedMemory", false}, + {"ExternallyManagedMemory", true}, {"MultiAxisPacking", false}}); } diff --git a/src/backends/backendsCommon/test/MemoryManagerTests.cpp b/src/backends/backendsCommon/test/MemoryManagerTests.cpp index c873499ef3..662a5c2423 100644 --- a/src/backends/backendsCommon/test/MemoryManagerTests.cpp +++ b/src/backends/backendsCommon/test/MemoryManagerTests.cpp @@ -59,17 +59,18 @@ TEST_CASE("MemoryManagerTest") // Create mock up bufferStorageVector with 2 BufferStorage with the same TensorMemory size_t numTensors = 5; - std::vector tensorMemoryPointerVector(numTensors); - std::vector tensorMemoryVector; + std::vector> tensorMemoryPointerVector(numTensors); + std::vector> tensorMemoryVector; tensorMemoryVector.reserve(numTensors); std::vector offsets(numTensors); std::iota(std::begin(offsets), std::end(offsets), 0); - for (uint32_t idx = 0; idx < tensorMemoryPointerVector.size(); ++idx) + for (uint idx = 0; idx < tensorMemoryPointerVector.size(); ++idx) { - tensorMemoryVector.emplace_back(TensorMemory{offsets[idx], nullptr, 0}); - tensorMemoryPointerVector[idx] = &tensorMemoryVector[idx]; + tensorMemoryVector.emplace_back(std::make_shared(TensorMemory{offsets[idx], 0, nullptr})); + + tensorMemoryPointerVector[idx] = tensorMemoryVector[idx]; } std::vector bufferStorageVector; @@ -77,30 +78,31 @@ TEST_CASE("MemoryManagerTest") bufferStorageVector.emplace_back(BufferStorage{tensorMemoryPointerVector, numTensors}); // Create an instance of the SampleCustomAllocator - SampleCustomAllocator customAllocator = SampleCustomAllocator(); - customAllocator.m_Values = {10, 11, 12, 13, 14}; + std::shared_ptr customAllocator = + std::make_unique(SampleCustomAllocator()); + + customAllocator->m_Values = {10, 11, 12, 13, 14}; // Check that the test was set up correctly - CHECK(customAllocator.m_Values.size() == numTensors); + CHECK(customAllocator->m_Values.size() == numTensors); + size_t bufferVecSize = bufferStorageVector.size(); // Utilise 3 functions in the MemoryManager. Check the counters and the pointer to the values are correct. MemoryManager memoryManager; - memoryManager.StoreMemToAllocate(bufferStorageVector, &customAllocator); + memoryManager.StoreMemToAllocate(bufferStorageVector, customAllocator); memoryManager.Allocate(); - CHECK(customAllocator.m_CounterAllocate == bufferStorageVector.size()); - for (const auto& bufferStorage : bufferStorageVector) + CHECK(customAllocator->m_CounterAllocate == bufferVecSize); + + uint idx = 0; + for (auto tensorMemory : tensorMemoryVector) { - uint32_t idx = 0; - for (auto tensorMemory : bufferStorage.m_TensorMemoryVector) - { - auto value = reinterpret_cast(tensorMemory->m_Data); - CHECK(customAllocator.m_Values[idx] == *value); - idx += 1; - } + auto value = reinterpret_cast(tensorMemory->m_Data); + CHECK(customAllocator->m_Values[idx] == *value); + idx += 1; } memoryManager.Deallocate(); - CHECK(customAllocator.m_CounterFree == bufferStorageVector.size()); + CHECK(customAllocator->m_CounterFree == bufferStorageVector.size()); } } diff --git a/src/backends/backendsCommon/test/OptimizedNetworkTests.cpp b/src/backends/backendsCommon/test/OptimizedNetworkTests.cpp index 012737e1d7..b0ee9bee32 100644 --- a/src/backends/backendsCommon/test/OptimizedNetworkTests.cpp +++ b/src/backends/backendsCommon/test/OptimizedNetworkTests.cpp @@ -138,7 +138,7 @@ TEST_CASE("OptimizeValidateDeviceNonSupportLayerWithFallback") // the other layers are supported by CpuRef. // If NEON is not enabled, all layers are supported by CpuRef. #if defined(ARMCOMPUTENEON_ENABLED) - if (layer->GetType() == armnn::LayerType::Input || layer->GetType() == armnn::LayerType::Output) + if (layer->GetType() == armnn::LayerType::Output) { CHECK(layer->GetBackendId() == armnn::Compute::CpuAcc); } @@ -337,7 +337,7 @@ TEST_CASE("OptimizeValidateWorkloadsDuplicateComputeDeviceWithFallback") // the other layers are supported by CpuRef. // If neither NEON, nor CL is enabled, all layers are supported by CpuRef. #if defined(ARMCOMPUTENEON_ENABLED) - if (layer->GetType() == armnn::LayerType::Input || layer->GetType() == armnn::LayerType::Output) + if (layer->GetType() == armnn::LayerType::Output) { CHECK(layer->GetBackendId() == armnn::Compute::CpuAcc); } -- cgit v1.2.1