ArmNN
 20.05
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 namespace armnn
11 {
12 
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)
22 {
23  // Perform FullyConnected implementation
24  unsigned int outputSize = rOutputShape[1];
25 
26  for (unsigned int n = 0; n < rInputShape[0]; n++)
27  {
28  for (unsigned int channelOutput = 0; channelOutput < outputSize; channelOutput++)
29  {
30  float outval = 0.f;
31 
32  for (unsigned int channelInput = 0; channelInput < K; channelInput++)
33  {
34  float weight;
35  if (transposeWeights)
36  {
37  rWeightDecoder[channelOutput * K + channelInput];
38  weight = rWeightDecoder.Get();
39  }
40  else
41  {
42  rWeightDecoder[channelInput * outputSize + channelOutput];
43  weight = rWeightDecoder.Get();
44  }
45 
46  rInputDecoder[n * K + channelInput];
47  outval += weight * rInputDecoder.Get();
48  }
49 
50  if (biasEnabled)
51  {
52  rBiasDecoder[channelOutput];
53  outval += rBiasDecoder.Get();
54  }
55 
56  rOutputEncoder[n * outputSize + channelOutput];
57  rOutputEncoder.Set(outval);
58  }
59  }
60 }
61 
62 } //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