ArmNN
 20.08
SliceLayer.cpp
Go to the documentation of this file.
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 
14 
15 #include <boost/numeric/conversion/cast.hpp>
16 
17 namespace armnn
18 {
19 
20 SliceLayer::SliceLayer(const SliceDescriptor& param, const char* name)
21  : LayerWithParameters(1, 1, LayerType::Slice, param, name)
22 {
23 }
24 
25 std::unique_ptr<IWorkload> SliceLayer::CreateWorkload(const IWorkloadFactory& factory) const
26 {
27  SliceQueueDescriptor descriptor;
28  return factory.CreateSlice(descriptor, PrepInfoAndDesc(descriptor));
29 }
30 
32 {
33  return CloneBase<SliceLayer>(graph, m_Param, GetName());
34 }
35 
37 {
39 
40  const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
41 
43 
44  auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
45 
46  ARMNN_ASSERT(inferredShapes.size() == 1);
47 
48  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SliceLayer");
49 }
50 
51 std::vector<TensorShape> SliceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
52 {
53  IgnoreUnused(inputShapes);
54  ARMNN_ASSERT(inputShapes.size() == 1);
55 
56  TensorShape outputShape(boost::numeric_cast<unsigned int>(m_Param.m_Size.size()), m_Param.m_Size.data());
57 
58  return std::vector<TensorShape>({ outputShape });
59 }
60 
61 void SliceLayer::Accept(ILayerVisitor& visitor) const
62 {
63  visitor.VisitSliceLayer(this, GetParameters(), GetName());
64 }
65 
66 } // namespace armnn
SliceDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
void Slice(const TensorInfo &inputInfo, const SliceDescriptor &descriptor, const void *inputData, void *outputData, unsigned int dataTypeSize)
Definition: Slice.cpp:16
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of SliceLayer.
Definition: SliceLayer.cpp:36
const TensorShape & GetShape() const
Definition: Tensor.hpp:187
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition: Layer.cpp:432
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition: Layer.cpp:392
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:344
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:312
SliceLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: SliceLayer.cpp:31
virtual void VisitSliceLayer(const IConnectableLayer *layer, const SliceDescriptor &sliceDescriptor, const char *name=nullptr)=0
Function that a slice layer should call back to when its Accept(ILayerVisitor&) function is invoked...
SliceLayer(const SliceDescriptor &param, const char *name)
Constructor to create a SliceLayer.
Definition: SliceLayer.cpp:20
void Accept(ILayerVisitor &visitor) const override
Apply a visitor to this layer.
Definition: SliceLayer.cpp:61
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Slice type.
Definition: SliceLayer.cpp:25
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
#define CHECK_LOCATION()
Definition: Exceptions.hpp:197
A SliceDescriptor for the SliceLayer.
virtual std::unique_ptr< IWorkload > CreateSlice(const SliceQueueDescriptor &descriptor, const WorkloadInfo &info) const
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:314
virtual const TensorInfo & GetTensorInfo() const =0
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:307
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties.
Definition: SliceLayer.cpp:51
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
ShapeInferenceMethod m_ShapeInferenceMethod
Definition: Layer.hpp:387