aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/backendsCommon')
-rw-r--r--src/backends/backendsCommon/DefaultAllocator.hpp4
-rw-r--r--src/backends/backendsCommon/MemoryManager.cpp2
-rw-r--r--src/backends/backendsCommon/MemoryManager.hpp11
-rw-r--r--src/backends/backendsCommon/common.mk7
-rw-r--r--src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.cpp4
-rw-r--r--src/backends/backendsCommon/test/CompatibilityTests.cpp6
-rw-r--r--src/backends/backendsCommon/test/MemoryManagerTests.cpp40
-rw-r--r--src/backends/backendsCommon/test/OptimizedNetworkTests.cpp4
8 files changed, 42 insertions, 36 deletions
diff --git a/src/backends/backendsCommon/DefaultAllocator.hpp b/src/backends/backendsCommon/DefaultAllocator.hpp
index 2451db3ab8..cf0f1774f0 100644
--- a/src/backends/backendsCommon/DefaultAllocator.hpp
+++ b/src/backends/backendsCommon/DefaultAllocator.hpp
@@ -22,12 +22,12 @@ public:
void* allocate(size_t size, size_t alignment = 0) override
{
IgnoreUnused(alignment);
- return ::operator new(size);
+ return ::operator new(size_t(size));
}
void free(void* ptr) override
{
- std::free(ptr);
+ ::operator delete(ptr);
}
armnn::MemorySource GetMemorySourceType() override
diff --git a/src/backends/backendsCommon/MemoryManager.cpp b/src/backends/backendsCommon/MemoryManager.cpp
index 1c109c3c91..77cab27789 100644
--- a/src/backends/backendsCommon/MemoryManager.cpp
+++ b/src/backends/backendsCommon/MemoryManager.cpp
@@ -11,7 +11,7 @@ namespace armnn
{
void MemoryManager::StoreMemToAllocate(std::vector<BufferStorage> bufferStorageVector,
- ICustomAllocator* customAllocator,
+ std::shared_ptr<ICustomAllocator> customAllocator,
const size_t typeAlignment)
{
IgnoreUnused(typeAlignment);
diff --git a/src/backends/backendsCommon/MemoryManager.hpp b/src/backends/backendsCommon/MemoryManager.hpp
index cbd6fcf9bc..5113b231d3 100644
--- a/src/backends/backendsCommon/MemoryManager.hpp
+++ b/src/backends/backendsCommon/MemoryManager.hpp
@@ -2,6 +2,7 @@
// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
+#pragma once
#include <armnn/backends/ICustomAllocator.hpp>
@@ -10,7 +11,7 @@ namespace armnn
struct Allocator
{
/// Pointer to @ICustomAllocator.
- ICustomAllocator* m_CustomAllocator{};
+ std::shared_ptr<ICustomAllocator> m_CustomAllocator{};
/// Value which the size of each buffer (actual data size + padding) has to be a multiple of.
size_t m_Alignment = 0 ;
};
@@ -19,16 +20,16 @@ struct TensorMemory
{
/// Number of bytes the value is away from the @BufferStorage.m_Buffer.
size_t m_Offset{};
- /// Pointer to the tensor value.
- void* m_Data = nullptr;
/// Identifier to be used by the @LoadedNetwork to order the tensors.
unsigned int m_OutputSlotId{};
+ /// Pointer to the tensor value.
+ void* m_Data = nullptr;
};
struct BufferStorage
{
/// Vector of pointer to @TensorMemory.
- std::vector<TensorMemory*> m_TensorMemoryVector;
+ std::vector<std::shared_ptr<TensorMemory>> m_TensorMemoryVector;
/// Total size of the buffer.
size_t m_BufferSize;
/// Pointer to the first element of the buffer.
@@ -43,7 +44,7 @@ public:
/// @param[in] customAllocator - Pointer to @ICustomAllocator.
/// @param[in] typeAlignment - Optional parameter. Value of which the size of each value has to be multiple of.
void StoreMemToAllocate(std::vector<BufferStorage> bufferStorageVector,
- ICustomAllocator* customAllocator,
+ std::shared_ptr<ICustomAllocator> customAllocator,
size_t typeAlignment = 0);
/// Allocate the amount of memory indicated by @m_BufferSize, and
diff --git a/src/backends/backendsCommon/common.mk b/src/backends/backendsCommon/common.mk
index a77ec06035..56c9d6545a 100644
--- a/src/backends/backendsCommon/common.mk
+++ b/src/backends/backendsCommon/common.mk
@@ -17,6 +17,7 @@ COMMON_SOURCES := \
MapWorkload.cpp \
MemCopyWorkload.cpp \
MemImportWorkload.cpp \
+ MemoryManager.cpp \
MemSyncWorkload.cpp \
OptimizationViews.cpp \
TensorHandleFactoryRegistry.cpp \
@@ -25,7 +26,8 @@ COMMON_SOURCES := \
WorkloadFactory.cpp \
WorkloadUtils.cpp \
memoryOptimizerStrategyLibrary/strategies/ConstantMemoryStrategy.cpp \
- memoryOptimizerStrategyLibrary/strategies/StrategyValidator.cpp \
+ memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.cpp \
+ memoryOptimizerStrategyLibrary/strategies/StrategyValidator.cpp
# COMMON_TEST_SOURCES contains the list of files to be included
@@ -104,7 +106,8 @@ COMMON_TEST_SOURCES := \
test/layerTests/TransposeConvolution2dTestImpl.cpp \
test/layerTests/UnidirectionalSequenceLstmTestImpl.cpp \
memoryOptimizerStrategyLibrary/test/ConstMemoryStrategyTests.cpp \
- memoryOptimizerStrategyLibrary/test/ValidatorStrategyTests.cpp
+ memoryOptimizerStrategyLibrary/test/ValidatorStrategyTests.cpp \
+ memoryOptimizerStrategyLibrary/test/SingleAxisPriorityListTests.cpp
ifeq ($(ARMNN_REF_ENABLED),1)
COMMON_TEST_SOURCES += \
diff --git a/src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.cpp b/src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.cpp
index 3afa061681..738b7137a7 100644
--- a/src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.cpp
+++ b/src/backends/backendsCommon/memoryOptimizerStrategyLibrary/strategies/SingleAxisPriorityList.cpp
@@ -155,9 +155,9 @@ void SingleAxisPriorityList::PlaceBlocks(const std::list<MemBlock*>& priorityLis
// The indexes don't match we need at least two words
// Zero the bits to the right of curBlock->m_EndOfLife
- remainder = (curBlock->m_EndOfLife +1 - lastWordIndex * wordSize);
+ remainder = (curBlock->m_EndOfLife - lastWordIndex * wordSize);
- size_t lastWord = (1u << remainder) - 1;
+ size_t lastWord = (1ul << remainder) - 1;
lastWord = lastWord << (wordSize - remainder);
if(firstWordIndex + 1 == lastWordIndex)
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<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());
}
}
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);
}