ArmNN
 25.11
Loading...
Searching...
No Matches
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
15namespace armnn
16{
17
18static constexpr arm_compute::ConvertPolicy g_AclConvertPolicy = arm_compute::ConvertPolicy::SATURATE;
19
20arm_compute::Status ClCastValidate(const TensorInfo& input, const TensorInfo& output)
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()
ClBaseWorkload(const CastQueueDescriptor &descriptor, const WorkloadInfo &info)
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.
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
arm_compute::Status ClCastValidate(const TensorInfo &input, const TensorInfo &output)
DestType PolymorphicDowncast(SourceType *value)
Polymorphic downcast for build in pointers only.
Contains information about TensorInfos of a layer.