2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
5 #include "MultiplicationLayer.hpp"
7 #include "LayerCloneBase.hpp"
9 #include <armnn/TypesUtils.hpp>
10 #include <backends/WorkloadData.hpp>
11 #include <backends/WorkloadFactory.hpp>
16 MultiplicationLayer::MultiplicationLayer(const char* name)
17 : Layer(2, 1, LayerType::Multiplication, name)
21 std::unique_ptr<IWorkload> MultiplicationLayer::CreateWorkload(const Graph& graph,
22 const IWorkloadFactory& factory) const
24 MultiplicationQueueDescriptor descriptor;
26 return factory.CreateMultiplication(descriptor, PrepInfoAndDesc(descriptor, graph));
29 MultiplicationLayer* MultiplicationLayer::Clone(Graph& graph) const
31 return CloneBase<MultiplicationLayer>(graph, GetName());
34 std::vector<TensorShape> MultiplicationLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
36 BOOST_ASSERT(inputShapes.size() == 2);
37 auto& input0 = inputShapes[0];
38 auto& input1 = inputShapes[1];
40 // Get the max of the inputs.
41 BOOST_ASSERT(input0.GetNumDimensions() == input1.GetNumDimensions());
42 unsigned int numDims = input0.GetNumDimensions();
43 std::vector<unsigned int> dims(numDims);
45 for (unsigned int i = 0; i < numDims; i++)
47 unsigned int dim0 = input0[i];
48 unsigned int dim1 = input1[i];
50 // Validates inputs are broadcast compatible.
54 BOOST_ASSERT_MSG(dim0 == 1 || dim1 == 1, "Dimensions should either match or one should be of size 1.");
58 dims[i] = std::max(dim0, dim1);
61 return std::vector<TensorShape>({ TensorShape(numDims, dims.data()) });
64 void MultiplicationLayer::ValidateTensorShapesFromInputs()
66 VerifyLayerConnections(2, CHECK_LOCATION());
68 auto inferredShapes = InferOutputShapes({
69 GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape(),
70 GetInputSlot(1).GetConnection()->GetTensorInfo().GetShape()
73 BOOST_ASSERT(inferredShapes.size() == 1);
75 ConditionalThrowIfNotEqual<LayerValidationException>(
76 "MultiplicationLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
77 GetOutputSlot(0).GetTensorInfo().GetShape(),