ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ClCastWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ClCastWorkload.hpp"
7 #include "ClWorkloadUtils.hpp"
8 
10 
12 
13 #include <cl/ClTensorHandle.hpp>
14 
15 namespace armnn
16 {
17 
18 static constexpr arm_compute::ConvertPolicy g_AclConvertPolicy = arm_compute::ConvertPolicy::SATURATE;
19 
21 {
22  // ACL doesn't have a Boolean type - the armnn Boolean is evaluated as an ACL U8.
23  // This causes issues when casting numbers to Boolean, as casting float to U8 truncates decimal points
24  // and casting negative signed ints to U8 clamps to 0, but a cast to Boolean returns true for anything non-zero.
25  // For example, float to U8 expects 0.1f -> 0u, but float to Boolean 0.1f -> true.
26  // ACL isn't aware of the Boolean type, so this check has to be here.
28  {
29  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Cast to Boolean unsupported"};
30  }
31 
32  const arm_compute::TensorInfo aclInput = armcomputetensorutils::BuildArmComputeTensorInfo(input);
33  const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
34 
35  return arm_compute::CLCast::validate(&aclInput, &aclOutput, g_AclConvertPolicy);
36 }
37 
39  const WorkloadInfo& info,
40  const arm_compute::CLCompileContext& clCompileContext)
42 {
43  m_Data.ValidateInputsOutputs("ClCastWorkload", 1, 1);
44 
45  arm_compute::ICLTensor& input = PolymorphicDowncast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
46  arm_compute::ICLTensor& output = PolymorphicDowncast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
47 
48  {
49  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClCastWorkload_configure");
50  m_CastLayer.configure(clCompileContext, &input, &output, g_AclConvertPolicy);
51  }
52 }
53 
55 {
56  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClCastWorkload_Execute");
57  RunClFunction(m_CastLayer, CHECK_LOCATION());
58 }
59 
60 } // namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
QueueDescriptor m_Data
Definition: Workload.hpp:74
virtual void Execute() const override
ClCastWorkload(const CastQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
DataType GetDataType() const
Definition: Tensor.hpp:200
Copyright (c) 2021 ARM Limited and Contributors.
Status
enumeration
Definition: Types.hpp:43
arm_compute::Status ClCastValidate(const TensorInfo &input, const TensorInfo &output)
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
std::vector< ITensorHandle * > m_Inputs
std::vector< ITensorHandle * > m_Outputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Contains information about TensorInfos of a layer.