ArmNN
 24.02
GpuFsaPooling2d.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "GpuFsaPooling2d.hpp"
7 #include "UtilsGpuFsa.hpp"
8 
10 
11 #include <arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadContext.h>
12 #include <arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.h>
13 #include <arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h>
14 #include <arm_compute/dynamic_fusion/sketch/gpu/operators/GpuOutput.h>
15 
16 using namespace arm_compute::experimental::dynamic_fusion;
17 using namespace armnn::armcomputetensorutils;
18 
19 namespace armnn
20 {
21 
23  const Pooling2dDescriptor& descriptor)
24 {
25  // Create a new workload sketch, for validation purposes
26  auto compileCtx = arm_compute::CLKernelLibrary::get().get_compile_context();
27  auto workloadContext = GpuWorkloadContext(&compileCtx);
28  GpuWorkloadSketch sketch{ &workloadContext };
29 
30  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
31  aclInputInfo.set_are_values_constant(input.IsConstant());
32  arm_compute::ITensorInfo* inputInfo = workloadContext.create_tensor_info(aclInputInfo);
33 
34  Pool2dAttributes pool2dAttributes = CreatePool2dAttributes(descriptor);
35  GpuPool2dSettings pool2dSettings{};
36 
37  return GpuPool2d::validate_op(sketch, inputInfo, pool2dAttributes, pool2dSettings);
38 }
39 
41  const TensorInfo& input,
42  const Pooling2dDescriptor& descriptor)
43 {
44  GpuWorkloadSketch* sketch = blob->sketch.get();
45  GpuWorkloadContext* workloadContext = blob->workloadContext.get();
46  std::vector<arm_compute::ITensorInfo*> inputTensorInfos = {};
47  std::vector<arm_compute::ITensorInfo*> outputTensorInfos = {};
48 
49  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
50  aclInputInfo.set_are_values_constant(input.IsConstant());
51 
52  inputTensorInfos.emplace_back(workloadContext->create_tensor_info(aclInputInfo));
53 
54  Pool2dAttributes pool2dAttributes = CreatePool2dAttributes(descriptor);
55  GpuPool2dSettings pool2dSettings{};
56 
57  // Validate operator, check status and update reasonIfUnsupported
58  arm_compute::Status aclStatus = GpuPool2d::validate_op(*sketch,
59  inputTensorInfos[0],
60  pool2dAttributes,
61  pool2dSettings);
62 
63  const bool supported = aclStatus.error_code() == arm_compute::ErrorCode::OK;
64  if (!supported)
65  {
66  throw BackendCapabilityException("\"GpuFsa\" backend failed during pooling 2d validation");
67  }
68 
69  arm_compute::ITensorInfo* addOutputInfo = GpuPool2d::create_op(*sketch,
70  inputTensorInfos[0],
71  pool2dAttributes,
72  pool2dSettings);
73 
74  // Temporary fix until fusing attempt is make for GpuFsa backend and Output layer workload is created.
75  outputTensorInfos.emplace_back(workloadContext->create_tensor_info());
76  GpuOutput::create_op(*sketch, addOutputInfo, outputTensorInfos[0]);
77 
78  // Store the TensorInfos within the blob as unique_ptrs to be used later
79  blob->inputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(inputTensorInfos);
80  blob->outputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(outputTensorInfos);
81 }
82 
83 } // namespace armnn
armnn::GpuFsaPooling2dCreateOp
void GpuFsaPooling2dCreateOp(GpuFsaPreCompiledBlob *blob, const TensorInfo &input, const Pooling2dDescriptor &descriptor)
Definition: GpuFsaPooling2d.cpp:40
armnn::GpuFsaPooling2dValidate
arm_compute::Status GpuFsaPooling2dValidate(const TensorInfo &input, const Pooling2dDescriptor &descriptor)
Definition: GpuFsaPooling2d.cpp:22
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::TensorInfo::IsConstant
bool IsConstant() const
Definition: Tensor.cpp:509
armnn::GpuFsaPreCompiledBlob::inputTensorInfos
std::unique_ptr< std::vector< arm_compute::ITensorInfo * > > inputTensorInfos
Definition: GpuFsaBackend.hpp:37
CreatePool2dAttributes
arm_compute::experimental::dynamic_fusion::Pool2dAttributes CreatePool2dAttributes(const Pooling2dDescriptor &descriptor)
Utility function used to setup an arm_compute::Pool2dAttributes object from given descriptor.
Definition: UtilsGpuFsa.cpp:45
armnn::Pooling2dDescriptor::m_DataLayout
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Definition: Descriptors.hpp:427
armnn::GpuFsaPreCompiledBlob::sketch
std::unique_ptr< arm_compute::experimental::dynamic_fusion::GpuWorkloadSketch > sketch
Definition: GpuFsaBackend.hpp:34
armnn::Status
Status
Definition: Types.hpp:42
armnn::BackendCapabilityException
Definition: Exceptions.hpp:152
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::GpuFsaPreCompiledBlob::workloadContext
std::shared_ptr< arm_compute::experimental::dynamic_fusion::GpuWorkloadContext > workloadContext
Definition: GpuFsaBackend.hpp:35
armnn::GpuFsaPreCompiledBlob
A structure which contains all the elements needed to execute a fused workload in the GpuFsa Backend.
Definition: GpuFsaBackend.hpp:32
UtilsGpuFsa.hpp
armnn::Pooling2dDescriptor
A Pooling2dDescriptor for the Pooling2dLayer.
Definition: Descriptors.hpp:371
GpuFsaPooling2d.hpp
armnn::GpuFsaPreCompiledBlob::outputTensorInfos
std::unique_ptr< std::vector< arm_compute::ITensorInfo * > > outputTensorInfos
Definition: GpuFsaBackend.hpp:38