aboutsummaryrefslogtreecommitdiff
path: root/src/backends/tosaCommon/operatorMappings/TosaOperatorUtils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings/TosaOperatorUtils.hpp')
-rw-r--r--src/backends/tosaCommon/operatorMappings/TosaOperatorUtils.hpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/TosaOperatorUtils.hpp b/src/backends/tosaCommon/operatorMappings/TosaOperatorUtils.hpp
index 047e0a1f42..f566504a40 100644
--- a/src/backends/tosaCommon/operatorMappings/TosaOperatorUtils.hpp
+++ b/src/backends/tosaCommon/operatorMappings/TosaOperatorUtils.hpp
@@ -48,6 +48,33 @@ inline DType ArmNNToDType(const DataType& type)
}
}
+// Function to return ArmNN datatype from input Tosa datatype.
+inline DataType DtypeToArmNN(const DType type)
+{
+ switch (type)
+ {
+ case DType_FP16:
+ return DataType::Float16;
+ case DType_BF16:
+ return DataType::BFloat16;
+ case DType_FP32:
+ return DataType::Float32;
+ case DType_UINT8:
+ return DataType::QAsymmU8;
+ case DType_INT8:
+ return DataType::QSymmS8;
+ case DType_INT16:
+ return DataType::QSymmS16;
+ case DType_INT32:
+ return DataType::Signed32;
+ case DType_BOOL:
+ return DataType::Boolean;
+ default:
+ throw armnn::Exception("DtypeToArmNN: Unsupported tosa::DType in ArmNN.");
+ return DataType::Boolean;
+ }
+}
+
// Function to return Tosa tensor shape from input ArmNN tensor shape.
inline std::vector<int32_t> GetTosaTensorShape(const TensorShape& shape)
{
@@ -60,7 +87,7 @@ inline std::vector<int32_t> GetTosaTensorShape(const TensorShape& shape)
}
// Function that generates unique name using the layer type, input slot and layer guid.
-inline std::string GenerateUniqueName(const Layer& layer, uint32_t layerSlot)
+static std::string GenerateUniqueName(const Layer& layer, uint32_t layerSlot)
{
std::string guid = std::to_string(layer.GetGuid());
std::string slotAndGuid = std::to_string(layerSlot) + "_" + guid;
@@ -68,7 +95,7 @@ inline std::string GenerateUniqueName(const Layer& layer, uint32_t layerSlot)
switch (layer.GetType())
{
case LayerType::Input:
- return "input" + slotAndGuid;
+ return "input_" + guid;
case LayerType::Output:
return "output" + slotAndGuid;
case LayerType::Constant:
@@ -78,8 +105,19 @@ inline std::string GenerateUniqueName(const Layer& layer, uint32_t layerSlot)
}
}
+// Function that generates unique name for the parent layer from the child layer input slot.
+inline std::string GenerateUniqueInputName(const armnn::InputSlot& slot)
+{
+ // Get the layers connected to the input slots and determine unique tensor names.
+ Layer& connectedLayer = slot.GetConnectedOutputSlot()->GetOwningLayer();
+ // For layer input, we want to ensure we get the correct output slot of the parent layer.
+ // For example, if parent layer is split, the parent output slot could be 0 or 1 index.
+ uint32_t connectedOutputSlotIdx = slot.GetConnectedOutputSlot()->CalculateIndexOnOwner();
+ return GenerateUniqueName(connectedLayer, connectedOutputSlotIdx);
+}
+
// Function that generates unique output name using the layer type, input slot and layer guid.
-inline std::string GenerateUniqueOutputName(const Layer& layer, uint32_t layerSlot)
+inline std::string GenerateUniqueOutputName(const Layer& layer, uint32_t layerSlot = 0)
{
Layer& connectedLayer = layer.GetOutputSlot().GetConnection(0)->GetOwningLayer();
@@ -416,6 +454,12 @@ inline std::vector<uint8_t> CreateConstTosaData(const void* value,
error = TosaSerializationHandler::ConvertI8toU8(data, uint8Data);
break;
}
+ case DType::DType_UINT8:
+ {
+ const int8_t* copy_data = static_cast<const int8_t*>(value);
+ uint8Data.assign(copy_data, copy_data + numElements);
+ break;
+ }
case DType::DType_INT4:
{
std::vector<int8_t> data(numElements, *static_cast<const int8_t*>(value));