ArmNN
 20.02
RefTensorHandleTests.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
6 
7 #include <boost/test/unit_test.hpp>
8 
9 BOOST_AUTO_TEST_SUITE(RefTensorHandleTests)
10 using namespace armnn;
11 
12 BOOST_AUTO_TEST_CASE(AcquireAndRelease)
13 {
14  std::shared_ptr<RefMemoryManager> memoryManager = std::make_shared<RefMemoryManager>();
15 
16  TensorInfo info({1,1,1,1}, DataType::Float32);
17  RefTensorHandle handle(info, memoryManager);
18 
19  handle.Manage();
20  handle.Allocate();
21 
22  memoryManager->Acquire();
23  {
24  float *buffer = reinterpret_cast<float *>(handle.Map());
25 
26  BOOST_CHECK(buffer != nullptr); // Yields a valid pointer
27 
28  buffer[0] = 2.5f;
29 
30  BOOST_CHECK(buffer[0] == 2.5f); // Memory is writable and readable
31 
32  }
33  memoryManager->Release();
34 
35  memoryManager->Acquire();
36  {
37  float *buffer = reinterpret_cast<float *>(handle.Map());
38 
39  BOOST_CHECK(buffer != nullptr); // Yields a valid pointer
40 
41  buffer[0] = 3.5f;
42 
43  BOOST_CHECK(buffer[0] == 3.5f); // Memory is writable and readable
44  }
45  memoryManager->Release();
46 }
47 
48 #if !defined(__ANDROID__)
49 // Only run these tests on non Android platforms
50 BOOST_AUTO_TEST_CASE(CheckSourceType)
51 {
52  std::shared_ptr<RefMemoryManager> memoryManager = std::make_shared<RefMemoryManager>();
53 
55  RefTensorHandle handle(info, memoryManager, static_cast<unsigned int>(MemorySource::Malloc));
56 
57  int* testPtr = new int(4);
58 
59  // Not supported
60  BOOST_CHECK(!handle.Import(static_cast<void *>(testPtr), MemorySource::DmaBuf));
61 
62  // Not supported
63  BOOST_CHECK(!handle.Import(static_cast<void *>(testPtr), MemorySource::DmaBufProtected));
64 
65  // Supported
66  BOOST_CHECK(handle.Import(static_cast<void *>(testPtr), MemorySource::Malloc));
67 
68  delete testPtr;
69 }
70 
71 BOOST_AUTO_TEST_CASE(ReusePointer)
72 {
73  std::shared_ptr<RefMemoryManager> memoryManager = std::make_shared<RefMemoryManager>();
74 
76  RefTensorHandle handle(info, memoryManager, static_cast<unsigned int>(MemorySource::Malloc));
77 
78  int* testPtr = new int(4);
79 
80  handle.Import(static_cast<void *>(testPtr), MemorySource::Malloc);
81 
82  // Reusing previously Imported pointer
83  BOOST_CHECK(handle.Import(static_cast<void *>(testPtr), MemorySource::Malloc));
84 
85  delete testPtr;
86 }
87 
88 BOOST_AUTO_TEST_CASE(MisalignedPointer)
89 {
90  std::shared_ptr<RefMemoryManager> memoryManager = std::make_shared<RefMemoryManager>();
91 
93  RefTensorHandle handle(info, memoryManager, static_cast<unsigned int>(MemorySource::Malloc));
94 
95  // Allocate a 2 int array
96  int* testPtr = new int[2];
97 
98  // Increment pointer by 1 byte
99  void* misalignedPtr = static_cast<void*>(reinterpret_cast<char*>(testPtr) + 1);
100 
101  BOOST_CHECK(!handle.Import(misalignedPtr, MemorySource::Malloc));
102 
103  delete[] testPtr;
104 }
105 
106 #endif
107 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
Copyright (c) 2020 ARM Limited.
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
BOOST_AUTO_TEST_SUITE_END()