1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "SliceLayer.hpp"
7
8 #include "LayerCloneBase.hpp"
9
10 #include <armnn/TypesUtils.hpp>
11 #include <armnn/utility/NumericCast.hpp>
12
13 #include <armnn/backends/WorkloadData.hpp>
14 #include <armnn/backends/WorkloadFactory.hpp>
15
16 namespace armnn
17 {
18
SliceLayer(const SliceDescriptor & param,const char * name)19 SliceLayer::SliceLayer(const SliceDescriptor& param, const char* name)
20 : LayerWithParameters(1, 1, LayerType::Slice, param, name)
21 {
22 }
23
CreateWorkload(const IWorkloadFactory & factory) const24 std::unique_ptr<IWorkload> SliceLayer::CreateWorkload(const IWorkloadFactory& factory) const
25 {
26 SliceQueueDescriptor descriptor;
27 SetAdditionalInfo(descriptor);
28
29 return factory.CreateWorkload(LayerType::Slice, descriptor, PrepInfoAndDesc(descriptor));
30 }
31
Clone(Graph & graph) const32 SliceLayer* SliceLayer::Clone(Graph& graph) const
33 {
34 return CloneBase<SliceLayer>(graph, m_Param, GetName());
35 }
36
ValidateTensorShapesFromInputs()37 void SliceLayer::ValidateTensorShapesFromInputs()
38 {
39 VerifyLayerConnections(1, CHECK_LOCATION());
40
41 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
42
43 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
44
45 auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
46
47 ARMNN_ASSERT(inferredShapes.size() == 1);
48
49 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SliceLayer");
50 }
51
InferOutputShapes(const std::vector<TensorShape> & inputShapes) const52 std::vector<TensorShape> SliceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
53 {
54 IgnoreUnused(inputShapes);
55 ARMNN_ASSERT(inputShapes.size() == 1);
56
57 TensorShape outputShape(armnn::numeric_cast<unsigned int>(m_Param.m_Size.size()), m_Param.m_Size.data());
58
59 return std::vector<TensorShape>({ outputShape });
60 }
61
ExecuteStrategy(IStrategy & strategy) const62 void SliceLayer::ExecuteStrategy(IStrategy& strategy) const
63 {
64 strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
65 }
66
67 } // namespace armnn
68