aboutsummaryrefslogtreecommitdiff
path: root/src/backends/tosaCommon/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/tosaCommon/test')
-rw-r--r--src/backends/tosaCommon/test/AvgPool2DIgnoreValueChecker.hpp18
-rw-r--r--src/backends/tosaCommon/test/OneToOneMappingTests.cpp146
-rw-r--r--src/backends/tosaCommon/test/TosaTestUtils.hpp52
3 files changed, 159 insertions, 57 deletions
diff --git a/src/backends/tosaCommon/test/AvgPool2DIgnoreValueChecker.hpp b/src/backends/tosaCommon/test/AvgPool2DIgnoreValueChecker.hpp
index a38f66b466..6f57c4a61e 100644
--- a/src/backends/tosaCommon/test/AvgPool2DIgnoreValueChecker.hpp
+++ b/src/backends/tosaCommon/test/AvgPool2DIgnoreValueChecker.hpp
@@ -68,9 +68,11 @@ void VerifyAvgPool2DIgnoreValue(TosaSerializationBasicBlock* basicBlock,
CHECK(padOp->GetAttributeType() == Attribute_PadAttribute);
CHECK(padOp->GetOp() == Op_PAD);
- VerifyTosaAttributeFromDescriptor(descriptor,
- padOp->GetAttribute(),
- LayerType::Pooling2d);
+ VerifyTosaAttribute(descriptor,
+ padOp->GetAttribute(),
+ inputShape[0],
+ outputShape[0],
+ LayerType::Pooling2d);
//
// Verify average pool operator second.
@@ -115,9 +117,11 @@ void VerifyAvgPool2DIgnoreValue(TosaSerializationBasicBlock* basicBlock,
CHECK(poolOp->GetAttributeType() == Attribute_PoolAttribute);
CHECK(poolOp->GetOp() == Op_AVG_POOL2D);
- VerifyTosaAttributeFromDescriptor(descriptor,
- poolOp->GetAttribute(),
- LayerType::Pooling2d,
- 1);
+ VerifyTosaAttribute(descriptor,
+ poolOp->GetAttribute(),
+ inputShape[0],
+ outputShape[0],
+ LayerType::Pooling2d,
+ 1);
} \ No newline at end of file
diff --git a/src/backends/tosaCommon/test/OneToOneMappingTests.cpp b/src/backends/tosaCommon/test/OneToOneMappingTests.cpp
index af9f9e26df..b1fa6847bc 100644
--- a/src/backends/tosaCommon/test/OneToOneMappingTests.cpp
+++ b/src/backends/tosaCommon/test/OneToOneMappingTests.cpp
@@ -79,7 +79,7 @@ TEST_CASE("GetTosaMappingFromLayer_ConstantLayer")
std::vector<std::vector<int32_t>> outputShape = {{ 1, 2, 4, 2 }};
std::vector<float> data = GenerateRandomData<float>(info.GetNumElements());
- armnn::ConstTensor constTensor(info, data);
+ ConstTensor constTensor(info, data);
IConnectableLayer* constant = net->AddConstantLayer(constTensor, "constant");
IConnectableLayer* output = net->AddOutputLayer(0, "output");
@@ -95,7 +95,7 @@ TEST_CASE("GetTosaMappingFromLayer_ConstantLayer")
TEST_CASE("GetTosaMapping_Conv2dLayer")
{
- armnn::Convolution2dDescriptor descriptor;
+ Convolution2dDescriptor descriptor;
descriptor.m_PadLeft = 1;
descriptor.m_PadRight = 1;
descriptor.m_PadTop = 1;
@@ -106,10 +106,10 @@ TEST_CASE("GetTosaMapping_Conv2dLayer")
descriptor.m_DilationY = 2;
descriptor.m_BiasEnabled = true;
- const armnn::TensorInfo inputInfo ({ 1, 5, 5, 1 }, armnn::DataType::Float32);
- const armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32);
- const armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32, 0.0f, 0, true);
- const armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true);
+ const TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
+ const TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32);
+ const TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
+ const TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
std::vector<std::vector<int32_t>> inputShape = {{ 1, 5, 5, 1 }, { 1, 3, 3, 1 }, { 1 }};
std::vector<std::vector<int32_t>> outputShape = {{ 1, 3, 3, 1 }};
@@ -131,7 +131,7 @@ TEST_CASE("GetTosaMappingFromLayer_Conv2dLayer")
// Builds up the structure of the network.
INetworkPtr net(INetwork::Create());
- armnn::Convolution2dDescriptor descriptor;
+ Convolution2dDescriptor descriptor;
descriptor.m_PadLeft = 1;
descriptor.m_PadRight = 1;
descriptor.m_PadTop = 1;
@@ -142,25 +142,25 @@ TEST_CASE("GetTosaMappingFromLayer_Conv2dLayer")
descriptor.m_DilationY = 2;
descriptor.m_BiasEnabled = true;
- const armnn::TensorInfo inputInfo ({ 1, 5, 5, 1 }, armnn::DataType::Float32);
- const armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32);
- const armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32, 0.0f, 0, true);
- const armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true);
+ const TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
+ const TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32);
+ const TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
+ const TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
std::vector<std::vector<int32_t>> inputShape = {{ 1, 5, 5, 1 }};
std::vector<std::vector<int32_t>> outputShape = {{ 1, 3, 3, 1 }};
std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements());
- armnn::ConstTensor weights(weightsInfo, weightsData);
+ ConstTensor weights(weightsInfo, weightsData);
std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements());
- armnn::ConstTensor biases(biasesInfo, biasesData);
+ ConstTensor biases(biasesInfo, biasesData);
- armnn::IConnectableLayer* const inputLayer = net->AddInputLayer(0, "input0");
- armnn::IConnectableLayer* const weightsLayer = net->AddConstantLayer(weights, "weights");
- armnn::IConnectableLayer* const biasesLayer = net->AddConstantLayer(biases, "biases");
- armnn::IConnectableLayer* const convLayer = net->AddConvolution2dLayer(descriptor, "conv2d");
- armnn::IConnectableLayer* const outputLayer = net->AddOutputLayer(0);
+ IConnectableLayer* const inputLayer = net->AddInputLayer(0, "input0");
+ IConnectableLayer* const weightsLayer = net->AddConstantLayer(weights, "weights");
+ IConnectableLayer* const biasesLayer = net->AddConstantLayer(biases, "biases");
+ IConnectableLayer* const convLayer = net->AddConvolution2dLayer(descriptor, "conv2d");
+ IConnectableLayer* const outputLayer = net->AddOutputLayer(0);
inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0));
weightsLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(1));
@@ -179,18 +179,18 @@ TEST_CASE("GetTosaMappingFromLayer_Conv2dLayer")
TEST_CASE("GetTosaMapping_MaxPool2DLayer")
{
- armnn::Pooling2dDescriptor descriptor;
- descriptor.m_PoolType = armnn::PoolingAlgorithm::Max;
+ Pooling2dDescriptor descriptor;
+ descriptor.m_PoolType = PoolingAlgorithm::Max;
descriptor.m_PoolWidth = descriptor.m_PoolHeight = 2;
descriptor.m_StrideX = descriptor.m_StrideY = 2;
descriptor.m_PadLeft = 1;
descriptor.m_PadRight = 1;
descriptor.m_PadTop = 1;
descriptor.m_PadBottom = 1;
- descriptor.m_PaddingMethod = armnn::PaddingMethod::Exclude;
+ descriptor.m_PaddingMethod = PaddingMethod::Exclude;
- armnn::TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
- armnn::TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
+ TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
+ TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
std::vector<std::vector<int32_t>> inputShape = {{ 1, 1, 4, 4 }};
std::vector<std::vector<int32_t>> outputShape = {{ 1, 1, 3, 3 }};
@@ -209,30 +209,30 @@ TEST_CASE("GetTosaMappingFromLayer_MaxPool2DLayer")
// Builds up the structure of the network.
INetworkPtr net(INetwork::Create());
- armnn::Pooling2dDescriptor descriptor;
- descriptor.m_PoolType = armnn::PoolingAlgorithm::Max;
+ Pooling2dDescriptor descriptor;
+ descriptor.m_PoolType = PoolingAlgorithm::Max;
descriptor.m_PoolWidth = descriptor.m_PoolHeight = 2;
descriptor.m_StrideX = descriptor.m_StrideY = 2;
descriptor.m_PadLeft = 1;
descriptor.m_PadRight = 1;
descriptor.m_PadTop = 1;
descriptor.m_PadBottom = 1;
- descriptor.m_PaddingMethod = armnn::PaddingMethod::Exclude;
+ descriptor.m_PaddingMethod = PaddingMethod::Exclude;
- IConnectableLayer* input0 = net->AddInputLayer(0, "input0");
- IConnectableLayer* pool = net->AddPooling2dLayer(descriptor, "pool");
- IConnectableLayer* output = net->AddOutputLayer(0, "output");
+ IConnectableLayer* input = net->AddInputLayer(0, "input0");
+ IConnectableLayer* pool = net->AddPooling2dLayer(descriptor, "pool");
+ IConnectableLayer* output = net->AddOutputLayer(0, "output");
- input0->GetOutputSlot(0).Connect(pool->GetInputSlot(0));
+ input->GetOutputSlot(0).Connect(pool->GetInputSlot(0));
pool->GetOutputSlot(0).Connect(output->GetInputSlot(0));
- armnn::TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
- armnn::TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
+ TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
+ TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
std::vector<std::vector<int32_t>> inputShape = {{ 1, 1, 4, 4 }};
std::vector<std::vector<int32_t>> outputShape = {{ 1, 1, 3, 3 }};
- input0->GetOutputSlot(0).SetTensorInfo(inputTensorInfo);
+ input->GetOutputSlot(0).SetTensorInfo(inputTensorInfo);
pool->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
TosaSerializationBasicBlock* basicBlock =
@@ -243,18 +243,18 @@ TEST_CASE("GetTosaMappingFromLayer_MaxPool2DLayer")
TEST_CASE("GetTosaMapping_AvgPool2DLayer")
{
- armnn::Pooling2dDescriptor descriptor;
- descriptor.m_PoolType = armnn::PoolingAlgorithm::Average;
+ Pooling2dDescriptor descriptor;
+ descriptor.m_PoolType = PoolingAlgorithm::Average;
descriptor.m_PoolWidth = descriptor.m_PoolHeight = 2;
descriptor.m_StrideX = descriptor.m_StrideY = 2;
descriptor.m_PadLeft = 1;
descriptor.m_PadRight = 1;
descriptor.m_PadTop = 1;
descriptor.m_PadBottom = 1;
- descriptor.m_PaddingMethod = armnn::PaddingMethod::Exclude;
+ descriptor.m_PaddingMethod = PaddingMethod::Exclude;
- armnn::TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
- armnn::TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
+ TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
+ TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
std::vector<std::vector<int32_t>> inputShape = {{ 1, 1, 4, 4 }};
std::vector<std::vector<int32_t>> outputShape = {{ 1, 1, 3, 3 }};
@@ -278,15 +278,15 @@ TEST_CASE("GetTosaMappingFromLayer_AvgPool2DLayer")
// Builds up the structure of the network.
INetworkPtr net(INetwork::Create());
- armnn::Pooling2dDescriptor descriptor;
- descriptor.m_PoolType = armnn::PoolingAlgorithm::Average;
+ Pooling2dDescriptor descriptor;
+ descriptor.m_PoolType = PoolingAlgorithm::Average;
descriptor.m_PoolWidth = descriptor.m_PoolHeight = 2;
descriptor.m_StrideX = descriptor.m_StrideY = 2;
descriptor.m_PadLeft = 1;
descriptor.m_PadRight = 1;
descriptor.m_PadTop = 1;
descriptor.m_PadBottom = 1;
- descriptor.m_PaddingMethod = armnn::PaddingMethod::Exclude;
+ descriptor.m_PaddingMethod = PaddingMethod::Exclude;
IConnectableLayer* input0 = net->AddInputLayer(0, "input0");
IConnectableLayer* pool = net->AddPooling2dLayer(descriptor, "pool");
@@ -295,8 +295,8 @@ TEST_CASE("GetTosaMappingFromLayer_AvgPool2DLayer")
input0->GetOutputSlot(0).Connect(pool->GetInputSlot(0));
pool->GetOutputSlot(0).Connect(output->GetInputSlot(0));
- armnn::TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
- armnn::TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
+ TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32);
+ TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32);
std::vector<std::vector<int32_t>> inputShape = {{ 1, 1, 4, 4 }};
std::vector<std::vector<int32_t>> outputShape = {{ 1, 1, 3, 3 }};
@@ -315,6 +315,66 @@ TEST_CASE("GetTosaMappingFromLayer_AvgPool2DLayer")
LayerType::Pooling2d);
}
+TEST_CASE("GetTosaMapping_ReshapeLayer")
+{
+ TensorInfo inputInfo = TensorInfo({ 2, 3 }, DataType::Float32);
+ TensorInfo outputInfo = TensorInfo({ 6 }, DataType::Float32);
+
+ std::vector<std::vector<int32_t>> inputShape = {{ 2, 3 }};
+ std::vector<std::vector<int32_t>> outputShape = {{ 6 }};
+
+ ReshapeDescriptor descriptor;
+ descriptor.m_TargetShape = { 6 };
+
+ TosaSerializationBasicBlock* basicBlock =
+ GetTosaMapping(nullptr, LayerType::Reshape, {&inputInfo}, {&outputInfo}, descriptor);
+ AssertTosaOneToOneMappingBasicBlock(basicBlock,
+ inputShape,
+ outputShape,
+ Op_RESHAPE,
+ Attribute_ReshapeAttribute,
+ descriptor,
+ LayerType::Reshape);
+}
+
+TEST_CASE("GetTosaMappingFromLayer_ReshapeLayer")
+{
+ IRuntime::CreationOptions options;
+ IRuntimePtr runtime(IRuntime::Create(options));
+
+ // Builds up the structure of the network.
+ INetworkPtr net(INetwork::Create());
+
+ ReshapeDescriptor descriptor;
+ descriptor.m_TargetShape = { 6 };
+
+ IConnectableLayer* input = net->AddInputLayer(0, "input");
+ IConnectableLayer* reshape = net->AddReshapeLayer(descriptor, "reshape");
+ IConnectableLayer* output = net->AddOutputLayer(0, "output");
+
+ input->GetOutputSlot(0).Connect(reshape->GetInputSlot(0));
+ reshape->GetOutputSlot(0).Connect(output->GetInputSlot(0));
+
+ TensorInfo inputInfo = TensorInfo({ 2, 3 }, DataType::Float32);
+ TensorInfo outputInfo = TensorInfo({ 6 }, DataType::Float32);
+
+ input->GetOutputSlot(0).SetTensorInfo(inputInfo);
+ reshape->GetOutputSlot(0).SetTensorInfo(outputInfo);
+
+ std::vector<std::vector<int32_t>> inputShape = {{ 2, 3 }};
+ std::vector<std::vector<int32_t>> outputShape = {{ 6 }};
+
+ TosaSerializationBasicBlock* basicBlock =
+ GetTosaMappingFromLayer(PolymorphicDowncast<Layer*>(reshape));
+ AssertTosaOneToOneMappingBasicBlock(basicBlock,
+ inputShape,
+ outputShape,
+ Op_RESHAPE,
+ Attribute_ReshapeAttribute,
+ descriptor,
+ LayerType::Reshape);
+}
+
TEST_CASE("GetTosaMapping_Unimplemented")
{
TosaSerializationBasicBlock* basicBlock =
diff --git a/src/backends/tosaCommon/test/TosaTestUtils.hpp b/src/backends/tosaCommon/test/TosaTestUtils.hpp
index dd63c0efdf..5c10a6d638 100644
--- a/src/backends/tosaCommon/test/TosaTestUtils.hpp
+++ b/src/backends/tosaCommon/test/TosaTestUtils.hpp
@@ -8,16 +8,20 @@
#include <Layer.hpp>
#include <tosaCommon/TosaMappings.hpp>
+#include <tosaCommon/operatorMappings/TosaOperatorUtils.hpp>
#include <doctest/doctest.h>
+#include <numeric>
using namespace armnn;
using namespace tosa;
-inline void VerifyTosaAttributeFromDescriptor(const BaseDescriptor& descriptor,
- const TosaAttributeBase* attribute,
- LayerType type,
- uint32_t mappingOpNumber = 0)
+inline void VerifyTosaAttribute(const BaseDescriptor& descriptor,
+ const TosaAttributeBase* attribute,
+ std::vector<int32_t> inputShape,
+ std::vector<int32_t> outputShape,
+ LayerType type,
+ uint32_t mappingOpNumber = 0)
{
switch (type)
{
@@ -100,6 +104,25 @@ inline void VerifyTosaAttributeFromDescriptor(const BaseDescriptor& descriptor,
CHECK(stride == poolAttribute.stride());
break;
}
+ case LayerType::Reshape:
+ {
+ auto reshapeDesc = PolymorphicDowncast<const ReshapeDescriptor*>(&descriptor);
+ TosaReshapeAttribute reshapeAttribute(attribute);
+ std::vector<int32_t> shapeAttrib = reshapeAttribute.new_shape();
+
+ CHECK(GetTosaTensorShape(reshapeDesc->m_TargetShape) == shapeAttrib);
+ CHECK(outputShape == shapeAttrib);
+
+ auto numInputElements = std::accumulate(std::begin(inputShape),
+ std::end(inputShape),
+ 1,
+ std::multiplies<int32_t>());
+ auto numAttributeShapeElements = std::accumulate(std::begin(shapeAttrib),
+ std::end(shapeAttrib),
+ 1,
+ std::multiplies<int32_t>());
+ CHECK(numInputElements == numAttributeShapeElements);
+ }
default:
break;
}
@@ -195,7 +218,22 @@ inline void AssertTosaOneToOneMappingBasicBlock(TosaSerializationBasicBlock* bas
}
}
- VerifyTosaAttributeFromDescriptor(descriptor,
- op->GetAttribute(),
- type);
+ std::vector<int32_t> input = {};
+ std::vector<int32_t> output = {};
+
+ if (!inputShape.empty())
+ {
+ input = inputShape[0];
+ }
+
+ if (!outputShape.empty())
+ {
+ output = outputShape[0];
+ }
+
+ VerifyTosaAttribute(descriptor,
+ op->GetAttribute(),
+ input,
+ output,
+ type);
} \ No newline at end of file