aboutsummaryrefslogtreecommitdiff
path: root/src/backends/reference/test/RefTensorHandleTests.cpp
diff options
context:
space:
mode:
authorMatthew Bentham <matthew.bentham@arm.com>2022-11-23 18:17:48 +0000
committerTeresaARM <teresa.charlinreyes@arm.com>2022-12-15 12:24:27 +0000
commit6b5f674aad30a3438c295c25b5d115007e80b757 (patch)
tree3932603e408330c9f5d09b19a4b224e47e996dec /src/backends/reference/test/RefTensorHandleTests.cpp
parentda6bf9e2eac374cd92147d3c60a8af8bd6bc5a37 (diff)
downloadarmnn-6b5f674aad30a3438c295c25b5d115007e80b757.tar.gz
Change the semantics of RefTensorHandle::Import to 'overlay' existing memory
This makes it possible to call Import on an Allocated() or memory-managed Tensor, which is needed for the current implementation of OptimizerOptions::m_ExportEnabled to work (as the last layer before the OutputLayer needs to be able to Import the user's OutputTensor, but this is done after other memory allocation). Signed-off-by: Matthew Bentham <matthew.bentham@arm.com> Change-Id: I1a885c2da7b1f0f3964ae53b8135b5e96a66614f
Diffstat (limited to 'src/backends/reference/test/RefTensorHandleTests.cpp')
-rw-r--r--src/backends/reference/test/RefTensorHandleTests.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/backends/reference/test/RefTensorHandleTests.cpp b/src/backends/reference/test/RefTensorHandleTests.cpp
index b5fcc212a9..883df6fe4d 100644
--- a/src/backends/reference/test/RefTensorHandleTests.cpp
+++ b/src/backends/reference/test/RefTensorHandleTests.cpp
@@ -99,8 +99,14 @@ TEST_CASE("RefTensorHandleFactoryMemoryManaged")
memoryManager->Release();
float testPtr[2] = { 2.5f, 5.5f };
- // Cannot import as import is disabled
- CHECK(!handle->Import(static_cast<void*>(testPtr), MemorySource::Malloc));
+ // Check import overlays contents
+ CHECK(handle->Import(static_cast<void*>(testPtr), MemorySource::Malloc));
+ {
+ float* buffer = reinterpret_cast<float*>(handle->Map());
+ CHECK(buffer != nullptr); // Yields a valid pointer
+ CHECK(buffer[0] == 2.5f); // Memory is writable and readable
+ CHECK(buffer[1] == 5.5f); // Memory is writable and readable
+ }
}
TEST_CASE("RefTensorHandleFactoryImport")
@@ -115,11 +121,12 @@ TEST_CASE("RefTensorHandleFactoryImport")
handle->Allocate();
memoryManager->Acquire();
- // No buffer allocated when import is enabled
- CHECK_THROWS_AS(handle->Map(), armnn::NullPointerException);
+ // Check storage has been allocated
+ void* unmanagedStorage = handle->Map();
+ CHECK(unmanagedStorage != nullptr);
+ // Check importing overlays the storage
float testPtr[2] = { 2.5f, 5.5f };
- // Correctly import
CHECK(handle->Import(static_cast<void*>(testPtr), MemorySource::Malloc));
float* buffer = reinterpret_cast<float*>(handle->Map());
CHECK(buffer != nullptr); // Yields a valid pointer after import
@@ -142,11 +149,11 @@ TEST_CASE("RefTensorHandleImport")
handle.Manage();
handle.Allocate();
- // No buffer allocated when import is enabled
- CHECK_THROWS_AS(handle.Map(), armnn::NullPointerException);
+ // Check unmanaged memory allocated
+ CHECK(handle.Map());
float testPtr[2] = { 2.5f, 5.5f };
- // Correctly import
+ // Check imoport overlays the unamaged memory
CHECK(handle.Import(static_cast<void*>(testPtr), MemorySource::Malloc));
float* buffer = reinterpret_cast<float*>(handle.Map());
CHECK(buffer != nullptr); // Yields a valid pointer after import