ArmNN
 20.02
FullyConnected.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "FullyConnected.hpp"
7 
8 #include "RefWorkloadUtils.hpp"
9 
10 #include <boost/assert.hpp>
11 
12 namespace armnn
13 {
14 
15 void FullyConnected(const TensorShape& rInputShape,
16  Decoder<float>& rInputDecoder,
17  const TensorShape& rOutputShape,
18  Encoder<float>& rOutputEncoder,
19  Decoder<float>& rWeightDecoder,
20  Decoder<float>& rBiasDecoder,
21  const bool biasEnabled,
22  const unsigned int K,
23  const bool transposeWeights)
24 {
25  // Perform FullyConnected implementation
26  unsigned int outputSize = rOutputShape[1];
27 
28  for (unsigned int n = 0; n < rInputShape[0]; n++)
29  {
30  for (unsigned int channelOutput = 0; channelOutput < outputSize; channelOutput++)
31  {
32  float outval = 0.f;
33 
34  for (unsigned int channelInput = 0; channelInput < K; channelInput++)
35  {
36  float weight;
37  if (transposeWeights)
38  {
39  rWeightDecoder[channelOutput * K + channelInput];
40  weight = rWeightDecoder.Get();
41  }
42  else
43  {
44  rWeightDecoder[channelInput * outputSize + channelOutput];
45  weight = rWeightDecoder.Get();
46  }
47 
48  rInputDecoder[n * K + channelInput];
49  outval += weight * rInputDecoder.Get();
50  }
51 
52  if (biasEnabled)
53  {
54  rBiasDecoder[channelOutput];
55  outval += rBiasDecoder.Get();
56  }
57 
58  rOutputEncoder[n * outputSize + channelOutput];
59  rOutputEncoder.Set(outval);
60  }
61  }
62 }
63 
64 } //namespace armnn
virtual void Set(IType right)=0
void FullyConnected(const TensorShape &rInputShape, Decoder< float > &rInputDecoder, const TensorShape &rOutputShape, Encoder< float > &rOutputEncoder, Decoder< float > &rWeightDecoder, Decoder< float > &rBiasDecoder, const bool biasEnabled, const unsigned int K, const bool transposeWeights)
Performs a matrix multiplication and optionally adds a bias.
Copyright (c) 2020 ARM Limited.
virtual IType Get() const =0