xref: /aosp_15_r20/external/armnn/src/backends/cl/workloads/ClFloorFloatWorkload.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ClFloorFloatWorkload.hpp"
7 #include <cl/ClTensorHandle.hpp>
8 
9 #include "ClWorkloadUtils.hpp"
10 
11 namespace armnn
12 {
13 
ClFloorWorkloadValidate(const TensorInfo & input,const TensorInfo & output)14 arm_compute::Status ClFloorWorkloadValidate(const TensorInfo& input,
15                                             const TensorInfo& output)
16 {
17     const arm_compute::TensorInfo aclInput  = armcomputetensorutils::BuildArmComputeTensorInfo(input);
18     const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
19 
20     return arm_compute::CLFloor::validate(&aclInput, &aclOutput);
21 }
22 
ClFloorFloatWorkload(const FloorQueueDescriptor & descriptor,const WorkloadInfo & info,const arm_compute::CLCompileContext & clCompileContext)23 ClFloorFloatWorkload::ClFloorFloatWorkload(const FloorQueueDescriptor& descriptor,
24                                            const WorkloadInfo& info,
25                                            const arm_compute::CLCompileContext& clCompileContext)
26     : FloatWorkload<FloorQueueDescriptor>(descriptor, info)
27 {
28     m_Data.ValidateInputsOutputs("ClFloorFloatWorkload", 1, 1);
29 
30     arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
31     arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
32     {
33         ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClFloorFloatWorkload_configure");
34         m_Layer.configure(clCompileContext, &input, &output);
35     }
36 }
37 
Execute() const38 void ClFloorFloatWorkload::Execute() const
39 {
40     ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClFloorFloatWorkload_Execute", this->GetGuid());
41     RunClFunction(m_Layer, CHECK_LOCATION());
42 }
43 
ReplaceInputTensorHandle(ITensorHandle * tensorHandle,unsigned int slot)44 void ClFloorFloatWorkload::ReplaceInputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
45 {
46     ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
47     this->m_Data.m_Inputs[slot] = tensorHandle;
48     try
49     {
50         Reconfigure();
51     }
52     catch(armnn::UnimplementedException& e)
53     {
54         // Cannot reconfigure, revert the slot back and throw the exception.
55         this->m_Data.m_Inputs[slot] = backupHandle;
56         throw e;
57     }
58 }
59 
60 // Replace output tensor handle with the given TensorHandle
ReplaceOutputTensorHandle(ITensorHandle * tensorHandle,unsigned int slot)61 void ClFloorFloatWorkload::ReplaceOutputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
62 {
63     ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
64     this->m_Data.m_Inputs[slot] = tensorHandle;
65     try
66     {
67         Reconfigure();
68     }
69     catch(armnn::UnimplementedException& e)
70     {
71         // Cannot reconfigure, revert the slot back and throw the exception.
72         this->m_Data.m_Inputs[slot] = backupHandle;
73         throw e;
74     }
75 }
76 
Reconfigure()77 void ClFloorFloatWorkload::Reconfigure()
78 {
79     throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
80 }
81 
82 } //namespace armnn
83