diff options
author | Cathal Corbett <cathal.corbett@arm.com> | 2022-12-09 12:17:27 +0000 |
---|---|---|
committer | TeresaARM <teresa.charlinreyes@arm.com> | 2022-12-13 12:13:20 +0000 |
commit | 3b9acd515918ac1af5498b3e7501c0b16a88a8e0 (patch) | |
tree | a537cbdd7c45fea1772cbb34f8a23ecc7dbd6e1a /src/backends/tosaCommon/test | |
parent | 8107ccce5167f160b9c98a6042878dd0408220b5 (diff) | |
download | armnn-3b9acd515918ac1af5498b3e7501c0b16a88a8e0.tar.gz |
IVGCVSW-7342 Add Slice support to TOSA Reference Backend
Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Change-Id: I8be286b69bebd4cd36033e3145632bb043938d16
Diffstat (limited to 'src/backends/tosaCommon/test')
-rw-r--r-- | src/backends/tosaCommon/test/OneToOneMappingTests.cpp | 63 | ||||
-rw-r--r-- | src/backends/tosaCommon/test/TosaTestUtils.hpp | 21 |
2 files changed, 84 insertions, 0 deletions
diff --git a/src/backends/tosaCommon/test/OneToOneMappingTests.cpp b/src/backends/tosaCommon/test/OneToOneMappingTests.cpp index b1fa6847bc..07ffae41d1 100644 --- a/src/backends/tosaCommon/test/OneToOneMappingTests.cpp +++ b/src/backends/tosaCommon/test/OneToOneMappingTests.cpp @@ -375,6 +375,69 @@ TEST_CASE("GetTosaMappingFromLayer_ReshapeLayer") LayerType::Reshape); } +TEST_CASE("GetTosaMapping_SliceLayer") +{ + TensorInfo inputInfo = TensorInfo({ 3, 2, 3 }, DataType::Float32); + TensorInfo outputInfo = TensorInfo({ 2, 1, 3 }, DataType::Float32); + + std::vector<std::vector<int32_t>> inputShape = {{ 3, 2, 3 }}; + std::vector<std::vector<int32_t>> outputShape = {{ 2, 1, 3 }}; + + SliceDescriptor descriptor; + descriptor.m_Begin = { 3 }; + descriptor.m_Size = { 3 }; + + TosaSerializationBasicBlock* basicBlock = + GetTosaMapping(nullptr, LayerType::Slice, {&inputInfo}, {&outputInfo}, descriptor); + AssertTosaOneToOneMappingBasicBlock(basicBlock, + inputShape, + outputShape, + Op_SLICE, + Attribute_SliceAttribute, + descriptor, + LayerType::Slice); +} + +TEST_CASE("GetTosaMappingFromLayer_SliceLayer") +{ + IRuntime::CreationOptions options; + IRuntimePtr runtime(IRuntime::Create(options)); + + // Builds up the structure of the network. + INetworkPtr net(INetwork::Create()); + + TensorInfo inputInfo = TensorInfo({ 3, 2, 3 }, DataType::Float32); + TensorInfo outputInfo = TensorInfo({ 2, 1, 3 }, DataType::Float32); + + std::vector<std::vector<int32_t>> inputShape = {{ 3, 2, 3 }}; + std::vector<std::vector<int32_t>> outputShape = {{ 2, 1, 3 }}; + + SliceDescriptor descriptor; + descriptor.m_Begin = { 1, 0, 0 }; + descriptor.m_Size = { 2, 1, 3 }; + + IConnectableLayer* input = net->AddInputLayer(0, "input"); + IConnectableLayer* slice = net->AddSliceLayer(descriptor, "slice"); + IConnectableLayer* output = net->AddOutputLayer(0, "output"); + + input->GetOutputSlot(0).Connect(slice->GetInputSlot(0)); + slice->GetOutputSlot(0).Connect(output->GetInputSlot(0)); + + input->GetOutputSlot(0).SetTensorInfo(inputInfo); + slice->GetOutputSlot(0).SetTensorInfo(outputInfo); + + TosaSerializationBasicBlock* basicBlock = + GetTosaMappingFromLayer(PolymorphicDowncast<Layer*>(slice)); + AssertTosaOneToOneMappingBasicBlock(basicBlock, + inputShape, + outputShape, + Op_SLICE, + Attribute_SliceAttribute, + descriptor, + LayerType::Slice); +} + + TEST_CASE("GetTosaMapping_Unimplemented") { TosaSerializationBasicBlock* basicBlock = diff --git a/src/backends/tosaCommon/test/TosaTestUtils.hpp b/src/backends/tosaCommon/test/TosaTestUtils.hpp index 5c10a6d638..93b9e7d36f 100644 --- a/src/backends/tosaCommon/test/TosaTestUtils.hpp +++ b/src/backends/tosaCommon/test/TosaTestUtils.hpp @@ -122,6 +122,27 @@ inline void VerifyTosaAttribute(const BaseDescriptor& descriptor, 1, std::multiplies<int32_t>()); CHECK(numInputElements == numAttributeShapeElements); + + break; + } + case LayerType::Slice: + { + auto sliceDesc = PolymorphicDowncast<const SliceDescriptor*>(&descriptor); + TosaSliceAttribute reshapeAttribute(attribute); + + std::vector<int32_t> begin(sliceDesc->m_Begin.begin(), sliceDesc->m_Begin.end()); + std::vector<int32_t> size(sliceDesc->m_Size.begin(), sliceDesc->m_Size.end()); + + CHECK(begin == reshapeAttribute.start()); + CHECK(size == reshapeAttribute.size()); + + CHECK(begin.size() == inputShape.size()); + CHECK(size.size() == inputShape.size()); + + CHECK(begin.size() == outputShape.size()); + CHECK(size.size() == outputShape.size()); + + break; } default: break; |