Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <armnn/Tensor.hpp> |
| 9 | |
| 10 | #include "../ConversionUtils.hpp" |
| 11 | |
| 12 | namespace armnn_driver |
| 13 | { |
| 14 | |
FinnWilliamsArm | 7b8d2e6 | 2020-01-08 14:57:47 +0000 | [diff] [blame] | 15 | inline armnn::TensorShape FlattenFullyConnectedInput(const armnn::TensorShape& inputShape, |
| 16 | const armnn::TensorShape& weightsShape) |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 17 | { |
| 18 | if (inputShape.GetNumDimensions() > 2U) |
| 19 | { |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 20 | unsigned int totalInputElements = inputShape.GetNumElements(); |
| 21 | unsigned int inputSize = weightsShape[1]; |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 22 | |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 23 | unsigned int batchSize = totalInputElements / inputSize; |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 24 | |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 25 | if(totalInputElements % batchSize != 0) |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 26 | { |
| 27 | throw std::runtime_error("Failed to deduce tensor shape"); |
| 28 | } |
| 29 | |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 30 | return armnn::TensorShape({batchSize, inputSize}); |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 31 | } |
| 32 | else |
| 33 | { |
| 34 | return inputShape; |
| 35 | } |
| 36 | } |
| 37 | |
FinnWilliamsArm | 7b8d2e6 | 2020-01-08 14:57:47 +0000 | [diff] [blame] | 38 | inline bool VerifyFullyConnectedShapes(const armnn::TensorShape& inputShape, |
| 39 | const armnn::TensorShape& weightsShape, |
| 40 | const armnn::TensorShape& outputShape, |
| 41 | bool transposeWeightMatrix) |
| 42 | { |
| 43 | unsigned int dimIdx = transposeWeightMatrix ? 0 : 1; |
| 44 | return (inputShape[0] == outputShape[0] && weightsShape[dimIdx] == outputShape[1]); |
| 45 | } |
| 46 | |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 47 | } |