• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ClPadWorkload.hpp"
7 
8 #include <cl/ClTensorHandle.hpp>
9 #include <aclCommon/ArmComputeUtils.hpp>
10 #include <aclCommon/ArmComputeTensorUtils.hpp>
11 #include <arm_compute/core/Types.h>
12 
13 #include "ClWorkloadUtils.hpp"
14 
15 namespace armnn
16 {
17 using namespace armcomputetensorutils;
18 
ClPadWorkload(const PadQueueDescriptor & descriptor,const WorkloadInfo & info,const arm_compute::CLCompileContext & clCompileContext)19 ClPadWorkload::ClPadWorkload(const PadQueueDescriptor& descriptor,
20                              const WorkloadInfo& info,
21                              const arm_compute::CLCompileContext& clCompileContext)
22     : ClBaseWorkload<PadQueueDescriptor>(descriptor, info)
23 {
24     // Report Profiling Details
25     ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClPadWorkload_Construct",
26                                          descriptor.m_Parameters,
27                                          info,
28                                          this->GetGuid());
29 
30     this->m_Data.ValidateInputsOutputs("ClPadWorkload", 1, 1);
31 
32     arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(this->m_Data.m_Inputs[0])->GetTensor();
33     arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(this->m_Data.m_Outputs[0])->GetTensor();
34 
35     std::vector<std::pair<unsigned int, unsigned int>> reversed_PadList(descriptor.m_Parameters.m_PadList.size());
36 
37     std::reverse_copy(std::begin(descriptor.m_Parameters.m_PadList),
38             std::end(descriptor.m_Parameters.m_PadList),
39             std::begin(reversed_PadList));
40 
41     arm_compute::PaddingList padList = static_cast<arm_compute::PaddingList>(reversed_PadList);
42 
43     arm_compute::PixelValue pixelValue = GetPixelValue(input.info(), descriptor.m_Parameters.m_PadValue);
44 
45     {
46         ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClPadWorkload_configure");
47         m_Layer.configure(clCompileContext,
48                           &input,
49                           &output,
50                           padList,
51                           pixelValue,
52                           ConvertPaddingModeToAcl(descriptor.m_Parameters.m_PaddingMode));
53     }
54 }
55 
Execute() const56 void ClPadWorkload::Execute() const
57 {
58     ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClPadWorkload_Execute", this->GetGuid());
59     RunClFunction(m_Layer, CHECK_LOCATION());
60 }
61 
ClPadValidate(const TensorInfo & input,const TensorInfo & output,const PadDescriptor & descriptor)62 arm_compute::Status ClPadValidate(const TensorInfo& input,
63                                   const TensorInfo& output,
64                                   const PadDescriptor& descriptor)
65 {
66     const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
67     const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
68 
69     std::vector<std::pair<unsigned int, unsigned int>> reversed_PadList(descriptor.m_PadList.size());
70 
71     std::reverse_copy(std::begin(descriptor.m_PadList),
72                       std::end(descriptor.m_PadList),
73                       std::begin(reversed_PadList));
74 
75     arm_compute::PaddingList padList = static_cast<arm_compute::PaddingList>(reversed_PadList);
76 
77     // PixelValue is currently unused when validating, but it's required to pass in PaddingMode.
78     arm_compute::PixelValue pixelValue = GetPixelValue(&aclInputInfo, descriptor.m_PadValue);
79     const arm_compute::Status aclStatus =
80             arm_compute::CLPadLayer::validate(&aclInputInfo,
81                                               &aclOutputInfo,
82                                               padList,
83                                               pixelValue,
84                                               ConvertPaddingModeToAcl(descriptor.m_PaddingMode));
85 
86     return aclStatus;
87 }
88 
89 } // namespace armnn
90