ArmNN
 24.08
NeonChannelShuffleWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "NeonWorkloadUtils.hpp"
8 
11 
13 
14 namespace armnn
15 {
16 
18  const TensorInfo& output,
19  const ChannelShuffleDescriptor& descriptor)
20 {
21  arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input);
22  arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
23 
24  // In Arm NN and in NNAPI, channel shuffle implementation is datalayout agnostic and it has axis as a parameter.
25  // The channel shuffle Implementation for Neon is dependent on datalayout and does not have axis as a parameter,
26  // it only supports channel shuffle for 4D tensors in dimension C (1 or 3).
27  arm_compute::DataLayout aclDataLayout;
28  if (input.GetNumDimensions() == 4)
29  {
30  switch (descriptor.m_Axis)
31  {
32  case 1:
33  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NCHW);
34  break;
35  case 3:
36  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NHWC);
37  break;
38  default:
39  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported axis"};
40  }
41  aclInputInfo.set_data_layout(aclDataLayout);
42  aclOutputInfo.set_data_layout(aclDataLayout);
43  return arm_compute::NEChannelShuffleLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_NumGroups);
44  }
45  else
46  {
47  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported number of dimensions"};
48  }
49 }
50 
52  const WorkloadInfo& info)
54 {
55  // Report Profiling Details
56  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonChannelShufflenWorkload_Construct",
57  descriptor.m_Parameters,
58  info,
59  this->GetGuid());
60 
61  m_Data.ValidateInputsOutputs("NeonChannelShuffleWorkload", 1, 1);
62 
63  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
64  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
65 
66  // In Arm NN and in NNAPI, channel shuffle implementation is datalayout agnostic and it has axis as a parameter.
67  // The channel shuffle Implementation for Neon is dependent on datalayout and does not have axis as a parameter,
68  // it only supports channel shuffle for 4D tensors in dimension C (1 or 3).
69  arm_compute::DataLayout aclDataLayout;
70  switch (descriptor.m_Parameters.m_Axis)
71  {
72  case 1:
73  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NCHW);
74  break;
75  case 3:
76  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NHWC);
77  break;
78  default:
79  throw InvalidArgumentException("Value for axis: " + std::to_string(descriptor.m_Parameters.m_Axis) +
80  " is not valid");
81  break;
82  }
83  input.info()->set_data_layout(aclDataLayout);
84  output.info()->set_data_layout(aclDataLayout);
85 
86  m_ChannelShuffleLayer.configure(&input, &output, descriptor.m_Parameters.m_NumGroups);
87 }
88 
90 {
91  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonChannelShuffleWorkload_Execute");
92  m_ChannelShuffleLayer.run();
93 }
94 
95 } // namespace armnn
armnn::ChannelShuffleDescriptor::m_Axis
uint32_t m_Axis
Axis to apply channel shuffle operation on.
Definition: Descriptors.hpp:1580
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
armnn::DataLayout::NHWC
@ NHWC
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:447
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::NeonChannelShuffleWorkload::Execute
virtual void Execute() const override
Definition: NeonChannelShuffleWorkload.cpp:89
armnn::TensorInfo::GetNumDimensions
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:197
armnn::ChannelShuffleDescriptor
A ChannelShuffleDescriptor for the ChannelShuffle operator.
Definition: Descriptors.hpp:1562
NeonChannelShuffleWorkload.hpp
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::NeonChannelShuffleWorkload::NeonChannelShuffleWorkload
NeonChannelShuffleWorkload(const ChannelShuffleQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: NeonChannelShuffleWorkload.cpp:51
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
ArmComputeTensorHandle.hpp
ARMNN_REPORT_PROFILING_WORKLOAD_DESC
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< ChannelShuffleQueueDescriptor >::m_Data
ChannelShuffleQueueDescriptor m_Data
Definition: Workload.hpp:89
NeonWorkloadUtils.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::ChannelShuffleDescriptor::m_NumGroups
uint32_t m_NumGroups
Number of groups for the channel shuffle operation.
Definition: Descriptors.hpp:1578
armnn::NeonChannelShuffleValidate
arm_compute::Status NeonChannelShuffleValidate(const TensorInfo &input, const TensorInfo &output, const ChannelShuffleDescriptor &descriptor)
Definition: NeonChannelShuffleWorkload.cpp:17
ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: NeonWorkloadUtils.hpp:33
armnn::ChannelShuffleQueueDescriptor
Definition: WorkloadData.hpp:748
armnn::NeonBaseWorkload
Definition: NeonBaseWorkload.hpp:13
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::DataLayout::NCHW
@ NCHW