keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClStridedSliceWorkload.hpp" |
| 7 | |
| 8 | #include "ClWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <aclCommon/ArmComputeUtils.hpp> |
| 11 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 12 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 13 | #include <backendsCommon/TensorHandle.hpp> |
Francis Murtagh | ec33a91 | 2019-11-05 14:26:23 +0000 | [diff] [blame] | 14 | #include <backendsCommon/WorkloadUtils.hpp> |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 15 | |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 16 | #include <armnn/utility/NumericCast.hpp> |
| 17 | |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 18 | #include <cl/ClLayerSupport.hpp> |
| 19 | #include <cl/ClTensorHandle.hpp> |
| 20 | #include <cl/ClLayerSupport.hpp> |
| 21 | |
| 22 | namespace armnn |
| 23 | { |
| 24 | |
| 25 | using namespace armcomputetensorutils; |
| 26 | |
| 27 | arm_compute::Status ClStridedSliceWorkloadValidate(const TensorInfo& input, |
| 28 | const TensorInfo& output, |
| 29 | const StridedSliceDescriptor& descriptor) |
| 30 | { |
| 31 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 32 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 33 | |
| 34 | arm_compute::Coordinates starts; |
| 35 | arm_compute::Coordinates ends; |
| 36 | arm_compute::Coordinates strides; |
| 37 | |
| 38 | std::tie(starts, ends, strides) = SetClStridedSliceData(descriptor.m_Begin, descriptor.m_End, descriptor.m_Stride); |
| 39 | |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 40 | auto numDimensions = armnn::numeric_cast<int>(input.GetNumDimensions()); |
Francis Murtagh | ec33a91 | 2019-11-05 14:26:23 +0000 | [diff] [blame] | 41 | int32_t begin_mask = ConvertMaskToACLFormat(descriptor.m_BeginMask, numDimensions); |
| 42 | int32_t end_mask = ConvertMaskToACLFormat(descriptor.m_EndMask, numDimensions); |
| 43 | int32_t shrink_axis_mask = ConvertMaskToACLFormat(descriptor.m_ShrinkAxisMask, numDimensions); |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 44 | |
| 45 | return arm_compute::CLStridedSlice::validate(&aclInputInfo, |
| 46 | &aclOutputInfo, |
| 47 | starts, |
| 48 | ends, |
| 49 | strides, |
| 50 | begin_mask, |
| 51 | end_mask, |
| 52 | shrink_axis_mask); |
| 53 | } |
| 54 | |
| 55 | ClStridedSliceWorkload::ClStridedSliceWorkload(const StridedSliceQueueDescriptor& descriptor, |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 56 | const WorkloadInfo& info, |
| 57 | const arm_compute::CLCompileContext& clCompileContext) |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 58 | : BaseWorkload<StridedSliceQueueDescriptor>(descriptor, info) |
| 59 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 60 | // Report Profiling Details |
| 61 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClStridedSliceWorkload_Construct", |
| 62 | descriptor.m_Parameters, |
| 63 | info, |
| 64 | this->GetGuid()); |
| 65 | |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 66 | m_Data.ValidateInputsOutputs("ClStridedSliceWorkload", 1, 1); |
| 67 | |
| 68 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 69 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 70 | |
| 71 | arm_compute::Coordinates starts; |
| 72 | arm_compute::Coordinates ends; |
| 73 | arm_compute::Coordinates strides; |
| 74 | |
| 75 | std::tie(starts, ends, strides) = SetClStridedSliceData(m_Data.m_Parameters.m_Begin, |
| 76 | m_Data.m_Parameters.m_End, |
| 77 | m_Data.m_Parameters.m_Stride); |
| 78 | |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 79 | auto numDimensions = armnn::numeric_cast<int>(info.m_InputTensorInfos[0].GetNumDimensions()); |
Francis Murtagh | ec33a91 | 2019-11-05 14:26:23 +0000 | [diff] [blame] | 80 | int32_t begin_mask = ConvertMaskToACLFormat(m_Data.m_Parameters.m_BeginMask, numDimensions); |
| 81 | int32_t end_mask = ConvertMaskToACLFormat(m_Data.m_Parameters.m_EndMask, numDimensions); |
| 82 | int32_t shrink_axis_mask = ConvertMaskToACLFormat(m_Data.m_Parameters.m_ShrinkAxisMask, numDimensions); |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 83 | |
| 84 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 85 | input.info()->set_data_layout(aclDataLayout); |
| 86 | output.info()->set_data_layout(aclDataLayout); |
| 87 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 88 | m_StridedSliceLayer.configure(clCompileContext, |
| 89 | &input, |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 90 | &output, |
| 91 | starts, |
| 92 | ends, |
| 93 | strides, |
| 94 | begin_mask, |
| 95 | end_mask, |
| 96 | shrink_axis_mask); |
| 97 | } |
| 98 | |
| 99 | void ClStridedSliceWorkload::Execute() const |
| 100 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 101 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClStridedSliceWorkload_Execute", this->GetGuid()); |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 102 | RunClFunction(m_StridedSliceLayer, CHECK_LOCATION()); |
| 103 | } |
| 104 | |
| 105 | } //namespace armnn |