ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NeonCastWorkload.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 "NeonCastWorkload.hpp"
7 #include "NeonWorkloadUtils.hpp"
8 
11 
13 
14 namespace armnn
15 {
16 
17 static constexpr arm_compute::ConvertPolicy g_AclConvertPolicy = arm_compute::ConvertPolicy::SATURATE;
18 
20 {
21  // ACL doesn't have a Boolean type - the armnn Boolean is evaluated as an ACL U8.
22  // This causes issues when casting numbers to Boolean, as casting float to U8 truncates decimal points
23  // and casting negative signed ints to U8 clamps to 0, but a cast to Boolean returns true for anything non-zero.
24  // For example, float to U8 expects 0.1f -> 0u, but float to Boolean 0.1f -> true.
25  // ACL isn't aware of the Boolean type, so this check has to be here.
27  {
28  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Cast to Boolean unsupported"};
29  }
30 
31  arm_compute::TensorInfo aclInput = armcomputetensorutils::BuildArmComputeTensorInfo(input);
32  arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
33 
34  return arm_compute::NECast::validate(&aclInput, &aclOutput, g_AclConvertPolicy);
35 }
36 
39 {
40  m_Data.ValidateInputsOutputs("NeonCastWorkload", 1, 1);
41 
42  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
43  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
44 
45  m_CastLayer.configure(&input, &output, g_AclConvertPolicy);
46 }
47 
49 {
50  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonCastWorkload_Execute");
51  m_CastLayer.run();
52 }
53 
54 } // namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
QueueDescriptor m_Data
Definition: Workload.hpp:74
NeonCastWorkload(const CastQueueDescriptor &descriptor, const WorkloadInfo &info)
virtual void Execute() const override
DataType GetDataType() const
Definition: Tensor.hpp:200
Copyright (c) 2021 ARM Limited and Contributors.
arm_compute::Status NeonCastValidate(const TensorInfo &input, const TensorInfo &output)
Status
enumeration
Definition: Types.hpp:43
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.