ArmNN
 21.05
ClImportTensorHandleFactoryTests.cpp File Reference
#include <cl/ClImportTensorHandleFactory.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (ImportTensorFactoryAskedToCreateManagedTensorThrowsException)
 
 BOOST_AUTO_TEST_CASE (ImportTensorFactoryCreateMallocTensorHandle)
 
 BOOST_AUTO_TEST_CASE (CreateSubtensorOfImportTensor)
 
 BOOST_AUTO_TEST_CASE (CreateSubtensorNonZeroXYIsInvalid)
 
 BOOST_AUTO_TEST_CASE (CreateSubtensorXYMustMatchParent)
 
 BOOST_AUTO_TEST_CASE (CreateSubtensorMustBeSmallerThanParent)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

BOOST_AUTO_TEST_CASE ( ImportTensorFactoryAskedToCreateManagedTensorThrowsException  )

Definition at line 13 of file ClImportTensorHandleFactoryTests.cpp.

References ClImportTensorHandleFactory::CreateTensorHandle(), armnn::Malloc, and armnn::NCHW.

14 {
15  // Create the factory to import tensors.
16  ClImportTensorHandleFactory factory(static_cast<MemorySourceFlags>(MemorySource::Malloc),
17  static_cast<MemorySourceFlags>(MemorySource::Malloc));
18  TensorInfo tensorInfo;
19  // This factory is designed to import the memory of tensors. Asking for a handle that requires
20  // a memory manager should result in an exception.
21  BOOST_REQUIRE_THROW(factory.CreateTensorHandle(tensorInfo, true), InvalidArgumentException);
22  BOOST_REQUIRE_THROW(factory.CreateTensorHandle(tensorInfo, DataLayout::NCHW, true), InvalidArgumentException);
23 }
This factory creates ClImportTensorHandles that refer to imported memory tensors. ...

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( ImportTensorFactoryCreateMallocTensorHandle  )

Definition at line 25 of file ClImportTensorHandleFactoryTests.cpp.

References ClImportTensorHandleFactory::CreateTensorHandle(), armnn::Float32, armnn::Malloc, and armnn::NHWC.

26 {
27  // Create the factory to import tensors.
28  ClImportTensorHandleFactory factory(static_cast<MemorySourceFlags>(MemorySource::Malloc),
29  static_cast<MemorySourceFlags>(MemorySource::Malloc));
30  TensorShape tensorShape{ 6, 7, 8, 9 };
31  TensorInfo tensorInfo(tensorShape, armnn::DataType::Float32);
32  // Start with the TensorInfo factory method. Create an import tensor handle and verify the data is
33  // passed through correctly.
34  auto tensorHandle = factory.CreateTensorHandle(tensorInfo);
35  BOOST_ASSERT(tensorHandle);
36  BOOST_ASSERT(tensorHandle->GetImportFlags() == static_cast<MemorySourceFlags>(MemorySource::Malloc));
37  BOOST_ASSERT(tensorHandle->GetShape() == tensorShape);
38 
39  // Same method but explicitly specifying isManaged = false.
40  tensorHandle = factory.CreateTensorHandle(tensorInfo, false);
41  BOOST_CHECK(tensorHandle);
42  BOOST_ASSERT(tensorHandle->GetImportFlags() == static_cast<MemorySourceFlags>(MemorySource::Malloc));
43  BOOST_ASSERT(tensorHandle->GetShape() == tensorShape);
44 
45  // Now try TensorInfo and DataLayout factory method.
46  tensorHandle = factory.CreateTensorHandle(tensorInfo, DataLayout::NHWC);
47  BOOST_CHECK(tensorHandle);
48  BOOST_ASSERT(tensorHandle->GetImportFlags() == static_cast<MemorySourceFlags>(MemorySource::Malloc));
49  BOOST_ASSERT(tensorHandle->GetShape() == tensorShape);
50 }
unsigned int MemorySourceFlags
This factory creates ClImportTensorHandles that refer to imported memory tensors. ...

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( CreateSubtensorOfImportTensor  )

Definition at line 52 of file ClImportTensorHandleFactoryTests.cpp.

References ClImportTensorHandleFactory::CreateSubTensorHandle(), ClImportTensorHandleFactory::CreateTensorHandle(), armnn::Float32, and armnn::Malloc.

53 {
54  // Create the factory to import tensors.
55  ClImportTensorHandleFactory factory(static_cast<MemorySourceFlags>(MemorySource::Malloc),
56  static_cast<MemorySourceFlags>(MemorySource::Malloc));
57  // Create a standard inport tensor.
58  TensorShape tensorShape{ 224, 224, 1, 1 };
59  TensorInfo tensorInfo(tensorShape, armnn::DataType::Float32);
60  auto tensorHandle = factory.CreateTensorHandle(tensorInfo);
61  // Use the factory to create a 16x16 sub tensor.
62  TensorShape subTensorShape{ 16, 16, 1, 1 };
63  // Starting at an offset of 1x1.
64  uint32_t origin[4] = { 1, 1, 0, 0 };
65  auto subTensor = factory.CreateSubTensorHandle(*tensorHandle, subTensorShape, origin);
66  BOOST_CHECK(subTensor);
67  BOOST_ASSERT(subTensor->GetShape() == subTensorShape);
68  BOOST_ASSERT(subTensor->GetParent() == tensorHandle.get());
69 }
This factory creates ClImportTensorHandles that refer to imported memory tensors. ...

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( CreateSubtensorNonZeroXYIsInvalid  )

Definition at line 71 of file ClImportTensorHandleFactoryTests.cpp.

References ClImportTensorHandleFactory::CreateSubTensorHandle(), ClImportTensorHandleFactory::CreateTensorHandle(), armnn::Float32, and armnn::Malloc.

72 {
73  // Create the factory to import tensors.
74  ClImportTensorHandleFactory factory(static_cast<MemorySourceFlags>(MemorySource::Malloc),
75  static_cast<MemorySourceFlags>(MemorySource::Malloc));
76  // Create a standard import tensor.
77  TensorShape tensorShape{ 224, 224, 1, 1 };
78  TensorInfo tensorInfo(tensorShape, armnn::DataType::Float32);
79  auto tensorHandle = factory.CreateTensorHandle(tensorInfo);
80  // Use the factory to create a 16x16 sub tensor.
81  TensorShape subTensorShape{ 16, 16, 1, 1 };
82  // This looks a bit backwards because of how Cl specifies tensors. Essentially we want to trigger our
83  // check "(coords.x() != 0 || coords.y() != 0)"
84  uint32_t origin[4] = { 0, 0, 1, 1 };
85  auto subTensor = factory.CreateSubTensorHandle(*tensorHandle, subTensorShape, origin);
86  // We expect a nullptr.
87  BOOST_ASSERT(subTensor == nullptr);
88 }
This factory creates ClImportTensorHandles that refer to imported memory tensors. ...

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( CreateSubtensorXYMustMatchParent  )

Definition at line 90 of file ClImportTensorHandleFactoryTests.cpp.

References ClImportTensorHandleFactory::CreateSubTensorHandle(), ClImportTensorHandleFactory::CreateTensorHandle(), armnn::Float32, and armnn::Malloc.

91 {
92  // Create the factory to import tensors.
93  ClImportTensorHandleFactory factory(static_cast<MemorySourceFlags>(MemorySource::Malloc),
94  static_cast<MemorySourceFlags>(MemorySource::Malloc));
95  // Create a standard import tensor.
96  TensorShape tensorShape{ 224, 224, 1, 1 };
97  TensorInfo tensorInfo(tensorShape, armnn::DataType::Float32);
98  auto tensorHandle = factory.CreateTensorHandle(tensorInfo);
99  // Use the factory to create a 16x16 sub tensor but make the CL x and y axis different.
100  TensorShape subTensorShape{ 16, 16, 2, 2 };
101  // We want to trigger our ((parentShape.x() != shape.x()) || (parentShape.y() != shape.y()))
102  uint32_t origin[4] = { 1, 1, 0, 0 };
103  auto subTensor = factory.CreateSubTensorHandle(*tensorHandle, subTensorShape, origin);
104  // We expect a nullptr.
105  BOOST_ASSERT(subTensor == nullptr);
106 }
This factory creates ClImportTensorHandles that refer to imported memory tensors. ...

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( CreateSubtensorMustBeSmallerThanParent  )

Definition at line 108 of file ClImportTensorHandleFactoryTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), ClImportTensorHandleFactory::CreateSubTensorHandle(), ClImportTensorHandleFactory::CreateTensorHandle(), armnn::Float32, and armnn::Malloc.

109 {
110  // Create the factory to import tensors.
111  ClImportTensorHandleFactory factory(static_cast<MemorySourceFlags>(MemorySource::Malloc),
112  static_cast<MemorySourceFlags>(MemorySource::Malloc));
113  // Create a standard import tensor.
114  TensorShape tensorShape{ 224, 224, 1, 1 };
115  TensorInfo tensorInfo(tensorShape, armnn::DataType::Float32);
116  auto tensorHandle = factory.CreateTensorHandle(tensorInfo);
117  // Ask for a subtensor that's the same size as the parent.
118  TensorShape subTensorShape{ 224, 224, 1, 1 };
119  uint32_t origin[4] = { 1, 1, 0, 0 };
120  // This should result in a nullptr.
121  auto subTensor = factory.CreateSubTensorHandle(*tensorHandle, subTensorShape, origin);
122  BOOST_ASSERT(subTensor == nullptr);
123 }
This factory creates ClImportTensorHandles that refer to imported memory tensors. ...