aboutsummaryrefslogtreecommitdiff
path: root/src/backends/tosaCommon/operatorMappings
diff options
context:
space:
mode:
authorKevin May <kevin.may@arm.com>2022-12-15 10:15:21 +0000
committerTeresa Charlin <teresa.charlinreyes@arm.com>2022-12-15 17:16:12 +0000
commit5b58e31109f661f70331048e22f8a66934e74d15 (patch)
tree7ad8f88bf7427a1dd2622b53fcd0b4b8632ee34e /src/backends/tosaCommon/operatorMappings
parent3fbad94012ee6b1c6ec8e93d760619b15d98c464 (diff)
downloadarmnn-5b58e31109f661f70331048e22f8a66934e74d15.tar.gz
IVGCVSW-7170 Add Concat support to TOSA Reference Backend
* Change comment for the unique tensor names in all tosa common operators Signed-off-by: Kevin May <kevin.may@arm.com> Change-Id: I247b4b2365d5f0173218c5dfd11fba12d2399959
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings')
-rw-r--r--src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp4
-rw-r--r--src/backends/tosaCommon/operatorMappings/AvgPool2DIgnoreValueOperator.cpp4
-rw-r--r--src/backends/tosaCommon/operatorMappings/CMakeLists.txt2
-rw-r--r--src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp81
-rw-r--r--src/backends/tosaCommon/operatorMappings/ConcatOperator.hpp20
-rw-r--r--src/backends/tosaCommon/operatorMappings/Conv2dOperator.cpp10
-rw-r--r--src/backends/tosaCommon/operatorMappings/Pooling2DOperator.cpp4
-rw-r--r--src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp4
-rw-r--r--src/backends/tosaCommon/operatorMappings/SliceOperator.cpp4
-rw-r--r--src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp1
-rw-r--r--src/backends/tosaCommon/operatorMappings/TransposeConv2dOperator.cpp2
11 files changed, 121 insertions, 15 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp b/src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp
index 20ba146574..7014886d92 100644
--- a/src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp
+++ b/src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp
@@ -18,14 +18,14 @@ TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const Layer* layer,
// using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
if(layer != nullptr)
{
- // Get the layers connected to the input slots and determine unique layer names.
+ // Get the layers connected to the input slots and determine unique tensors names.
Layer& connectedLayer0 = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
input0Name = GenerateUniqueName(connectedLayer0, 0);
Layer& connectedLayer1 = layer->GetInputSlot(1).GetConnectedOutputSlot()->GetOwningLayer();
input1Name = GenerateUniqueName(connectedLayer1, 1);
- // Get the layer connected to the output slot and determine unique layer name.
+ // Determine unique output tensor name.
outputName = GenerateUniqueOutputName(*layer, 0);
}
diff --git a/src/backends/tosaCommon/operatorMappings/AvgPool2DIgnoreValueOperator.cpp b/src/backends/tosaCommon/operatorMappings/AvgPool2DIgnoreValueOperator.cpp
index d268c2faa4..61de0ae39a 100644
--- a/src/backends/tosaCommon/operatorMappings/AvgPool2DIgnoreValueOperator.cpp
+++ b/src/backends/tosaCommon/operatorMappings/AvgPool2DIgnoreValueOperator.cpp
@@ -19,11 +19,11 @@ TosaSerializationBasicBlock* ConvertAvgPool2DIgnoreValueToTosaOperator(const Lay
// using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
if(layer != nullptr)
{
- // Get the layers connected to the input slots and determine unique layer names.
+ // Get the layers connected to the input slots and determine unique tensors names.
Layer& connectedInputLayer = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
padInputName = GenerateUniqueName(connectedInputLayer, 0);
- // Get the layer connected to the output slot and determine unique layer name.
+ // Determine unique output tensor name.
poolOutputName = GenerateUniqueOutputName(*layer, 0);
}
diff --git a/src/backends/tosaCommon/operatorMappings/CMakeLists.txt b/src/backends/tosaCommon/operatorMappings/CMakeLists.txt
index 90c1a4f958..2443dc0585 100644
--- a/src/backends/tosaCommon/operatorMappings/CMakeLists.txt
+++ b/src/backends/tosaCommon/operatorMappings/CMakeLists.txt
@@ -8,6 +8,8 @@ list(APPEND armnnTosaBackendOperators_sources
AdditionOperator.cpp
AvgPool2DIgnoreValueOperator.hpp
AvgPool2DIgnoreValueOperator.cpp
+ ConcatOperator.hpp
+ ConcatOperator.cpp
ConstantOperator.hpp
ConstantOperator.cpp
Conv2dOperator.hpp
diff --git a/src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp b/src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp
new file mode 100644
index 0000000000..8c651be052
--- /dev/null
+++ b/src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp
@@ -0,0 +1,81 @@
+//
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ConcatOperator.hpp"
+
+TosaSerializationBasicBlock* ConvertConcatToTosaOperator(const Layer* layer,
+ const std::vector<const TensorInfo*>& inputs,
+ const std::vector<const TensorInfo*>& outputs,
+ const OriginsDescriptor* concatDescriptor)
+{
+ auto numInputs = inputs.size();
+ std::vector<std::string> inputNames;
+ inputNames.reserve(numInputs);
+ std::string outputName = std::string("output0_");
+ std::string blockName = std::string("Op_CONCAT_block_") + GetUniqueTosaMappingID();
+
+ // Set input names for validation purposes only.
+ if (layer == nullptr)
+ {
+ for (uint32_t i = 0; i < numInputs; ++i)
+ {
+ inputNames.push_back("input"+ std::to_string(i) +"_");
+ }
+ }
+ // If a layer is present then the block will be used for execution, so input and output names need to be determined
+ // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
+ else
+ {
+ // Get the layers connected to the input slots and determine unique tensor names.
+ for (uint32_t i = 0; i < numInputs; ++i)
+ {
+ Layer& connectedLayer = layer->GetInputSlot(i).GetConnectedOutputSlot()->GetOwningLayer();
+
+ std::string inputName = GenerateUniqueName(connectedLayer, i);
+ inputNames.push_back(inputName);
+ }
+
+ // Determine unique output tensor name.
+ outputName = GenerateUniqueOutputName(*layer, 0);
+ }
+
+ auto axis = static_cast<int32_t>(concatDescriptor->GetConcatAxis());
+ TosaAxisAttribute attribute(axis);
+
+ TosaSerializationOperator* op = new TosaSerializationOperator(Op_CONCAT,
+ Attribute_AxisAttribute,
+ &attribute,
+ inputNames,
+ {outputName});
+
+ std::vector<TosaSerializationTensor*> tensors;
+ tensors.reserve(numInputs);
+
+ for (uint32_t i = 0; i < numInputs; ++i)
+ {
+ // Only add input tensors for validation or when the connected layer is an input layer.
+ // As there can't be duplicate tensors and intermediate or constant tensors are created separately.
+ if(inputNames[i].find("input") != std::string::npos)
+ {
+ std::vector<int32_t> inputShape = GetTosaTensorShape(inputs[i]->GetShape());
+ DType inputDType = ArmNNToDType(inputs[i]->GetDataType());
+ tensors.push_back(new TosaSerializationTensor(inputNames[i], inputShape, inputDType, {}));
+ }
+ }
+
+ std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape());
+ DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType());
+
+ TosaSerializationTensor* outputTensor0 = new TosaSerializationTensor(outputName, outputShape0, outputDType0, {});
+ tensors.push_back(outputTensor0);
+
+ // operatorInputNames/operatorOutputNames ends up being the same as
+ // blockInputNames/blockOutputNames for one-to-one ArmNN to TOSA mappings
+ return new TosaSerializationBasicBlock(blockName, // name
+ {op}, // operators
+ tensors, // tensors
+ inputNames, // inputs
+ {outputName}); // outputs
+} \ No newline at end of file
diff --git a/src/backends/tosaCommon/operatorMappings/ConcatOperator.hpp b/src/backends/tosaCommon/operatorMappings/ConcatOperator.hpp
new file mode 100644
index 0000000000..e6094ce03a
--- /dev/null
+++ b/src/backends/tosaCommon/operatorMappings/ConcatOperator.hpp
@@ -0,0 +1,20 @@
+//
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <Layer.hpp>
+
+#include <tosa_serialization_handler.h>
+
+#include "TosaOperatorUtils.hpp"
+
+using namespace armnn;
+using namespace tosa;
+
+TosaSerializationBasicBlock* ConvertConcatToTosaOperator(const Layer* layer,
+ const std::vector<const TensorInfo*>& inputs,
+ const std::vector<const TensorInfo*>& outputs,
+ const OriginsDescriptor* concatDescriptor);
diff --git a/src/backends/tosaCommon/operatorMappings/Conv2dOperator.cpp b/src/backends/tosaCommon/operatorMappings/Conv2dOperator.cpp
index 6fc1678c81..a7af08347a 100644
--- a/src/backends/tosaCommon/operatorMappings/Conv2dOperator.cpp
+++ b/src/backends/tosaCommon/operatorMappings/Conv2dOperator.cpp
@@ -24,21 +24,21 @@ TosaSerializationBasicBlock* ConvertConv2dToTosaOperator(const Layer* layer,
inputNames.emplace_back("input2_");
}
}
+ // If a layer is present then the block will be used for execution, so input and output names need to be
+ // determined using the previous and following layers so the graph is connected correctly.
+ // For validation this doesn't matter.
else
{
- // If a layer is present then the block will be used for execution, so input and output names need to be
- // determined using the previous and following layers so the graph is connected correctly.
- // For validation this doesn't matter.
+ // Get the layer connected to the input slot and determine unique tensor names.
for (uint32_t i = 0; i < inputs.size(); ++i)
{
- // Get the layer connected to the input slot and determine unique layer name.
Layer& connectedLayer = layer->GetInputSlot(i).GetConnectedOutputSlot()->GetOwningLayer();
std::string inputName = GenerateUniqueName(connectedLayer, i);
inputNames.push_back(inputName);
}
- // Get the layer connected to the output slot and determine unique layer name.
+ // Determine unique output tensor name.
outputName = GenerateUniqueOutputName(*layer, 0);
}
diff --git a/src/backends/tosaCommon/operatorMappings/Pooling2DOperator.cpp b/src/backends/tosaCommon/operatorMappings/Pooling2DOperator.cpp
index ee02425c17..444d99a39e 100644
--- a/src/backends/tosaCommon/operatorMappings/Pooling2DOperator.cpp
+++ b/src/backends/tosaCommon/operatorMappings/Pooling2DOperator.cpp
@@ -21,11 +21,11 @@ TosaSerializationBasicBlock* ConvertPooling2DToTosaOperator(const Layer* layer,
// using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
if(layer != nullptr)
{
- // Get the layers connected to the input slots and determine unique layer names.
+ // Get the layers connected to the input slots and determine unique tensor names.
Layer& connectedInputLayer = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
input0Name = GenerateUniqueName(connectedInputLayer, 0);
- // Get the layer connected to the output slot and determine unique layer name.
+ // Determine unique output tensor name.
outputName = GenerateUniqueOutputName(*layer, 0);
}
diff --git a/src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp b/src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp
index 3027e2ef42..10670ecb95 100644
--- a/src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp
+++ b/src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp
@@ -18,11 +18,11 @@ TosaSerializationBasicBlock* ConvertReshapeToTosaOperator(const Layer* layer,
// using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
if(layer != nullptr)
{
- // Get the layers connected to the input slots and determine unique layer names.
+ // Get the layers connected to the input slots and determine unique tensor names.
Layer& connectedLayer = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
inputName = GenerateUniqueName(connectedLayer, 0);
- // Get the layer connected to the output slot and determine unique layer name.
+ // Determine unique output tensor name.
outputName = GenerateUniqueOutputName(*layer, 0);
}
diff --git a/src/backends/tosaCommon/operatorMappings/SliceOperator.cpp b/src/backends/tosaCommon/operatorMappings/SliceOperator.cpp
index 742ba88d73..b98576f47d 100644
--- a/src/backends/tosaCommon/operatorMappings/SliceOperator.cpp
+++ b/src/backends/tosaCommon/operatorMappings/SliceOperator.cpp
@@ -18,11 +18,11 @@ TosaSerializationBasicBlock* ConvertSliceToTosaOperator(const Layer* layer,
// using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
if(layer != nullptr)
{
- // Get the layers connected to the input slots and determine unique layer names.
+ // Get the layers connected to the input slots and determine unique tensor names.
Layer& connectedLayer = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
inputName = GenerateUniqueName(connectedLayer, 0);
- // Get the layer connected to the output slot and determine unique layer name.
+ // Determine unique output tensor name.
outputName = GenerateUniqueOutputName(*layer, 0);
}
diff --git a/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp b/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp
index 1a9d6be9c0..052c54c3af 100644
--- a/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp
+++ b/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp
@@ -6,6 +6,7 @@
#pragma once
#include "AdditionOperator.hpp"
+#include "ConcatOperator.hpp"
#include "ConstantOperator.hpp"
#include "Conv2dOperator.hpp"
#include "AvgPool2DIgnoreValueOperator.hpp"
diff --git a/src/backends/tosaCommon/operatorMappings/TransposeConv2dOperator.cpp b/src/backends/tosaCommon/operatorMappings/TransposeConv2dOperator.cpp
index 1ad8c9562f..c8af5c2926 100644
--- a/src/backends/tosaCommon/operatorMappings/TransposeConv2dOperator.cpp
+++ b/src/backends/tosaCommon/operatorMappings/TransposeConv2dOperator.cpp
@@ -22,9 +22,11 @@ TosaSerializationBasicBlock* ConvertTransposeConv2dToTosaOperator(const Layer* l
// using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
if(layer != nullptr)
{
+ // Get the layers connected to the input slots and determine unique tensor names.
Layer& connectedInputLayer = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
input0Name = GenerateUniqueName(connectedInputLayer, 0);
+ // Determine unique output tensor name.
outputName = GenerateUniqueOutputName(*layer, 0);
}