blob: afab88f0a8afc7d265bc138ffd11880095e855c1 [file] [log] [blame]
Matthew Sloyanb63a3112021-09-08 13:05:51 +01001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "RefConvolution3dWorkload.hpp"
7
8#include "Conv3dImpl.hpp"
9#include "RefWorkloadUtils.hpp"
10
11#include "Profiling.hpp"
12
13namespace armnn
14{
15RefConvolution3dWorkload::RefConvolution3dWorkload(
16 const Convolution3dQueueDescriptor& descriptor, const WorkloadInfo& info)
17 : BaseWorkload<Convolution3dQueueDescriptor>(descriptor, info)
18{
19 WorkloadInfo detailsInfo;
20 detailsInfo.m_InputTensorInfos = info.m_InputTensorInfos;
21 detailsInfo.m_OutputTensorInfos = info.m_OutputTensorInfos;
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010022 detailsInfo.m_WeightsTensorInfo = armnn::Optional<armnn::TensorInfo>(info.m_InputTensorInfos[1]);
Matthew Sloyanb63a3112021-09-08 13:05:51 +010023 if (descriptor.m_Parameters.m_BiasEnabled)
24 {
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010025 detailsInfo.m_BiasTensorInfo = armnn::Optional<armnn::TensorInfo>(info.m_InputTensorInfos[2]);
Matthew Sloyanb63a3112021-09-08 13:05:51 +010026 }
27
28 // Report Profiling Details
29 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("RefConvolution3dWorkload_Construct",
30 descriptor.m_Parameters,
31 detailsInfo,
32 this->GetGuid());
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010033}
Matthew Sloyanb63a3112021-09-08 13:05:51 +010034
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010035void RefConvolution3dWorkload::PostAllocationConfigure()
36{
37 PostAllocationConfigure(m_Data.m_Inputs, m_Data.m_Outputs);
38}
Matthew Sloyanb63a3112021-09-08 13:05:51 +010039
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010040void RefConvolution3dWorkload::PostAllocationConfigure(std::vector<ITensorHandle*> inputs,
41 std::vector<ITensorHandle*> outputs)
42{
43 IgnoreUnused(outputs);
44 const TensorInfo& rFilterInfo = GetTensorInfo(inputs[1]);
Matthew Sloyanb63a3112021-09-08 13:05:51 +010045 m_FilterShape = rFilterInfo.GetShape();
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010046 m_FilterDecoder = MakeDecoder<float>(rFilterInfo);
Matthew Sloyanb63a3112021-09-08 13:05:51 +010047
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010048 if (m_Data.m_Parameters.m_BiasEnabled)
Matthew Sloyanb63a3112021-09-08 13:05:51 +010049 {
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010050 const TensorInfo& biasInfo = GetTensorInfo(inputs[2]);
51 m_BiasDecoder = MakeDecoder<float>(biasInfo);
Matthew Sloyanb63a3112021-09-08 13:05:51 +010052 }
53}
54
55void RefConvolution3dWorkload::Execute() const
56{
57 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
58}
59
60void RefConvolution3dWorkload::ExecuteAsync(WorkingMemDescriptor& workingMemDescriptor)
61{
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010062 PostAllocationConfigure(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
63
Matthew Sloyanb63a3112021-09-08 13:05:51 +010064 Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
65}
66
67void RefConvolution3dWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
68{
69 ARMNN_SCOPED_PROFILING_EVENT_GUID(Compute::CpuRef, "RefConvolution3dWorkload_Execute", this->GetGuid());
70
71 std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]), inputs[0]->Map());
72 std::unique_ptr<Encoder<float>> outputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]), outputs[0]->Map());
73
74 const TensorShape& inputShape = GetTensorInfo(inputs[0]).GetShape();
75 const TensorShape& outputShape = GetTensorInfo(outputs[0]).GetShape();
76
Matthew Sloyan5d7b0a32021-10-18 13:07:49 +010077 m_FilterDecoder->Reset(inputs[1]->Map());
78 if (m_Data.m_Parameters.m_BiasEnabled)
79 {
80 m_BiasDecoder->Reset(inputs[2]->Map());
81 }
82
Matthew Sloyanb63a3112021-09-08 13:05:51 +010083 Convolve3d(inputShape, *inputDecoder, outputShape, *outputEncoder, m_FilterShape,
84 *m_FilterDecoder, m_Data.m_Parameters.m_BiasEnabled, m_BiasDecoder.get(),
85 m_Data.m_Parameters.m_DataLayout,
86 m_Data.m_Parameters.m_PadTop, m_Data.m_Parameters.m_PadLeft, m_Data.m_Parameters.m_PadFront,
87 m_Data.m_Parameters.m_StrideX, m_Data.m_Parameters.m_StrideY, m_Data.m_Parameters.m_StrideZ,
88 m_Data.m_Parameters.m_DilationX, m_Data.m_Parameters.m_DilationY, m_Data.m_Parameters.m_DilationZ);
89}
90
91} //namespace armnn