9 #include <doctest/doctest.h> 18 SampleCustomAllocator() =
default;
20 void* allocate(
size_t size,
size_t alignment)
override 23 CHECK(size == m_Values.size());
25 return m_Values.data();
28 void free(
void* ptr)
override 30 CHECK(ptr == m_Values.data());
39 virtual void* GetMemoryRegionAtOffset(
void* buffer,
size_t offset,
size_t alignment = 0 )
override 42 return (static_cast<char*>(buffer) + offset);
46 std::vector<uint8_t> m_Values;
48 unsigned long m_CounterAllocate= 0;
50 unsigned long m_CounterFree = 0;
56 TEST_CASE(
"MemoryManagerTest")
58 using namespace armnn;
61 size_t numTensors = 5;
62 std::vector<std::shared_ptr<TensorMemory>> tensorMemoryPointerVector(numTensors);
63 std::vector<std::shared_ptr<TensorMemory>> tensorMemoryVector;
64 tensorMemoryVector.reserve(numTensors);
66 std::vector<size_t> offsets(numTensors);
67 std::iota(std::begin(offsets), std::end(offsets), 0);
69 for (uint32_t idx = 0; idx < tensorMemoryPointerVector.size(); ++idx)
71 tensorMemoryVector.emplace_back(std::make_shared<TensorMemory>(
TensorMemory{offsets[idx], 0,
nullptr}));
73 tensorMemoryPointerVector[idx] = tensorMemoryVector[idx];
76 std::vector<BufferStorage> bufferStorageVector;
77 bufferStorageVector.emplace_back(
BufferStorage{tensorMemoryPointerVector, numTensors});
78 bufferStorageVector.emplace_back(
BufferStorage{tensorMemoryPointerVector, numTensors});
81 std::shared_ptr<SampleCustomAllocator> customAllocator =
82 std::make_unique<SampleCustomAllocator>(SampleCustomAllocator());
84 customAllocator->m_Values = {10, 11, 12, 13, 14};
86 CHECK(customAllocator->m_Values.size() == numTensors);
88 size_t bufferVecSize = bufferStorageVector.size();
94 CHECK(customAllocator->m_CounterAllocate == bufferVecSize);
97 for (
auto tensorMemory : tensorMemoryVector)
99 auto value =
reinterpret_cast<uint8_t *
>(tensorMemory->m_Data);
100 CHECK(customAllocator->m_Values[idx] == *value);
105 CHECK(customAllocator->m_CounterFree == bufferStorageVector.size());
TEST_SUITE("TestConstTensorLayerVisitor")
Custom Allocator interface.
void Allocate()
Allocate the amount of memory indicated by , and point each to each correspondent Tensor so that the...
void Deallocate()
Deallocate memory.
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
MemorySource
Define the Memory Source to reduce copies.
void StoreMemToAllocate(std::vector< BufferStorage > bufferStorageVector, std::shared_ptr< ICustomAllocator > customAllocator, size_t typeAlignment=0)
Initialization method to store in all information needed.