Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 1 | // |
Matthew Sloyan | 2d213a7 | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 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) |
Finn Williams | 73c547d | 2022-02-15 20:47:34 +0000 | [diff] [blame] | 24 | : RefBaseWorkload<ComparisonQueueDescriptor>(desc, info) |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 25 | {} |
| 26 | |
| 27 | void RefComparisonWorkload::PostAllocationConfigure() |
| 28 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 29 | PostAllocationConfigure(m_Data.m_Inputs, m_Data.m_Outputs); |
| 30 | } |
| 31 | |
| 32 | void RefComparisonWorkload::PostAllocationConfigure(std::vector<ITensorHandle*> inputs, |
| 33 | std::vector<ITensorHandle*> outputs) |
| 34 | { |
| 35 | const TensorInfo& inputInfo0 = GetTensorInfo(inputs[0]); |
| 36 | const TensorInfo& inputInfo1 = GetTensorInfo(inputs[1]); |
| 37 | const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 38 | |
| 39 | m_Input0 = MakeDecoder<InType>(inputInfo0); |
| 40 | m_Input1 = MakeDecoder<InType>(inputInfo1); |
| 41 | |
| 42 | m_Output = MakeEncoder<OutType>(outputInfo); |
| 43 | } |
| 44 | |
| 45 | void RefComparisonWorkload::Execute() const |
| 46 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 47 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
| 48 | } |
| 49 | |
Matthew Sloyan | 2d213a7 | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 50 | void RefComparisonWorkload::ExecuteAsync(ExecutionData& executionData) |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 51 | { |
Matthew Sloyan | 2d213a7 | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 52 | WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data); |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 53 | |
Matthew Sloyan | 2d213a7 | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 54 | PostAllocationConfigure(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs); |
| 55 | Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs); |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void RefComparisonWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const |
| 59 | { |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 60 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefComparisonWorkload_Execute"); |
| 61 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 62 | const TensorInfo& inputInfo0 = GetTensorInfo(inputs[0]); |
| 63 | const TensorInfo& inputInfo1 = GetTensorInfo(inputs[1]); |
| 64 | const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 65 | |
| 66 | const TensorShape& inShape0 = inputInfo0.GetShape(); |
| 67 | const TensorShape& inShape1 = inputInfo1.GetShape(); |
| 68 | const TensorShape& outShape = outputInfo.GetShape(); |
| 69 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 70 | m_Input0->Reset(inputs[0]->Map()); |
| 71 | m_Input1->Reset(inputs[1]->Map()); |
| 72 | m_Output->Reset(outputs[0]->Map()); |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 73 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 74 | using EqualFunction = ElementwiseBinaryFunction<std::equal_to<InType>>; |
| 75 | using GreaterFunction = ElementwiseBinaryFunction<std::greater<InType>>; |
| 76 | using GreaterOrEqualFunction = ElementwiseBinaryFunction<std::greater_equal<InType>>; |
| 77 | using LessFunction = ElementwiseBinaryFunction<std::less<InType>>; |
| 78 | using LessOrEqualFunction = ElementwiseBinaryFunction<std::less_equal<InType>>; |
| 79 | using NotEqualFunction = ElementwiseBinaryFunction<std::not_equal_to<InType>>; |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 80 | |
| 81 | switch (m_Data.m_Parameters.m_Operation) |
| 82 | { |
| 83 | case ComparisonOperation::Equal: |
| 84 | { |
| 85 | EqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 86 | break; |
| 87 | } |
| 88 | case ComparisonOperation::Greater: |
| 89 | { |
| 90 | GreaterFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 91 | break; |
| 92 | } |
| 93 | case ComparisonOperation::GreaterOrEqual: |
| 94 | { |
| 95 | GreaterOrEqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 96 | break; |
| 97 | } |
| 98 | case ComparisonOperation::Less: |
| 99 | { |
| 100 | LessFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 101 | break; |
| 102 | } |
| 103 | case ComparisonOperation::LessOrEqual: |
| 104 | { |
| 105 | LessOrEqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 106 | break; |
| 107 | } |
| 108 | case ComparisonOperation::NotEqual: |
| 109 | { |
| 110 | NotEqualFunction(inShape0, inShape1, outShape, *m_Input0, *m_Input1, *m_Output); |
| 111 | break; |
| 112 | } |
| 113 | default: |
| 114 | { |
| 115 | throw InvalidArgumentException(std::string("Unsupported comparison operation ") + |
| 116 | GetComparisonOperationAsCString(m_Data.m_Parameters.m_Operation), CHECK_LOCATION()); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | } // namespace armnn |