diff options
author | David Beck <david.beck@arm.com> | 2018-09-24 13:18:27 +0100 |
---|---|---|
committer | Matthew Bentham <matthew.bentham@arm.com> | 2018-10-10 16:16:57 +0100 |
commit | b4540bef0b0327683fe8e63f727c1212800dc2a9 (patch) | |
tree | e1ea8bb6ee981640a1c469ceb556ed648ffde411 /src/backends/reference/workloads/FullyConnected.cpp | |
parent | 2d9dd36fb6bc20b370701ab15463359b9db35f18 (diff) | |
download | armnn-b4540bef0b0327683fe8e63f727c1212800dc2a9.tar.gz |
IVGCVSW-1898 : Ref backend folder structure
* Reference backend is renamed to backends/reference as per
https://confluence.arm.com/display/MLENG/Pluggable+backends
Change-Id: I27a13c274eb60995dfb459e3c49c0e2f60bcd32c
Diffstat (limited to 'src/backends/reference/workloads/FullyConnected.cpp')
-rw-r--r-- | src/backends/reference/workloads/FullyConnected.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/backends/reference/workloads/FullyConnected.cpp b/src/backends/reference/workloads/FullyConnected.cpp new file mode 100644 index 0000000000..bf5814d2ad --- /dev/null +++ b/src/backends/reference/workloads/FullyConnected.cpp @@ -0,0 +1,62 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "FullyConnected.hpp" + +#include <boost/assert.hpp> + +namespace armnn +{ + +void FullyConnected(const float* inputData, + float* outputData, + const TensorInfo& inputTensorInfo, + const TensorInfo& outputTensorInfo, + const float* weightData, + const float* biasData, + bool transposeWeights) +{ + unsigned int N = outputTensorInfo.GetShape()[1]; // Outputs Vector Size. + + BOOST_ASSERT(inputTensorInfo.GetNumDimensions() > 1); // Needs some data. + + unsigned int K = 1; // Total number of activations in the input. + for (unsigned int i = 1; i < inputTensorInfo.GetNumDimensions(); i++) + { + K *= inputTensorInfo.GetShape()[i]; + } + + for (unsigned int n = 0; n < inputTensorInfo.GetShape()[0]; n++) + { + for (unsigned int channelOutput = 0; channelOutput < N; channelOutput++) + { + float outval = 0.f; + + for (unsigned int channelInput = 0; channelInput < K; channelInput++) + { + float weight; + if (transposeWeights) + { + weight = weightData[channelOutput * K + channelInput]; + } + else + { + weight = weightData[channelInput * N + channelOutput]; + } + + outval += weight * inputData[n * K + channelInput]; + } + + if (biasData) + { + outval += biasData[channelOutput]; + } + + outputData[n * N + channelOutput] = outval; + } + } +} + +} //namespace armnn |