ArmNN
 24.08
GpuFsaResize.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 "GpuFsaResize.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/GpuResize.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 ResizeDescriptor& 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  ResizeAttributes resizeAttributes = CreateResizeAttributes(descriptor);
35 
36  return GpuResize::validate_op(sketch, inputInfo, resizeAttributes);
37 }
38 
40  const TensorInfo& input,
41  const ResizeDescriptor& descriptor)
42 {
43  GpuWorkloadSketch* sketch = blob->sketch.get();
44  GpuWorkloadContext* workloadContext = blob->workloadContext.get();
45  std::vector<arm_compute::ITensorInfo*> inputTensorInfos = {};
46  std::vector<arm_compute::ITensorInfo*> outputTensorInfos = {};
47 
48  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
49  aclInputInfo.set_are_values_constant(input.IsConstant());
50 
51  inputTensorInfos.emplace_back(workloadContext->create_tensor_info(aclInputInfo));
52 
53  ResizeAttributes resizeAttributes = CreateResizeAttributes(descriptor);
54 
55  // Validate operator, check status and update reasonIfUnsupported
56  arm_compute::Status aclStatus = GpuResize::validate_op(*sketch,
57  inputTensorInfos[0],
58  resizeAttributes);
59 
60  const bool supported = aclStatus.error_code() == arm_compute::ErrorCode::OK;
61  if (!supported)
62  {
63  throw BackendCapabilityException("\"GpuFsa\" backend failed during resize validation");
64  }
65 
66  arm_compute::ITensorInfo* addOutputInfo = GpuResize::create_op(*sketch,
67  inputTensorInfos[0],
68  resizeAttributes);
69 
70  // Temporary fix until fusing attempt is make for GpuFsa backend and Output layer workload is created.
71  outputTensorInfos.emplace_back(workloadContext->create_tensor_info());
72  GpuOutput::create_op(*sketch, addOutputInfo, outputTensorInfos[0]);
73 
74  // Store the TensorInfos within the blob as unique_ptrs to be used later
75  blob->inputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(inputTensorInfos);
76  blob->outputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(outputTensorInfos);
77 }
78 
79 } // namespace armnn
armnn::ResizeDescriptor
A ResizeDescriptor for the ResizeLayer.
Definition: Descriptors.hpp:985
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::ResizeDescriptor::m_DataLayout
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Definition: Descriptors.hpp:1014
armnn::TensorInfo::IsConstant
bool IsConstant() const
Definition: Tensor.cpp:513
armnn::GpuFsaPreCompiledBlob::inputTensorInfos
std::unique_ptr< std::vector< arm_compute::ITensorInfo * > > inputTensorInfos
Definition: GpuFsaBackend.hpp:37
armnn::GpuFsaResizeValidate
arm_compute::Status GpuFsaResizeValidate(const TensorInfo &input, const ResizeDescriptor &descriptor)
Definition: GpuFsaResize.cpp:22
CreateResizeAttributes
arm_compute::experimental::dynamic_fusion::ResizeAttributes CreateResizeAttributes(const armnn::ResizeDescriptor &descriptor)
Utility function used to setup an arm_compute::ResizeDescriptor object from given descriptor.
Definition: UtilsGpuFsa.cpp:64
armnn::GpuFsaPreCompiledBlob::sketch
std::unique_ptr< arm_compute::experimental::dynamic_fusion::GpuWorkloadSketch > sketch
Definition: GpuFsaBackend.hpp:34
armnn::GpuFsaResizeCreateOp
void GpuFsaResizeCreateOp(GpuFsaPreCompiledBlob *blob, const TensorInfo &input, const ResizeDescriptor &descriptor)
Definition: GpuFsaResize.cpp:39
GpuFsaResize.hpp
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::GpuFsaPreCompiledBlob::outputTensorInfos
std::unique_ptr< std::vector< arm_compute::ITensorInfo * > > outputTensorInfos
Definition: GpuFsaBackend.hpp:38