blob: f0b7139b26bbd5ad1d8d8209a1b95da74ecebfef [file] [log] [blame]
//
// Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "TransposeLayer.hpp"
#include "LayerCloneBase.hpp"
#include <armnn/TypesUtils.hpp>
#include <armnnUtils/Transpose.hpp>
#include <armnn/backends/WorkloadData.hpp>
#include <armnn/backends/WorkloadFactory.hpp>
namespace armnn
{
TransposeLayer::TransposeLayer(const TransposeDescriptor& param, const char* name)
: LayerWithParameters(1, 1, LayerType::Transpose, param, name)
{
}
std::unique_ptr<IWorkload> TransposeLayer::CreateWorkload(const IWorkloadFactory& factory) const
{
TransposeQueueDescriptor descriptor;
SetAdditionalInfo(descriptor);
return factory.CreateWorkload(LayerType::Transpose, descriptor, PrepInfoAndDesc(descriptor));
}
TransposeLayer* TransposeLayer::Clone(Graph& graph) const
{
return CloneBase<TransposeLayer>(graph, m_Param, GetName());
}
std::vector<TensorShape> TransposeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
{
if (inputShapes.size() != 1)
{
throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) +
"\" - should be \"1\".");
}
const TensorShape& inShape = inputShapes[0];
return std::vector<TensorShape> ({armnnUtils::TransposeTensorShape(inShape, m_Param.m_DimMappings)});
}
void TransposeLayer::ValidateTensorShapesFromInputs()
{
VerifyLayerConnections(1, CHECK_LOCATION());
const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() });
if (inferredShapes.size() != 1)
{
throw armnn::LayerValidationException("inferredShapes has "
+ std::to_string(inferredShapes.size()) +
" elements - should only have 1.");
}
ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "TransposeLayer");
}
void TransposeLayer::ExecuteStrategy(IStrategy& strategy) const
{
strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
}
} // namespace armnn