ArmNN  NotReleased
SliceLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. 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/assert.hpp>
16 #include <boost/numeric/conversion/cast.hpp>
17 
18 namespace armnn
19 {
20 
21 SliceLayer::SliceLayer(const SliceDescriptor& param, const char* name)
22  : LayerWithParameters(1, 1, LayerType::Slice, param, name)
23 {
24 }
25 
26 std::unique_ptr<IWorkload> SliceLayer::CreateWorkload(const IWorkloadFactory& factory) const
27 {
28  SliceQueueDescriptor descriptor;
29  return factory.CreateSlice(descriptor, PrepInfoAndDesc(descriptor));
30 }
31 
33 {
34  return CloneBase<SliceLayer>(graph, m_Param, GetName());
35 }
36 
38 {
40 
41  auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
42 
43  BOOST_ASSERT(inferredShapes.size() == 1);
44 
45  ConditionalThrowIfNotEqual<LayerValidationException>(
46  "SliceLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
48  inferredShapes[0]);
49 }
50 
51 std::vector<TensorShape> SliceLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
52 {
53  boost::ignore_unused(inputShapes);
54  BOOST_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
const char * GetName() const override
Definition: Layer.hpp:305
virtual const TensorInfo & GetTensorInfo() const =0
void Accept(ILayerVisitor &visitor) const override
Definition: SliceLayer.cpp:61
SliceLayer * Clone(Graph &graph) const override
Definition: SliceLayer.cpp:32
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Definition: SliceLayer.cpp:51
SliceDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:337
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
virtual void VisitSliceLayer(const IConnectableLayer *layer, const SliceDescriptor &sliceDescriptor, const char *name=nullptr)=0
void Slice(const TensorInfo &inputInfo, const SliceDescriptor &descriptor, const void *inputData, void *outputData, unsigned int dataTypeSize)
Definition: Slice.cpp:15
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Definition: SliceLayer.cpp:26
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
void ValidateTensorShapesFromInputs() override
Definition: SliceLayer.cpp:37
virtual std::unique_ptr< IWorkload > CreateSlice(const SliceQueueDescriptor &descriptor, const WorkloadInfo &info) const
A SliceDescriptor for the SliceLayer.
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Definition: Layer.hpp:312
const InputSlot & GetInputSlot(unsigned int index) const override
Definition: Layer.hpp:310
SliceLayer(const SliceDescriptor &param, const char *name)
Definition: SliceLayer.cpp:21