ArmNN
 20.02
SwitchLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "SwitchLayer.hpp"
6 
7 #include "LayerCloneBase.hpp"
8 
11 
12 namespace armnn
13 {
14 
15 SwitchLayer::SwitchLayer(const char* name)
16  : Layer(2, 2, LayerType::Switch, name)
17 {}
18 
19 std::unique_ptr<IWorkload> SwitchLayer::CreateWorkload(const IWorkloadFactory& factory) const
20 {
21  SwitchQueueDescriptor descriptor;
22  return factory.CreateSwitch(descriptor, PrepInfoAndDesc(descriptor));
23 }
24 
26 {
27  return CloneBase<SwitchLayer>(graph, GetName());
28 }
29 
31 {
33 
34  BOOST_ASSERT_MSG(GetNumOutputSlots() == 2, "SwitchLayer: The layer should return 2 outputs.");
35 
36  // Assuming first input is the Input and second input is the Constant
37  std::vector<TensorShape> inferredShapes = InferOutputShapes({
40 
41  BOOST_ASSERT(inferredShapes.size() == 2);
42 
43  ConditionalThrowIfNotEqual<LayerValidationException>(
44  "SwitchLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
46  inferredShapes[0]);
47 
48  ConditionalThrowIfNotEqual<LayerValidationException>(
49  "SwitchLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
51  inferredShapes[0]);
52 }
53 
54 void SwitchLayer::Accept(ILayerVisitor& visitor) const
55 {
56  visitor.VisitSwitchLayer(this, GetName());
57 }
58 
59 } // namespace armnn
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Infer the shape of the output(s) based on the provided input shape(s)
Definition: Layer.cpp:371
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Switch type.
Definition: SwitchLayer.cpp:19
Copyright (c) 2020 ARM Limited.
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
Definition: Layer.hpp:308
SwitchLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: SwitchLayer.cpp:25
SwitchLayer(const char *name)
Constructor to create a SwitchLayer.
Definition: SwitchLayer.cpp:15
virtual void VisitSwitchLayer(const IConnectableLayer *layer, const char *name=nullptr)=0
Function a switch layer should call back to when its Accept(ILayerVisitor&) function is invoked...
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:338
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:310
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of SwitchLayer.
Definition: SwitchLayer.cpp:30
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
Definition: Layer.hpp:351
void Accept(ILayerVisitor &visitor) const override
Apply a visitor to this layer.
Definition: SwitchLayer.cpp:54
virtual std::unique_ptr< IWorkload > CreateSwitch(const SwitchQueueDescriptor &descriptor, const WorkloadInfo &Info) const
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
This layer calculates both true and false outputs for input.
Definition: SwitchLayer.hpp:13
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:312
virtual const TensorInfo & GetTensorInfo() const =0
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:305
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63