diff options
author | josh minor <josh.minor@arm.com> | 2020-01-06 16:40:46 -0600 |
---|---|---|
committer | Derek Lamberti <derek.lamberti@arm.com> | 2020-01-23 14:29:14 +0000 |
commit | 4a3c61091037e7e86e8b03bb060d8c1ab82731a9 (patch) | |
tree | 928644023400ad5ac0c26b33dfff2f975567d6e8 /src/backends/reference/workloads/RefElementwiseUnaryWorkload.cpp | |
parent | 190a39a4a9598e42b636ae4ab843761884148160 (diff) | |
download | armnn-4a3c61091037e7e86e8b03bb060d8c1ab82731a9.tar.gz |
IVGCVSW-4259 Add frontend and reference workload for UnaryOperationLayer
* Added new layer named ElementwiseUnary
* Deprecated existing Abs/Rsqrt layer functions
* Updated existing Abs/Rsqrt test infrastructure to use new layer
* Added boilerplate for new Exp,Neg,Sqrt elemwise op layers
* AbsQuantize test removed pending future commit
* Serialization support added
!android-nn-driver:2550
Change-Id: Ic595c645925e17b45db568187fd05646daf2e87f
Signed-off-by: josh minor <josh.minor@arm.com>
Diffstat (limited to 'src/backends/reference/workloads/RefElementwiseUnaryWorkload.cpp')
-rw-r--r-- | src/backends/reference/workloads/RefElementwiseUnaryWorkload.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/backends/reference/workloads/RefElementwiseUnaryWorkload.cpp b/src/backends/reference/workloads/RefElementwiseUnaryWorkload.cpp new file mode 100644 index 0000000000..4fbb0d123f --- /dev/null +++ b/src/backends/reference/workloads/RefElementwiseUnaryWorkload.cpp @@ -0,0 +1,95 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "RefElementwiseUnaryWorkload.hpp" + +#include "Decoders.hpp" +#include "ElementwiseFunction.hpp" +#include "Encoders.hpp" +#include "RefWorkloadUtils.hpp" +#include "Abs.hpp" +#include "Exp.hpp" +#include "Rsqrt.hpp" +#include "Sqrt.hpp" + +#include <Profiling.hpp> + +#include <armnn/TypesUtils.hpp> + +#include <functional> + +namespace armnn +{ + +RefElementwiseUnaryWorkload::RefElementwiseUnaryWorkload(const ElementwiseUnaryQueueDescriptor& desc, + const WorkloadInfo& info) + : BaseWorkload<ElementwiseUnaryQueueDescriptor>(desc, info) +{} + +void RefElementwiseUnaryWorkload::PostAllocationConfigure() +{ + const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]); + const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); + + m_Input = MakeDecoder<InType>(inputInfo); + + m_Output = MakeEncoder<OutType>(outputInfo); +} + +void RefElementwiseUnaryWorkload::Execute() const +{ + ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefElementwiseUnaryWorkload_Execute"); + + const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]); + const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); + + const TensorShape& inShape = inputInfo.GetShape(); + const TensorShape& outShape = outputInfo.GetShape(); + + m_Input->Reset(m_Data.m_Inputs[0]->Map()); + m_Output->Reset(m_Data.m_Outputs[0]->Map()); + + using AbsFunction = ElementwiseUnaryFunction<abs<InType>>; + using ExpFunction = ElementwiseUnaryFunction<exp<InType>>; + using NegFunction = ElementwiseUnaryFunction<std::negate<InType>>; + using RsqrtFunction = ElementwiseUnaryFunction<rsqrt<InType>>; + using SqrtFunction = ElementwiseUnaryFunction<sqrt<InType>>; + + switch (m_Data.m_Parameters.m_Operation) + { + case UnaryOperation::Abs: + { + AbsFunction(inShape, outShape, *m_Input, *m_Output); + break; + } + case UnaryOperation::Exp: + { + ExpFunction(inShape, outShape, *m_Input, *m_Output); + break; + } + case UnaryOperation::Neg: + { + NegFunction(inShape, outShape, *m_Input, *m_Output); + break; + } + case UnaryOperation::Rsqrt: + { + RsqrtFunction(inShape, outShape, *m_Input, *m_Output); + break; + } + case UnaryOperation::Sqrt: + { + SqrtFunction(inShape, outShape, *m_Input, *m_Output); + break; + } + default: + { + throw InvalidArgumentException(std::string("Unsupported unary operation ") + + GetUnaryOperationAsCString(m_Data.m_Parameters.m_Operation), CHECK_LOCATION()); + } + } +} + +} // namespace armnn |