diff options
author | Finn Williams <finn.williams@arm.com> | 2021-10-28 19:07:32 +0100 |
---|---|---|
committer | Finn Williams <finn.williams@arm.com> | 2021-11-08 14:33:17 +0000 |
commit | b1aad4270fa8ad5c4aa62e27d564baf723b2cee5 (patch) | |
tree | 98b19ba85b50e2c730d5d2e3822cd2b1438bd149 /src/backends/backendsCommon/test/MemoryManagerTests.cpp | |
parent | 3f22d27f51c493e37b9da0692b6bf776f4430dcf (diff) | |
download | armnn-b1aad4270fa8ad5c4aa62e27d564baf723b2cee5.tar.gz |
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 <finn.williams@arm.com>
Change-Id: I2216a724028312eb101b290df3f224177826b1a0
Diffstat (limited to 'src/backends/backendsCommon/test/MemoryManagerTests.cpp')
-rw-r--r-- | src/backends/backendsCommon/test/MemoryManagerTests.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
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<TensorMemory*> tensorMemoryPointerVector(numTensors); - std::vector<TensorMemory> tensorMemoryVector; + std::vector<std::shared_ptr<TensorMemory>> tensorMemoryPointerVector(numTensors); + std::vector<std::shared_ptr<TensorMemory>> tensorMemoryVector; tensorMemoryVector.reserve(numTensors); std::vector<size_t> 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>(TensorMemory{offsets[idx], 0, nullptr})); + + tensorMemoryPointerVector[idx] = tensorMemoryVector[idx]; } std::vector<BufferStorage> 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<SampleCustomAllocator> customAllocator = + std::make_unique<SampleCustomAllocator>(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<uint8_t *>(tensorMemory->m_Data); - CHECK(customAllocator.m_Values[idx] == *value); - idx += 1; - } + auto value = reinterpret_cast<uint8_t *>(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()); } } |