James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RefLogicalBinaryWorkload.hpp" |
| 7 | |
| 8 | #include "Decoders.hpp" |
| 9 | #include "ElementwiseFunction.hpp" |
| 10 | #include "Encoders.hpp" |
| 11 | #include "RefWorkloadUtils.hpp" |
| 12 | |
| 13 | #include <Profiling.hpp> |
| 14 | |
| 15 | #include <armnn/TypesUtils.hpp> |
| 16 | |
| 17 | namespace armnn |
| 18 | { |
| 19 | |
| 20 | RefLogicalBinaryWorkload::RefLogicalBinaryWorkload(const LogicalBinaryQueueDescriptor& desc, |
| 21 | const WorkloadInfo& info) |
| 22 | : BaseWorkload<LogicalBinaryQueueDescriptor>(desc, info) |
| 23 | {} |
| 24 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 25 | void RefLogicalBinaryWorkload::Execute() const |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 26 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 27 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 30 | void RefLogicalBinaryWorkload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 31 | { |
| 32 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 33 | } |
| 34 | |
| 35 | void RefLogicalBinaryWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 36 | { |
| 37 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefLogicalBinaryWorkload_Execute"); |
| 38 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 39 | const TensorInfo& inputInfo0 = GetTensorInfo(inputs[0]); |
| 40 | const TensorInfo& inputInfo1 = GetTensorInfo(inputs[1]); |
| 41 | const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 42 | |
| 43 | const TensorShape& inShape0 = inputInfo0.GetShape(); |
| 44 | const TensorShape& inShape1 = inputInfo1.GetShape(); |
| 45 | const TensorShape& outShape = outputInfo.GetShape(); |
| 46 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 47 | std::unique_ptr<Decoder<InType>> input0 = MakeDecoder<InType>(inputInfo0, inputs[0]->Map()); |
| 48 | std::unique_ptr<Decoder<InType>> input1 = MakeDecoder<InType>(inputInfo1, inputs[1]->Map()); |
| 49 | std::unique_ptr<Encoder<OutType>> output = MakeEncoder<OutType>(outputInfo, outputs[0]->Map()); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 50 | |
| 51 | using AndFunction = LogicalBinaryFunction<std::logical_and<bool>>; |
| 52 | using OrFunction = LogicalBinaryFunction<std::logical_or<bool>>; |
| 53 | |
| 54 | switch (m_Data.m_Parameters.m_Operation) |
| 55 | { |
| 56 | case LogicalBinaryOperation::LogicalAnd: |
| 57 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 58 | AndFunction(inShape0, inShape1, outShape, *input0, *input1, *output); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 59 | break; |
| 60 | } |
| 61 | case LogicalBinaryOperation::LogicalOr: |
| 62 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 63 | OrFunction(inShape0, inShape1, outShape, *input0, *input1, *output); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 64 | break; |
| 65 | } |
| 66 | default: |
| 67 | { |
| 68 | throw InvalidArgumentException(std::string("Unsupported Logical Binary operation") + |
| 69 | GetLogicalBinaryOperationAsCString(m_Data.m_Parameters.m_Operation), CHECK_LOCATION()); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } // namespace armnn |