ArmNN
 22.05.01
ClChannelShuffleWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "ClWorkloadUtils.hpp"
8 
10 
12 
13 #include <cl/ClTensorHandle.hpp>
14 
15 using namespace armnn::armcomputetensorutils;
16 
17 namespace armnn
18 {
19 
21  const TensorInfo& output,
22  const ChannelShuffleDescriptor& descriptor)
23 {
24  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
25  arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
26 
27  // In Arm NN and in NNAPI, channel shuffle implementation is datalayout agnostic and it has axis as a parameter.
28  // The channel shuffle Implementation for Neon is dependent on datalayout and does not have axis as a parameter,
29  // it only supports channel shuffle for 4D tensors in dimension C (1 or 3).
30  arm_compute::DataLayout aclDataLayout;
31  if (input.GetNumDimensions() == 4)
32  {
33  switch (descriptor.m_Axis)
34  {
35  case 1:
36  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NCHW);
37  break;
38  case 3:
39  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NHWC);
40  break;
41  default:
42  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported axis"};
43  }
44  aclInputInfo.set_data_layout(aclDataLayout);
45  aclOutputInfo.set_data_layout(aclDataLayout);
46  return arm_compute::CLChannelShuffleLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_NumGroups);
47  }
48  else
49  {
50  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported number of dimensions"};
51  }
52 }
53 
55  const WorkloadInfo& info,
56  const arm_compute::CLCompileContext& clCompileContext)
58 {
59  // Report Profiling Details
60  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClChannelShufflenWorkload_Construct",
61  descriptor.m_Parameters,
62  info,
63  this->GetGuid());
64 
65  m_Data.ValidateInputsOutputs("ClChannelShuffleWorkload", 1, 1);
66 
67  arm_compute::ICLTensor& input = PolymorphicDowncast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
68  arm_compute::ICLTensor& output = PolymorphicDowncast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
69 
70  // In Arm NN and in NNAPI, channel shuffle implementation is datalayout agnostic and it has axis as a parameter.
71  // The channel shuffle Implementation for Neon is dependent on datalayout and does not have axis as a parameter,
72  // it only supports channel shuffle for 4D tensors in dimension C (1 or 3).
73  arm_compute::DataLayout aclDataLayout;
74  switch (descriptor.m_Parameters.m_Axis)
75  {
76  case 1:
77  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NCHW);
78  break;
79  case 3:
80  aclDataLayout = ConvertDataLayout(armnn::DataLayout::NHWC);
81  break;
82  default:
83  ARMNN_ASSERT_MSG(false, "Unsupported axis");
84  break;
85  }
86  input.info()->set_data_layout(aclDataLayout);
87  output.info()->set_data_layout(aclDataLayout);
88 
89  {
90  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClChannelShuffleWorkload_configure");
91  m_ChannelShuffleLayer.configure(clCompileContext, &input, &output, descriptor.m_Parameters.m_NumGroups);
92  }
93 }
94 
96 {
97  ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClChannelShuffleWorkload_Execute", this->GetGuid());
98  RunClFunction(m_ChannelShuffleLayer, CHECK_LOCATION());
99 }
100 
101 } // namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_CL_GUID(name, guid)
DataLayout
Definition: Types.hpp:62
ClChannelShuffleWorkload(const ChannelShuffleQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:59
virtual void Execute() const override
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2021 ARM Limited and Contributors.
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
arm_compute::Status ClChannelShuffleValidate(const TensorInfo &input, const TensorInfo &output, const ChannelShuffleDescriptor &descriptor)
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
Status
enumeration
Definition: Types.hpp:42
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
uint32_t m_NumGroups
Number of groups for the channel shuffle operation.
std::vector< ITensorHandle * > m_Outputs
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
uint32_t m_Axis
Axis to apply channel shuffle operation on.
Contains information about TensorInfos of a layer.
std::vector< ITensorHandle * > m_Inputs
A ChannelShuffleDescriptor for the ChannelShuffle operator.
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195