Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RefComparisonWorkload.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 | #include <functional> |
| 18 | |
| 19 | namespace armnn |
| 20 | { |
| 21 | |
| 22 | RefComparisonWorkload::RefComparisonWorkload(const ComparisonQueueDescriptor& desc, |
| 23 | const WorkloadInfo& info) |
| 24 | : BaseWorkload<ComparisonQueueDescriptor>(desc, info) |
| 25 | {} |
| 26 | |
| 27 | void RefComparisonWorkload::PostAllocationConfigure() |
| 28 | { |
| 29 | const TensorInfo& inputInfo0 = GetTensorInfo(m_Data.m_Inputs[0]); |
| 30 | const TensorInfo& inputInfo1 = GetTensorInfo(m_Data.m_Inputs[1]); |
| 31 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 32 | |
| 33 | m_Input0 = MakeDecoder<InType>(inputInfo0); |
| 34 | m_Input1 = MakeDecoder<InType>(inputInfo1); |
| 35 | |
| 36 | m_Output = MakeEncoder<OutType>(outputInfo); |
| 37 | } |
| 38 | |
| 39 | void RefComparisonWorkload::Execute() const |
| 40 | { |
| 41 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefComparisonWorkload_Execute"); |
| 42 | |
| 43 | const TensorInfo& inputInfo0 = GetTensorInfo(m_Data.m_Inputs[0]); |
| 44 | const TensorInfo& inputInfo1 = GetTensorInfo(m_Data.m_Inputs[1]); |
| 45 | const TensorInfo& outputInfo = GetTensorInfo(m_Data.m_Outputs[0]); |
| 46 | |
| 47 | const TensorShape& inShape0 = inputInfo0.GetShape(); |
| 48 | const TensorShape& inShape1 = inputInfo1.GetShape(); |
| 49 | const TensorShape& outShape = outputInfo.GetShape(); |
| 50 | |
| 51 | m_Input0->Reset(m_Data.m_Inputs[0]->Map()); |
| 52 | m_Input1->Reset(m_Data.m_Inputs[1]->Map()); |
| 53 | m_Output->Reset(m_Data.m_Outputs[0]->Map()); |
| 54 | |
| 55 | using EqualFunction = ElementwiseFunction<std::equal_to<InType>>; |
| 56 | using GreaterFunction = ElementwiseFunction<std::greater<InType>>; |
| 57 | using GreaterOrEqualFunction = ElementwiseFunction<std::greater_equal<InType>>; |
| 58 | using LessFunction = ElementwiseFunction<std::less<InType>>; |
| 59 | using LessOrEqualFunction = ElementwiseFunction<std::less_equal<InType>>; |
| 60 | using NotEqualFunction = ElementwiseFunction<std::not_equal_to<InType>>; |
| 61 | |
| 62 | switch (m_Data.m_Parameters.m_Operation) |
| 63 | { |
| 64 | case ComparisonOperation::Equal: |
| 65 | { |
| 66 | EqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 67 | break; |
| 68 | } |
| 69 | case ComparisonOperation::Greater: |
| 70 | { |
| 71 | GreaterFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 72 | break; |
| 73 | } |
| 74 | case ComparisonOperation::GreaterOrEqual: |
| 75 | { |
| 76 | GreaterOrEqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 77 | break; |
| 78 | } |
| 79 | case ComparisonOperation::Less: |
| 80 | { |
| 81 | LessFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 82 | break; |
| 83 | } |
| 84 | case ComparisonOperation::LessOrEqual: |
| 85 | { |
| 86 | LessOrEqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 87 | break; |
| 88 | } |
| 89 | case ComparisonOperation::NotEqual: |
| 90 | { |
| 91 | NotEqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 92 | break; |
| 93 | } |
| 94 | default: |
| 95 | { |
| 96 | throw InvalidArgumentException(std::string("Unsupported comparison operation ") + |
| 97 | GetComparisonOperationAsCString(m_Data.m_Parameters.m_Operation), CHECK_LOCATION()); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | } // namespace armnn |