Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 1 | // |
Mike Kelly | 7cbe781 | 2023-07-25 17:37:33 +0100 | [diff] [blame] | 2 | // Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. |
Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClConvolution3dWorkload.hpp" |
| 7 | |
| 8 | #include "ClWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <cl/ClLayerSupport.hpp> |
| 11 | #include <cl/ClTensorHandle.hpp> |
| 12 | #include <cl/ClLayerSupport.hpp> |
| 13 | #include <aclCommon/ArmComputeUtils.hpp> |
| 14 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 15 | #include <armnn/backends/TensorHandle.hpp> |
Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 16 | |
| 17 | #include <arm_compute/runtime/CL/functions/CLConv3D.h> |
| 18 | |
| 19 | namespace armnn |
| 20 | { |
| 21 | using namespace armcomputetensorutils; |
| 22 | |
| 23 | arm_compute::Status ClConvolution3dWorkloadValidate(const TensorInfo& input, |
| 24 | const TensorInfo& output, |
| 25 | const Convolution3dDescriptor& descriptor, |
| 26 | const TensorInfo& weights, |
| 27 | const Optional<TensorInfo>& biases, |
| 28 | bool isFastMathEnabled, |
| 29 | const ActivationDescriptor* activationDescriptor) |
| 30 | { |
| 31 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 32 | const arm_compute::TensorInfo aclWeightsInfo = BuildArmComputeTensorInfo(weights, descriptor.m_DataLayout); |
| 33 | |
| 34 | arm_compute::TensorInfo aclBiasesInfo; |
| 35 | arm_compute::TensorInfo* optionalAclBiasesInfo = nullptr; |
| 36 | if (descriptor.m_BiasEnabled) |
| 37 | { |
Kevin May | 8eece0a | 2023-06-06 17:19:06 +0100 | [diff] [blame] | 38 | if (!biases.has_value()) |
| 39 | { |
| 40 | return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, |
| 41 | "ArmNN ClConvolution3dWorkload has empty bias value."}; |
| 42 | } |
Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 43 | aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout); |
| 44 | optionalAclBiasesInfo = &aclBiasesInfo; |
| 45 | } |
| 46 | |
| 47 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 48 | |
| 49 | const arm_compute::Conv3dInfo aclConv3DInfo = ComputeConv3DInfo(descriptor, |
| 50 | isFastMathEnabled, |
| 51 | activationDescriptor); |
| 52 | |
| 53 | return arm_compute::CLConv3D::validate(&aclInputInfo, |
| 54 | &aclWeightsInfo, |
| 55 | optionalAclBiasesInfo, |
| 56 | &aclOutputInfo, |
| 57 | aclConv3DInfo); |
| 58 | } |
| 59 | |
| 60 | ClConvolution3dWorkload::ClConvolution3dWorkload(const Convolution3dQueueDescriptor& descriptor, |
| 61 | const WorkloadInfo& info, |
| 62 | std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager, |
| 63 | const arm_compute::CLCompileContext& clCompileContext, |
| 64 | const bool isFastMathEnabled) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 65 | : ClBaseWorkload<Convolution3dQueueDescriptor>(descriptor, info) |
Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 66 | , m_ConvolutionLayer() |
| 67 | { |
| 68 | IgnoreUnused(memoryManager); |
| 69 | |
| 70 | uint32_t numInputs = m_Data.m_Parameters.m_BiasEnabled ? 3: 2; |
| 71 | m_Data.ValidateInputsOutputs("ClConvolution3dWorkload", numInputs, 1); |
| 72 | |
| 73 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 74 | arm_compute::ICLTensor& weights = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor(); |
| 75 | arm_compute::ICLTensor* biasesPtr = nullptr; |
| 76 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 77 | { |
| 78 | biasesPtr = &static_cast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor(); |
| 79 | } |
| 80 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 81 | |
| 82 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 83 | input.info()->set_data_layout(aclDataLayout); |
| 84 | weights.info()->set_data_layout(aclDataLayout); |
| 85 | output.info()->set_data_layout(aclDataLayout); |
| 86 | |
| 87 | const arm_compute::Conv3dInfo aclConv3DInfo = ComputeConv3DInfo(descriptor, |
| 88 | isFastMathEnabled); |
| 89 | |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 90 | { |
Mike Kelly | 7cbe781 | 2023-07-25 17:37:33 +0100 | [diff] [blame] | 91 | ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConvolution3dWorkload_configure"); |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 92 | m_ConvolutionLayer.configure(clCompileContext, |
| 93 | &input, |
| 94 | &weights, |
| 95 | biasesPtr, |
| 96 | &output, |
| 97 | aclConv3DInfo); |
| 98 | } |
Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 99 | // Add details for profiling output |
| 100 | WorkloadInfo detailsInfo; |
| 101 | |
| 102 | detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos; |
| 103 | detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos; |
| 104 | |
| 105 | // Report Profiling Details |
| 106 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClConvolution3dWorkload_Construct", |
| 107 | descriptor.m_Parameters, |
| 108 | detailsInfo, |
| 109 | this->GetGuid()); |
| 110 | |
| 111 | // Force Compute Library to perform the necessary copying and reshaping, after which |
| 112 | // delete all the input tensors that will no longer be needed |
| 113 | m_ConvolutionLayer.prepare(); |
| 114 | } |
| 115 | |
| 116 | void ClConvolution3dWorkload::Execute() const |
| 117 | { |
Mike Kelly | 7cbe781 | 2023-07-25 17:37:33 +0100 | [diff] [blame] | 118 | ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConvolution3dWorkload_Execute"); |
Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 119 | RunClFunction(m_ConvolutionLayer, CHECK_LOCATION()); |
| 120 | } |
| 121 | |
| 122 | } //namespace armnn |