ArmNN
 24.02
GpuFsaReshape.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 "GpuFsaReshape.hpp"
7 
9 
10 #include <arm_compute/dynamic_fusion/sketch/gpu/operators/GpuReshape.h>
11 #include <arm_compute/dynamic_fusion/sketch/gpu/operators/GpuOutput.h>
12 #include <arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadContext.h>
13 #include <arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.h>
14 
15 using namespace arm_compute::experimental::dynamic_fusion;
16 
17 namespace armnn
18 {
19 
20 using namespace armcomputetensorutils;
21 
23 {
24  auto compileContext = arm_compute::CLKernelLibrary::get().get_compile_context();
25  auto workloadContext = GpuWorkloadContext(&compileContext);
26 
27  GpuWorkloadSketch sketch(&workloadContext);
28 
29  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, input.GetNumDimensions());
30  aclInputInfo.set_are_values_constant(input.IsConstant());
31 
32  arm_compute::ITensorInfo* inputInfo = workloadContext.create_tensor_info(aclInputInfo);
33 
34  ReshapeAttributes attributes;
35  attributes.shape(BuildArmComputeTensorShape(descriptor.m_TargetShape));
36 
37  arm_compute::Status aclStatus = GpuReshape::validate_op(sketch, inputInfo, attributes);
38 
39 #ifndef NDEBUG
40  if (aclStatus.error_code() != arm_compute::ErrorCode::OK)
41  {
42  std::cout << "GpuFsaReshapeValidate failed: " << aclStatus.error_description() << std::endl;
43  }
44 #endif
45 
46  return aclStatus;
47 }
48 
49 void GpuFsaReshapeCreateOp(GpuFsaPreCompiledBlob* blob, const TensorInfo& input, const ReshapeDescriptor& descriptor)
50 {
51  GpuWorkloadSketch* sketch = blob->sketch.get();
52  GpuWorkloadContext* workloadContext = blob->workloadContext.get();
53 
54  std::vector<arm_compute::ITensorInfo*> inputTensorInfos;
55  std::vector<arm_compute::ITensorInfo*> outputTensorInfos;
56 
57  arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, input.GetNumDimensions());
58 
59  aclInputInfo.set_are_values_constant(input.IsConstant());
60 
61  inputTensorInfos.emplace_back(workloadContext->create_tensor_info(aclInputInfo));
62 
63  ReshapeAttributes attributes;
64  attributes.shape(BuildArmComputeTensorShape(descriptor.m_TargetShape));
65 
66  arm_compute::ITensorInfo* addOutputInfo = GpuReshape::create_op(*sketch, inputTensorInfos[0], attributes);
67 
68  // Temporary fix until fusing attempt is made for GpuFsa backend and outputLayer workoad is created
69  outputTensorInfos.emplace_back(workloadContext->create_tensor_info());
70  GpuOutput::create_op(*sketch, addOutputInfo, outputTensorInfos[0]);
71 
72  // Store the tensorInfos within the blob as std::unique_ptr<> so they can be used later
73  blob->inputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(inputTensorInfos);
74  blob->outputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(outputTensorInfos);
75 }
76 
77 } // namespace armnn
78 
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::TensorInfo::GetNumDimensions
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:197
armnn::TensorInfo::IsConstant
bool IsConstant() const
Definition: Tensor.cpp:509
armnn::GpuFsaReshapeCreateOp
void GpuFsaReshapeCreateOp(GpuFsaPreCompiledBlob *blob, const TensorInfo &input, const ReshapeDescriptor &descriptor)
Definition: GpuFsaReshape.cpp:49
armnn::GpuFsaPreCompiledBlob::inputTensorInfos
std::unique_ptr< std::vector< arm_compute::ITensorInfo * > > inputTensorInfos
Definition: GpuFsaBackend.hpp:37
armnn::GpuFsaPreCompiledBlob::sketch
std::unique_ptr< arm_compute::experimental::dynamic_fusion::GpuWorkloadSketch > sketch
Definition: GpuFsaBackend.hpp:34
armnn::ReshapeDescriptor
A ReshapeDescriptor for the ReshapeLayer.
Definition: Descriptors.hpp:1023
armnn::GpuFsaReshapeValidate
arm_compute::Status GpuFsaReshapeValidate(const TensorInfo &input, const ReshapeDescriptor &descriptor)
Definition: GpuFsaReshape.cpp:22
armnn::ReshapeDescriptor::m_TargetShape
TensorShape m_TargetShape
Target shape value.
Definition: Descriptors.hpp:1039
armnn::Status
Status
Definition: Types.hpp:42
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
GpuFsaReshape.hpp
armnn::GpuFsaPreCompiledBlob::outputTensorInfos
std::unique_ptr< std::vector< arm_compute::ITensorInfo * > > outputTensorInfos
Definition: GpuFsaBackend.hpp:38