ArmNN
 24.08
RefChannelShuffleWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
9 #include "RefWorkloadUtils.hpp"
10 #include "Profiling.hpp"
11 #include "Decoders.hpp"
12 #include "Encoders.hpp"
13 
14 namespace armnn
15 {
17 {
19 }
20 
22 {
23  WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
24  Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
25 }
26 
27 // Reference implementation for channel shuffle taken from
28 // https://android.googlesource.com/platform/frameworks/ml/+/refs/heads/master/nn/common/operations/ChannelShuffle.cpp
29 void RefChannelShuffleWorkload::Execute(std::vector<ITensorHandle*> inputs,
30  std::vector<ITensorHandle*> outputs) const
31 {
32  ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefChannelShuffleWorkload_Execute");
33 
34  const TensorInfo& inputInfo = GetTensorInfo(inputs[0]);
35  const TensorInfo& outputInfo = GetTensorInfo(outputs[0]);
36  std::unique_ptr<Decoder<float>> decoderPtr = MakeDecoder<float>(inputInfo, inputs[0]->Map());
37  Decoder<float>& decoder = *decoderPtr;
38 
39  std::unique_ptr<Encoder<float>> encoderPtr = MakeEncoder<float>(outputInfo, outputs[0]->Map());
40  Encoder<float>& encoder = *encoderPtr;
41 
42  auto getNumberOfElements = [](const TensorShape& tensorShape,uint32_t startAxis, uint32_t lastAxis)
43  {
44  uint32_t count = 1;
45  for (uint32_t i = startAxis; i < lastAxis; i++)
46  {
47  count *= tensorShape[i];
48  }
49  return count;
50  };
51  const TensorShape tensorShape = GetTensorInfo(inputs[0]).GetShape();
52  uint32_t channelsAxis = m_Data.m_Parameters.m_Axis; // channelsAxis to perform channel shuffle on
53 
54  const uint32_t numGroups = m_Data.m_Parameters.m_NumGroups;
55  const uint32_t groupSize = tensorShape[channelsAxis] / numGroups;
56 
57  uint32_t outerSize = getNumberOfElements(tensorShape, 0, channelsAxis);
58  uint32_t innerSize = getNumberOfElements(tensorShape, channelsAxis + 1, tensorShape.GetNumDimensions());
59 
60  for (uint32_t outer = 0; outer < outerSize; ++outer)
61  {
62  for (uint32_t inner = 0; inner < innerSize; ++inner)
63  {
64  uint32_t decoderStep1 = outer * tensorShape[channelsAxis] * innerSize + inner;
65  decoder += decoderStep1;
66  uint32_t encoderStep1 = outer * tensorShape[channelsAxis] * innerSize + inner;
67  encoder += encoderStep1;
68  for (uint32_t i = 0; i < groupSize; i++)
69  {
70  for (uint32_t j = 0; j < numGroups; j++, encoder += innerSize, encoderStep1 += innerSize)
71  {
72  decoder += innerSize * (i + j * groupSize);
73  float decoded = decoder.Get();
74  encoder.Set(decoded);
75  decoder -= innerSize * (i + j * groupSize);
76  }
77  }
78  decoder -= decoderStep1;
79  encoder -= encoderStep1;
80  }
81  }
82 }
83 }
armnn::Decoder< float >
RefChannelShuffleWorkload.hpp
armnn::ChannelShuffleDescriptor::m_Axis
uint32_t m_Axis
Axis to apply channel shuffle operation on.
Definition: Descriptors.hpp:1580
armnn::experimental::ExecutionData::m_Data
void * m_Data
Definition: ExecutionData.hpp:16
armnn::TensorInfo
Definition: Tensor.hpp:152
ITensorHandleFactory.hpp
Profiling.hpp
ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: RefWorkloadUtils.hpp:22
armnn::RefChannelShuffleWorkload::ExecuteAsync
void ExecuteAsync(ExecutionData &executionData) override
Definition: RefChannelShuffleWorkload.cpp:21
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::Encoder< float >
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::RefChannelShuffleWorkload::Execute
void Execute() const override
Definition: RefChannelShuffleWorkload.cpp:16
armnn::GetTensorInfo
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Definition: RefWorkloadUtils.hpp:33
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::Decoder::Get
virtual IType Get() const =0
Transpose.hpp
RefWorkloadUtils.hpp
armnn::BaseWorkload< ChannelShuffleQueueDescriptor >::m_Data
ChannelShuffleQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
Decoders.hpp
armnn::LayerType::Map
@ Map
armnn::experimental::WorkingMemDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkingMemDescriptor.hpp:20
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::experimental::WorkingMemDescriptor
Definition: WorkingMemDescriptor.hpp:18
armnn::ChannelShuffleDescriptor::m_NumGroups
uint32_t m_NumGroups
Number of groups for the channel shuffle operation.
Definition: Descriptors.hpp:1578
Encoders.hpp
armnn::experimental::WorkingMemDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkingMemDescriptor.hpp:21
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::experimental::ExecutionData
Definition: ExecutionData.hpp:14