Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 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> |
| 15 | #include <backendsCommon/TensorHandle.hpp> |
| 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 | { |
| 38 | ARMNN_ASSERT(biases.has_value()); |
| 39 | aclBiasesInfo = BuildArmComputeTensorInfo(biases.value(), descriptor.m_DataLayout); |
| 40 | optionalAclBiasesInfo = &aclBiasesInfo; |
| 41 | } |
| 42 | |
| 43 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
| 44 | |
| 45 | const arm_compute::Conv3dInfo aclConv3DInfo = ComputeConv3DInfo(descriptor, |
| 46 | isFastMathEnabled, |
| 47 | activationDescriptor); |
| 48 | |
| 49 | return arm_compute::CLConv3D::validate(&aclInputInfo, |
| 50 | &aclWeightsInfo, |
| 51 | optionalAclBiasesInfo, |
| 52 | &aclOutputInfo, |
| 53 | aclConv3DInfo); |
| 54 | } |
| 55 | |
| 56 | ClConvolution3dWorkload::ClConvolution3dWorkload(const Convolution3dQueueDescriptor& descriptor, |
| 57 | const WorkloadInfo& info, |
| 58 | std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager, |
| 59 | const arm_compute::CLCompileContext& clCompileContext, |
| 60 | const bool isFastMathEnabled) |
| 61 | : BaseWorkload<Convolution3dQueueDescriptor>(descriptor, info) |
| 62 | , m_ConvolutionLayer() |
| 63 | { |
| 64 | IgnoreUnused(memoryManager); |
| 65 | |
| 66 | uint32_t numInputs = m_Data.m_Parameters.m_BiasEnabled ? 3: 2; |
| 67 | m_Data.ValidateInputsOutputs("ClConvolution3dWorkload", numInputs, 1); |
| 68 | |
| 69 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 70 | arm_compute::ICLTensor& weights = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor(); |
| 71 | arm_compute::ICLTensor* biasesPtr = nullptr; |
| 72 | if (m_Data.m_Parameters.m_BiasEnabled) |
| 73 | { |
| 74 | biasesPtr = &static_cast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor(); |
| 75 | } |
| 76 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 77 | |
| 78 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 79 | input.info()->set_data_layout(aclDataLayout); |
| 80 | weights.info()->set_data_layout(aclDataLayout); |
| 81 | output.info()->set_data_layout(aclDataLayout); |
| 82 | |
| 83 | const arm_compute::Conv3dInfo aclConv3DInfo = ComputeConv3DInfo(descriptor, |
| 84 | isFastMathEnabled); |
| 85 | |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame^] | 86 | { |
| 87 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClConvolution3dWorkload_configure"); |
| 88 | m_ConvolutionLayer.configure(clCompileContext, |
| 89 | &input, |
| 90 | &weights, |
| 91 | biasesPtr, |
| 92 | &output, |
| 93 | aclConv3DInfo); |
| 94 | } |
Teresa Charlin | 615ad6c | 2021-10-26 12:22:20 +0100 | [diff] [blame] | 95 | // Add details for profiling output |
| 96 | WorkloadInfo detailsInfo; |
| 97 | |
| 98 | detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos; |
| 99 | detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos; |
| 100 | |
| 101 | // Report Profiling Details |
| 102 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClConvolution3dWorkload_Construct", |
| 103 | descriptor.m_Parameters, |
| 104 | detailsInfo, |
| 105 | this->GetGuid()); |
| 106 | |
| 107 | // Force Compute Library to perform the necessary copying and reshaping, after which |
| 108 | // delete all the input tensors that will no longer be needed |
| 109 | m_ConvolutionLayer.prepare(); |
| 110 | } |
| 111 | |
| 112 | void ClConvolution3dWorkload::Execute() const |
| 113 | { |
| 114 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConvolution3dWorkload_Execute", this->GetGuid()); |
| 115 | RunClFunction(m_ConvolutionLayer, CHECK_LOCATION()); |
| 116 | } |
| 117 | |
| 118 | } //namespace armnn |