ArmNN  NotReleased
ElementwiseBaseLayer Class Reference

#include <ElementwiseBaseLayer.hpp>

Inheritance diagram for ElementwiseBaseLayer:
Layer IConnectableLayer AdditionLayer DivisionLayer MaximumLayer MinimumLayer MultiplicationLayer SubtractionLayer

Public Member Functions

void ValidateTensorShapesFromInputs () override
 
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 
- Public Member Functions inherited from Layer
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, DataLayout layout, const char *name)
 
const std::string & GetNameStr () const
 
const OutputHandlerGetOutputHandler (unsigned int i=0) const
 
OutputHandlerGetOutputHandler (unsigned int i=0)
 
const std::vector< InputSlot > & GetInputSlots () const
 
const std::vector< OutputSlot > & GetOutputSlots () const
 
std::vector< InputSlot >::iterator BeginInputSlots ()
 
std::vector< InputSlot >::iterator EndInputSlots ()
 
std::vector< OutputSlot >::iterator BeginOutputSlots ()
 
std::vector< OutputSlot >::iterator EndOutputSlots ()
 
bool IsOutputUnconnected ()
 
void ResetPriority () const
 
LayerPriority GetPriority () const
 
LayerType GetType () const
 
DataType GetDataType () const
 
const BackendIdGetBackendId () const
 
void SetBackendId (const BackendId &id)
 
virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const =0
 
virtual void CreateTensorHandles (const TensorHandleFactoryRegistry &registry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
 
virtual LayerClone (Graph &graph) const =0
 
void VerifyLayerConnections (unsigned int expectedConnections, const CheckLocation &location) const
 
virtual void SerializeLayerParameters (ParameterStringifyFunction &fn) const
 
virtual void ReleaseConstantData ()
 
template<typename Op >
void OperateOnConstantTensors (Op op)
 
const char * GetName () const override
 
unsigned int GetNumInputSlots () const override
 
unsigned int GetNumOutputSlots () const override
 
const InputSlotGetInputSlot (unsigned int index) const override
 
InputSlotGetInputSlot (unsigned int index) override
 
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 
OutputSlotGetOutputSlot (unsigned int index=0) override
 
void SetGuid (LayerGuid guid)
 
LayerGuid GetGuid () const final
 
void AddRelatedLayerName (const std::string layerName)
 
const std::list< std::string > & GetRelatedLayerNames ()
 
virtual void Reparent (Graph &dest, std::list< Layer *>::const_iterator iterator)=0
 
- Public Member Functions inherited from IConnectableLayer
virtual void Accept (ILayerVisitor &visitor) const =0
 

Protected Member Functions

 ElementwiseBaseLayer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 
 ~ElementwiseBaseLayer ()=default
 Default destructor. More...
 
- Protected Member Functions inherited from Layer
virtual ~Layer ()=default
 
template<typename QueueDescriptor >
void CollectQueueDescriptorInputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
void CollectQueueDescriptorOutputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
template<typename LayerType , typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
 
virtual ConstantTensors GetConstantTensorsByRef ()
 
- Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle. More...
 

Additional Inherited Members

- Protected Types inherited from Layer
using ConstantTensors = std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >>
 
- Protected Attributes inherited from Layer
std::vector< OutputHandlerm_OutputHandlers
 

Detailed Description

NOTE: this is an abstract class to encapsulate the element wise operations, it does not implement: std::unique_ptr<IWorkload> Layer::CreateWorkload(const IWorkloadFactory& factory) const = 0; Layer* Clone(Graph& graph) const = 0;

Definition at line 16 of file ElementwiseBaseLayer.hpp.

Constructor & Destructor Documentation

◆ ElementwiseBaseLayer()

ElementwiseBaseLayer ( unsigned int  numInputSlots,
unsigned int  numOutputSlots,
LayerType  type,
const char *  name 
)
protected
Parameters
numInputSlotsThe number of input slots for the layer.
numOutputSlotsThe number of output slots for the layer.
typeThe layer type.
nameOptional name for the layer.

Definition at line 17 of file ElementwiseBaseLayer.cpp.

19  : Layer(numInputSlots, numOutputSlots, type, name)
20 {
21 }
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
Definition: Layer.cpp:212

◆ ~ElementwiseBaseLayer()

~ElementwiseBaseLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ InferOutputShapes()

std::vector< TensorShape > InferOutputShapes ( const std::vector< TensorShape > &  inputShapes) const
overridevirtual

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.

Parameters
[in]inputShapesThe input shapes layer has.
Returns
A vector to the inferred output shape.

Reimplemented from Layer.

Definition at line 23 of file ElementwiseBaseLayer.cpp.

Referenced by ElementwiseBaseLayer::ValidateTensorShapesFromInputs().

24 {
25  BOOST_ASSERT(inputShapes.size() == 2);
26  auto& input0 = inputShapes[0];
27  auto& input1 = inputShapes[1];
28 
29  // Get the max of the inputs.
30  BOOST_ASSERT(input0.GetNumDimensions() == input1.GetNumDimensions());
31  unsigned int numDims = input0.GetNumDimensions();
32  std::vector<unsigned int> dims(numDims);
33 
34  for (unsigned int i = 0; i < numDims; i++)
35  {
36  unsigned int dim0 = input0[i];
37  unsigned int dim1 = input1[i];
38 
39 #if !NDEBUG
40  // Validate inputs are broadcast compatible.
41  BOOST_ASSERT_MSG(dim0 == dim1 || dim0 == 1 || dim1 == 1,
42  "Dimensions should either match or one should be of size 1.");
43 #endif
44 
45  dims[i] = std::max(dim0, dim1);
46  }
47 
48  return std::vector<TensorShape>({ TensorShape(numDims, dims.data()) });
49 }

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

Check if the input tensor shape(s) will lead to a valid configuration of the element wise operation.

Implements Layer.

Definition at line 51 of file ElementwiseBaseLayer.cpp.

References CHECK_LOCATION, InputSlot::GetConnection(), Layer::GetInputSlot(), armnn::GetLayerTypeAsCString(), Layer::GetOutputSlot(), TensorInfo::GetShape(), IOutputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), Layer::GetType(), ElementwiseBaseLayer::InferOutputShapes(), and Layer::VerifyLayerConnections().

52 {
54 
55  auto inferredShapes = InferOutputShapes({
58  });
59 
60  BOOST_ASSERT(inferredShapes.size() == 1);
61 
62  std::string msg = GetLayerTypeAsCString(GetType());
63  msg += "Layer: TensorShape set on OutputSlot[0] does not match the inferred shape.";
64  ConditionalThrowIfNotEqual<LayerValidationException>(msg,
66  inferredShapes[0]);
67 }
LayerType GetType() const
Definition: Layer.hpp:259
virtual const TensorInfo & GetTensorInfo() const =0
char const * GetLayerTypeAsCString(LayerType type)
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:337
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

The documentation for this class was generated from the following files: