Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include "FullyConnected.hpp" |
| 7 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 8 | #include "RefWorkloadUtils.hpp" |
| 9 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | namespace armnn |
| 11 | { |
| 12 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 13 | void FullyConnected(const TensorShape& rInputShape, |
| 14 | Decoder<float>& rInputDecoder, |
| 15 | const TensorShape& rOutputShape, |
| 16 | Encoder<float>& rOutputEncoder, |
| 17 | Decoder<float>& rWeightDecoder, |
| 18 | Decoder<float>& rBiasDecoder, |
| 19 | const bool biasEnabled, |
| 20 | const unsigned int K, |
| 21 | const bool transposeWeights) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 22 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 23 | // Perform FullyConnected implementation |
| 24 | unsigned int outputSize = rOutputShape[1]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 26 | for (unsigned int n = 0; n < rInputShape[0]; n++) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 27 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 28 | for (unsigned int channelOutput = 0; channelOutput < outputSize; channelOutput++) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 29 | { |
| 30 | float outval = 0.f; |
| 31 | |
| 32 | for (unsigned int channelInput = 0; channelInput < K; channelInput++) |
| 33 | { |
| 34 | float weight; |
| 35 | if (transposeWeights) |
| 36 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 37 | rWeightDecoder[channelOutput * K + channelInput]; |
| 38 | weight = rWeightDecoder.Get(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 39 | } |
| 40 | else |
| 41 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 42 | rWeightDecoder[channelInput * outputSize + channelOutput]; |
| 43 | weight = rWeightDecoder.Get(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 46 | rInputDecoder[n * K + channelInput]; |
| 47 | outval += weight * rInputDecoder.Get(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 50 | if (biasEnabled) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 51 | { |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 52 | rBiasDecoder[channelOutput]; |
| 53 | outval += rBiasDecoder.Get(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 56 | rOutputEncoder[n * outputSize + channelOutput]; |
| 57 | rOutputEncoder.Set(outval); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | } //namespace armnn |