38 template<
typename FactoryType>
39 void ConcatLayer::CreateTensors(
const FactoryType& factory)
46 if (factory.SupportsSubTensors())
50 std::queue<ConcatLayer*> m_ConcatLayers;
52 m_ConcatLayers.push(
this);
53 while (!m_ConcatLayers.empty())
63 std::vector<std::unique_ptr<ITensorHandle>> subTensors(0);
64 subTensors.reserve(numInputSlots);
65 for (
unsigned int i = 0; i < numInputSlots; ++i)
70 auto CreateSubTensor = [&]()
84 return factory.CreateSubTensorHandle(*parentTensor,
88 return std::unique_ptr<ITensorHandle>();
91 auto subTensor = CreateSubTensor();
98 subTensors.push_back(std::move(subTensor));
103 if (subTensors.size() < numInputSlots)
110 for (
auto& subTensor : subTensors)
115 ARMNN_ASSERT_MSG(subTensor,
"ConcatLayer: Expected a valid sub-tensor for substitution.");
116 outputHandler.
SetData(std::move(subTensor));
122 m_ConcatLayers.push(PolymorphicDowncast<ConcatLayer*>(&inputLayer));
132 const bool IsMemoryManaged)
140 CreateTensors(workloadFactory);
146 CreateTensors(*handleFactory);
160 for (
unsigned int i=0; i< inputShapes.size(); i++)
162 auto& inputShape = inputShapes[i];
164 ConditionalThrowIfNotEqual<LayerValidationException>(
165 "ConcatLayer: Num Dimensions must match all inputs.",
167 inputShape.GetNumDimensions());
171 std::vector<unsigned int> extentMin(numDims);
172 std::vector<unsigned int> extentMax(numDims);
173 for (
unsigned int i = 0; i < inputShapes.size(); i++)
177 for (
unsigned int d = 0; d < numDims; d++)
179 extentMin[d] = std::min(extentMin[d], origin[d]);
180 extentMax[d] = std::max(extentMax[d], origin[d] + shape[d]);
185 if (!std::all_of(extentMin.begin(), extentMin.end(), [](
unsigned int s) {
return s == 0; }))
193 for (
unsigned int a = 0; a < inputShapes.size(); a++)
197 for (
unsigned int b = 0; b < a; b++)
202 bool allAxesOverlap =
true;
203 for (
unsigned int d = 0; d < numDims && allAxesOverlap; d++)
205 unsigned int a1 = aOrigin[d];
206 unsigned int a2 = aOrigin[d] + aShape[d];
208 unsigned int b1 = bOrigin[d];
209 unsigned int b2 = bOrigin[d] + bShape[d];
211 if (a2 <= b1 || b2 <= a1)
213 allAxesOverlap =
false;
226 unsigned int totalViewsVolume = 0;
227 for (
unsigned int i = 0; i < inputShapes.size(); i++)
229 totalViewsVolume += inputShapes[i].GetNumElements();
231 unsigned int outputVolume = 1;
232 for (
unsigned int d = 0; d < numDims; d++)
234 outputVolume *= (extentMax[d] - extentMin[d]);
237 ConditionalThrowIfNotEqual<LayerValidationException>(
238 "ConcatLayer: there are some gaps between views",
242 return std::vector<TensorShape>({
TensorShape({numDims, extentMax.data()}) });
248 ConditionalThrowIfNotEqual<LayerValidationException>(
249 "ConcatLayer: Num Inputs must match num views.",
255 std::vector<TensorShape> inputShapes;
265 ConditionalThrowIfNotEqual<LayerValidationException>(
266 "ConcatLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
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)
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Concat type.
Layer & GetOwningLayer() const
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
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.
std::vector< ViewOrigin > m_ViewOrigins
#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 override
static const FactoryId LegacyFactoryId
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.