diff options
author | Simon Obute <simon.obute@arm.com> | 2021-09-03 15:50:13 +0100 |
---|---|---|
committer | Teresa Charlin <teresa.charlinreyes@arm.com> | 2021-09-24 16:06:30 +0100 |
commit | 51f67776a695c217a32596af806afeeb080f5528 (patch) | |
tree | 33ccfd87ba365bcc6fc86d5a2181991a130b3061 /src/backends/reference/workloads/RefChannelShuffleWorkload.cpp | |
parent | f10b15a8946f39bdf3f60cebc59d2963069eedca (diff) | |
download | armnn-51f67776a695c217a32596af806afeeb080f5528.tar.gz |
IVGCVSW-3705 Add Channel Shuffle Front end and Ref Implementation
* Add front end
* Add reference workload
* Add unit tests
* Add Serializer and Deserializer
* Update ArmNN Versioning
Signed-off-by: Simon Obute <simon.obute@arm.com>
Change-Id: I9ac1f953af3974382eac8e8d62d794d2344e8f47
Diffstat (limited to 'src/backends/reference/workloads/RefChannelShuffleWorkload.cpp')
-rw-r--r-- | src/backends/reference/workloads/RefChannelShuffleWorkload.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/backends/reference/workloads/RefChannelShuffleWorkload.cpp b/src/backends/reference/workloads/RefChannelShuffleWorkload.cpp new file mode 100644 index 0000000000..6571715c63 --- /dev/null +++ b/src/backends/reference/workloads/RefChannelShuffleWorkload.cpp @@ -0,0 +1,83 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <backendsCommon/test/DataTypeUtils.hpp> +#include <armnn/backends/ITensorHandleFactory.hpp> +#include <armnnUtils/Transpose.hpp> +#include "RefChannelShuffleWorkload.hpp" +#include "RefWorkloadUtils.hpp" +#include "Profiling.hpp" +#include "Decoders.hpp" +#include "Encoders.hpp" + +namespace armnn +{ +void RefChannelShuffleWorkload::Execute() const +{ + Execute(m_Data.m_Inputs, m_Data.m_Outputs); +} + +void RefChannelShuffleWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) +{ + Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); +} + +// Reference implementation for channel shuffle taken from +// https://android.googlesource.com/platform/frameworks/ml/+/refs/heads/master/nn/common/operations/ChannelShuffle.cpp +void RefChannelShuffleWorkload::Execute(std::vector<ITensorHandle*> inputs, + std::vector<ITensorHandle*> outputs) const +{ + ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefChannelShuffleWorkload_Execute"); + + const TensorInfo& inputInfo = GetTensorInfo(inputs[0]); + const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); + std::unique_ptr<Decoder<float>> decoderPtr = MakeDecoder<float>(inputInfo, inputs[0]->Map()); + Decoder<float>& decoder = *decoderPtr; + + std::unique_ptr<Encoder<float>> encoderPtr = MakeEncoder<float>(outputInfo, outputs[0]->Map()); + Encoder<float>& encoder = *encoderPtr; + + auto getNumberOfElements = [](const TensorShape& tensorShape,uint32_t startAxis, uint32_t lastAxis) + { + uint32_t count = 1; + for (uint32_t i = startAxis; i < lastAxis; i++) + { + count *= tensorShape[i]; + } + return count; + }; + const TensorShape tensorShape = GetTensorInfo(inputs[0]).GetShape(); + uint32_t channelsAxis = m_Data.m_Parameters.m_Axis; // channelsAxis to perform channel shuffle on + + const uint32_t numGroups = m_Data.m_Parameters.m_NumGroups; + const uint32_t groupSize = tensorShape[channelsAxis] / numGroups; + + uint32_t outerSize = getNumberOfElements(tensorShape, 0, channelsAxis); + uint32_t innerSize = getNumberOfElements(tensorShape, channelsAxis + 1, tensorShape.GetNumDimensions()); + + for (uint32_t outer = 0; outer < outerSize; ++outer) + { + for (uint32_t inner = 0; inner < innerSize; ++inner) + { + uint32_t decoderStep1 = outer * tensorShape[channelsAxis] * innerSize + inner; + decoder += decoderStep1; + uint32_t encoderStep1 = outer * tensorShape[channelsAxis] * innerSize + inner; + encoder += encoderStep1; + for (uint32_t i = 0; i < groupSize; i++) + { + for (uint32_t j = 0; j < numGroups; j++, encoder += innerSize, encoderStep1 += innerSize) + { + decoder += innerSize * (i + j * groupSize); + float decoded = decoder.Get(); + encoder.Set(decoded); + decoder -= innerSize * (i + j * groupSize); + } + } + decoder -= decoderStep1; + encoder -= encoderStep1; + } + } +} +}
\ No newline at end of file |