blob: 4575d21421bee779e8dfde6c22d2db3d655849d4 [file] [log] [blame]
Teresa Charlina52bca22024-02-01 17:36:48 +00001//
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
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/GpuPool2d.h>
14#include <arm_compute/dynamic_fusion/sketch/gpu/operators/GpuOutput.h>
15
16using namespace arm_compute::experimental::dynamic_fusion;
17using namespace armnn::armcomputetensorutils;
18
19namespace armnn
20{
21
22arm_compute::Status GpuFsaPooling2dValidate(const TensorInfo& input,
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
40void GpuFsaPooling2dCreateOp(GpuFsaPreCompiledBlob* blob,
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