ArmNN
 24.11
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
armnn::RunClFunction
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
Definition: ClWorkloadUtils.hpp:167
armnn::DataType::Boolean
@ Boolean
armnn::ClCastWorkload::Execute
virtual void Execute() const override
Definition: ClCastWorkload.cpp:54
armnn::ClCastValidate
arm_compute::Status ClCastValidate(const TensorInfo &input, const TensorInfo &output)
Definition: ClCastWorkload.cpp:20
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:447
armnn::TensorInfo
Definition: Tensor.hpp:152
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::ClBaseWorkload
Definition: ClBaseWorkload.hpp:13
ClCastWorkload.hpp
armnn::ClCastWorkload::ClCastWorkload
ClCastWorkload(const CastQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Definition: ClCastWorkload.cpp:38
ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: ClWorkloadUtils.hpp:36
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
ClWorkloadUtils.hpp
armnn::BoostLogSeverityMapping::info
@ info
armnn::TensorInfo::GetDataType
DataType GetDataType() const
Definition: Tensor.hpp:200
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::CastQueueDescriptor
Definition: WorkloadData.hpp:168
armnn::Status
Status
Definition: Types.hpp:42
ClTensorHandle.hpp
armnn::BaseWorkload< CastQueueDescriptor >::m_Data
CastQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26