38 template<
typename FactoryType>
48 if (factory.SupportsSubTensors())
54 && ((concatAxis == numberOfDimensions - 1) || (concatAxis == numberOfDimensions - 2));
58 std::queue<ConcatLayer*> m_ConcatLayers;
60 m_ConcatLayers.push(
this);
61 while (!m_ConcatLayers.empty())
71 bool canUseSubTensorOnXorY =
true;
72 bool isTensorHandleFactory = std::is_same<armnn::ITensorHandleFactory, FactoryType>::value;
73 if (isTensorHandleFactory)
75 for (
unsigned int i = 0; i < numInputSlots; ++i)
79 std::vector<Capability> capabilities =
85 canUseSubTensorOnXorY =
false;
86 if (capabilities.empty())
88 canUseSubTensorOnXorY =
true;
92 if (!canUseSubTensorOnXorY)
100 std::vector<std::unique_ptr<ITensorHandle>> subTensors(0);
101 subTensors.reserve(numInputSlots);
102 for (
unsigned int i = 0; i < numInputSlots; ++i)
107 auto CreateSubTensor = [&]()
121 canUseSubTensorOnXorY)
124 return factory.CreateSubTensorHandle(*parentTensor,
129 return std::unique_ptr<ITensorHandle>();
132 auto subTensor = CreateSubTensor();
139 subTensors.push_back(std::move(subTensor));
144 if (subTensors.size() < numInputSlots)
151 for (
auto& subTensor : subTensors)
156 ARMNN_ASSERT_MSG(subTensor,
"ConcatLayer: Expected a valid sub-tensor for substitution.");
157 outputHandler.
SetData(std::move(subTensor));
163 m_ConcatLayers.push(PolymorphicDowncast<ConcatLayer*>(&inputLayer));
173 const bool isMemoryManaged)
180 CreateTensors(registry, workloadFactory, isMemoryManaged);
186 CreateTensors(registry, *handleFactory, isMemoryManaged);
200 for (
unsigned int i=0; i< inputShapes.size(); i++)
202 auto& inputShape = inputShapes[i];
204 ConditionalThrowIfNotEqual<LayerValidationException>(
205 "ConcatLayer: Num Dimensions must match all inputs.",
207 inputShape.GetNumDimensions());
211 std::vector<unsigned int> extentMin(numDims);
212 std::vector<unsigned int> extentMax(numDims);
213 for (
unsigned int i = 0; i < inputShapes.size(); i++)
217 for (
unsigned int d = 0; d < numDims; d++)
219 extentMin[d] = std::min(extentMin[d], origin[d]);
220 extentMax[d] = std::max(extentMax[d], origin[d] + shape[d]);
225 if (!std::all_of(extentMin.begin(), extentMin.end(), [](
unsigned int s) {
return s == 0; }))
233 for (
unsigned int a = 0; a < inputShapes.size(); a++)
237 for (
unsigned int b = 0; b < a; b++)
242 bool allAxesOverlap =
true;
243 for (
unsigned int d = 0; d < numDims && allAxesOverlap; d++)
245 unsigned int a1 = aOrigin[d];
246 unsigned int a2 = aOrigin[d] + aShape[d];
248 unsigned int b1 = bOrigin[d];
249 unsigned int b2 = bOrigin[d] + bShape[d];
251 if (a2 <= b1 || b2 <= a1)
253 allAxesOverlap =
false;
266 unsigned int totalViewsVolume = 0;
267 for (
unsigned int i = 0; i < inputShapes.size(); i++)
269 totalViewsVolume += inputShapes[i].GetNumElements();
271 unsigned int outputVolume = 1;
272 for (
unsigned int d = 0; d < numDims; d++)
274 outputVolume *= (extentMax[d] - extentMin[d]);
277 ConditionalThrowIfNotEqual<LayerValidationException>(
278 "ConcatLayer: there are some gaps between views",
282 return std::vector<TensorShape>({
TensorShape({numDims, extentMax.data()}) });
288 ConditionalThrowIfNotEqual<LayerValidationException>(
289 "ConcatLayer: Num Inputs must match num views.",
299 std::vector<TensorShape> inputShapes;
ConcatLayer(const OriginsDescriptor ¶m, const char *name)
Constructor to create a ConcatLayer.
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.
bool IsTypeSpaceMatch(const TensorInfo &other) const
Check that the types are the same and, if quantize, that the quantization parameters are the same...
OriginsDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
const OriginsDescriptor & GetParameters() const
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
const TensorShape & GetShape() const
void SetData(std::unique_ptr< ITensorHandle > data)
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Concat type.
Layer & GetOwningLayer() const
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Copyright (c) 2020 ARM Limited.
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
ConcatLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
virtual std::unique_ptr< IWorkload > CreateConcat(const ConcatQueueDescriptor &descriptor, const WorkloadInfo &info) const
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
unsigned int GetNumConnections() const override
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
const uint32_t * GetViewOrigin(uint32_t idx) const
Return the view origin at the int value idx.
virtual std::vector< Capability > GetCapabilities(const IConnectableLayer *layer, const IConnectableLayer *connectedLayer, CapabilityClass capabilityClass)
std::vector< ViewOrigin > m_ViewOrigins
#define ARMNN_NO_DEPRECATE_WARN_END
#define ARMNN_ASSERT_MSG(COND, MSG)
An OriginsDescriptor for the ConcatLayer.
void Accept(ILayerVisitor &visitor) const override
Apply a visitor to this layer.
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of ConcatLayer.
This layer represents a merge operation.
#define ARMNN_ASSERT(COND)
ITensorHandle * GetData() const
Gets the allocated tensor memory.
std::vector< OutputHandler > m_OutputHandlers
virtual void VisitConcatLayer(const IConnectableLayer *layer, const OriginsDescriptor &concatDescriptor, const char *name=nullptr)
Function that a concat layer should call back to when its Accept(ILayerVisitor&) function is invoked...
const OutputHandler & GetOutputHandler(unsigned int i=0) const
ClWorkloadFactory FactoryType
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
Find a TensorHandleFactory by Id Returns nullptr if not found.
uint32_t GetNumDimensions() const
Get the number of dimensions.
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
LayerType GetType() const
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
const OutputHandler & GetOutputHandler() const
const char * GetName() const override
Returns the name of the layer.
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
uint32_t GetNumViews() const
Get the number of views.
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
unsigned int GetConcatAxis() const
Get the concatenation axis value.
const TensorInfo & GetTensorInfo() const override
static const FactoryId LegacyFactoryId
ShapeInferenceMethod m_ShapeInferenceMethod
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true) override
Set the outputs to be appropriate sub tensors of the input if sub tensors are supported otherwise cre...
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.