josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1 | // |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RefElementwiseUnaryWorkload.hpp" |
| 7 | |
| 8 | #include "Decoders.hpp" |
| 9 | #include "ElementwiseFunction.hpp" |
| 10 | #include "Encoders.hpp" |
| 11 | #include "RefWorkloadUtils.hpp" |
| 12 | #include "Abs.hpp" |
| 13 | #include "Exp.hpp" |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 14 | #include "Log.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 15 | #include "Rsqrt.hpp" |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 16 | #include "Sin.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 17 | #include "Sqrt.hpp" |
| 18 | |
| 19 | #include <Profiling.hpp> |
| 20 | |
| 21 | #include <armnn/TypesUtils.hpp> |
| 22 | |
| 23 | #include <functional> |
| 24 | |
| 25 | namespace armnn |
| 26 | { |
| 27 | |
| 28 | RefElementwiseUnaryWorkload::RefElementwiseUnaryWorkload(const ElementwiseUnaryQueueDescriptor& desc, |
| 29 | const WorkloadInfo& info) |
| 30 | : BaseWorkload<ElementwiseUnaryQueueDescriptor>(desc, info) |
| 31 | {} |
| 32 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 33 | void RefElementwiseUnaryWorkload::Execute() const |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 34 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 35 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 36 | } |
| 37 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 38 | void RefElementwiseUnaryWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 39 | { |
| 40 | |
| 41 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 42 | } |
| 43 | |
| 44 | void RefElementwiseUnaryWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 45 | { |
| 46 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefElementwiseUnaryWorkload_Execute"); |
| 47 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 48 | const TensorInfo& inputInfo = GetTensorInfo(inputs[0]); |
| 49 | const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 50 | |
| 51 | const TensorShape& inShape = inputInfo.GetShape(); |
| 52 | const TensorShape& outShape = outputInfo.GetShape(); |
| 53 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 54 | std::unique_ptr<Decoder<InType>> input = MakeDecoder<InType>(inputInfo, inputs[0]->Map()); |
| 55 | std::unique_ptr<Encoder<OutType>> output= MakeEncoder<OutType>(outputInfo, outputs[0]->Map()); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 56 | |
| 57 | using AbsFunction = ElementwiseUnaryFunction<abs<InType>>; |
| 58 | using ExpFunction = ElementwiseUnaryFunction<exp<InType>>; |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 59 | using LogFunction = ElementwiseUnaryFunction<log<InType>>; |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 60 | using NegFunction = ElementwiseUnaryFunction<std::negate<InType>>; |
| 61 | using RsqrtFunction = ElementwiseUnaryFunction<rsqrt<InType>>; |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 62 | using SinFunction = ElementwiseUnaryFunction<sin<InType>>; |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 63 | using SqrtFunction = ElementwiseUnaryFunction<sqrt<InType>>; |
| 64 | |
| 65 | switch (m_Data.m_Parameters.m_Operation) |
| 66 | { |
| 67 | case UnaryOperation::Abs: |
| 68 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 69 | AbsFunction(inShape, outShape, *input, *output); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 70 | break; |
| 71 | } |
| 72 | case UnaryOperation::Exp: |
| 73 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 74 | ExpFunction(inShape, outShape, *input, *output); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 75 | break; |
| 76 | } |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 77 | case UnaryOperation::Log: |
| 78 | { |
| 79 | LogFunction(inShape, outShape, *input, *output); |
| 80 | break; |
| 81 | } |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 82 | case UnaryOperation::Neg: |
| 83 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 84 | NegFunction(inShape, outShape, *input, *output); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 85 | break; |
| 86 | } |
| 87 | case UnaryOperation::Rsqrt: |
| 88 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 89 | RsqrtFunction(inShape, outShape, *input, *output); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 90 | break; |
| 91 | } |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 92 | case UnaryOperation::Sin: |
| 93 | { |
| 94 | SinFunction(inShape, outShape, *input, *output); |
| 95 | break; |
| 96 | } |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 97 | case UnaryOperation::Sqrt: |
| 98 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 99 | SqrtFunction(inShape, outShape, *input, *output); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 100 | break; |
| 101 | } |
| 102 | default: |
| 103 | { |
| 104 | throw InvalidArgumentException(std::string("Unsupported unary operation ") + |
| 105 | GetUnaryOperationAsCString(m_Data.m_Parameters.m_Operation), CHECK_LOCATION()); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | } // namespace armnn |