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 | |
| 25 | void RefLogicalBinaryWorkload::PostAllocationConfigure() |
| 26 | { |
| 27 | const TensorInfo& inputInfo0 = GetTensorInfo(m_Data.m_Inputs[0]); |
| 28 | const TensorInfo& inputInfo1 = GetTensorInfo(m_Data.m_Inputs[1]); |
| 29 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 30 | |
| 31 | m_Input0 = MakeDecoder<InType>(inputInfo0); |
| 32 | m_Input1 = MakeDecoder<InType>(inputInfo1); |
| 33 | m_Output = MakeEncoder<OutType>(outputInfo); |
| 34 | } |
| 35 | |
| 36 | void RefLogicalBinaryWorkload::Execute() const |
| 37 | { |
| 38 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefLogicalBinaryWorkload_Execute"); |
| 39 | |
| 40 | const TensorInfo& inputInfo0 = GetTensorInfo(m_Data.m_Inputs[0]); |
| 41 | const TensorInfo& inputInfo1 = GetTensorInfo(m_Data.m_Inputs[1]); |
| 42 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 43 | |
| 44 | const TensorShape& inShape0 = inputInfo0.GetShape(); |
| 45 | const TensorShape& inShape1 = inputInfo1.GetShape(); |
| 46 | const TensorShape& outShape = outputInfo.GetShape(); |
| 47 | |
| 48 | m_Input0->Reset(m_Data.m_Inputs[0]->Map()); |
| 49 | m_Input1->Reset(m_Data.m_Inputs[1]->Map()); |
| 50 | m_Output->Reset(m_Data.m_Outputs[0]->Map()); |
| 51 | |
| 52 | using AndFunction = LogicalBinaryFunction<std::logical_and<bool>>; |
| 53 | using OrFunction = LogicalBinaryFunction<std::logical_or<bool>>; |
| 54 | |
| 55 | switch (m_Data.m_Parameters.m_Operation) |
| 56 | { |
| 57 | case LogicalBinaryOperation::LogicalAnd: |
| 58 | { |
| 59 | AndFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 60 | break; |
| 61 | } |
| 62 | case LogicalBinaryOperation::LogicalOr: |
| 63 | { |
| 64 | OrFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 65 | break; |
| 66 | } |
| 67 | default: |
| 68 | { |
| 69 | throw InvalidArgumentException(std::string("Unsupported Logical Binary operation") + |
| 70 | GetLogicalBinaryOperationAsCString(m_Data.m_Parameters.m_Operation), CHECK_LOCATION()); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } // namespace armnn |