Teresa Charlin | 1d6b731 | 2024-02-07 22:02:48 +0000 | [diff] [blame] | 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 | |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 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 | |
| 22 | arm_compute::Status GpuFsaResizeValidate(const TensorInfo& input, |
| 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 | |
| 39 | void GpuFsaResizeCreateOp(GpuFsaPreCompiledBlob* blob, |
| 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 |