Aron Virginas-Tar | e89ebad | 2019-08-27 18:14:26 +0100 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "EqualTestImpl.hpp" |
| 7 | |
| 8 | #include "ElementwiseTestImpl.hpp" |
| 9 | |
| 10 | template<> |
| 11 | std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::EqualQueueDescriptor>( |
| 12 | const armnn::IWorkloadFactory& workloadFactory, |
| 13 | const armnn::WorkloadInfo& info, |
| 14 | const armnn::EqualQueueDescriptor& descriptor) |
| 15 | { |
| 16 | return workloadFactory.CreateEqual(descriptor, info); |
| 17 | } |
| 18 | |
| 19 | LayerTestResult<uint8_t, 4> EqualSimpleTest(armnn::IWorkloadFactory& workloadFactory, |
| 20 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 21 | { |
| 22 | const unsigned int width = 2u; |
| 23 | const unsigned int height = 2u; |
| 24 | const unsigned int channelCount = 2u; |
| 25 | const unsigned int batchSize = 2u; |
| 26 | |
| 27 | unsigned int shape[] = { batchSize, channelCount, height, width }; |
| 28 | |
| 29 | std::vector<float> input0 = |
| 30 | { |
| 31 | 1.f, 1.f, 1.f, 1.f, 5.f, 5.f, 5.f, 5.f, |
| 32 | 3.f, 3.f, 3.f, 3.f, 4.f, 4.f, 4.f, 4.f |
| 33 | }; |
| 34 | |
| 35 | std::vector<float> input1({ 1, 1, 1, 1, 3, 3, 3, 3, |
| 36 | 5, 5, 5, 5, 4, 4, 4, 4 }); |
| 37 | |
| 38 | std::vector<uint8_t> output({ 1, 1, 1, 1, 0, 0, 0, 0, |
| 39 | 0, 0, 0, 0, 1, 1, 1, 1 }); |
| 40 | |
| 41 | return ElementwiseTestHelper<4, armnn::EqualQueueDescriptor, armnn::DataType::Float32, armnn::DataType::Boolean>( |
| 42 | workloadFactory, |
| 43 | memoryManager, |
| 44 | shape, |
| 45 | input0, |
| 46 | shape, |
| 47 | input1, |
| 48 | shape, |
| 49 | output); |
| 50 | } |
| 51 | |
| 52 | LayerTestResult<uint8_t, 4> EqualBroadcast1ElementTest( |
| 53 | armnn::IWorkloadFactory& workloadFactory, |
| 54 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 55 | { |
| 56 | unsigned int shape0[] = { 1, 2, 2, 2 }; |
| 57 | std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8}); |
| 58 | |
| 59 | unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 60 | std::vector<float> input1({ 1 }); |
| 61 | |
| 62 | std::vector<uint8_t> output({ 1, 0, 0, 0, 0, 0, 0, 0}); |
| 63 | |
| 64 | return ElementwiseTestHelper<4, armnn::EqualQueueDescriptor, armnn::DataType::Float32, armnn::DataType::Boolean>( |
| 65 | workloadFactory, |
| 66 | memoryManager, |
| 67 | shape0, |
| 68 | input0, |
| 69 | shape1, |
| 70 | input1, |
| 71 | shape0, |
| 72 | output); |
| 73 | } |
| 74 | |
| 75 | LayerTestResult<uint8_t, 4> EqualBroadcast1DVectorTest( |
| 76 | armnn::IWorkloadFactory& workloadFactory, |
| 77 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 78 | { |
| 79 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 80 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 81 | |
| 82 | std::vector<float> input0({ 1, 2, 3, 4, 5, 6, |
| 83 | 7, 8, 9, 10, 11, 12 }); |
| 84 | |
| 85 | std::vector<float> input1({ 1, 2, 3}); |
| 86 | |
| 87 | std::vector<uint8_t> output({ 1, 1, 1, 0, 0, 0, |
| 88 | 0, 0, 0, 0, 0, 0 }); |
| 89 | |
| 90 | return ElementwiseTestHelper<4, armnn::EqualQueueDescriptor, armnn::DataType::Float32, armnn::DataType::Boolean>( |
| 91 | workloadFactory, |
| 92 | memoryManager, |
| 93 | shape0, |
| 94 | input0, |
| 95 | shape1, |
| 96 | input1, |
| 97 | shape0, |
| 98 | output); |
| 99 | } |
| 100 | |
| 101 | LayerTestResult<uint8_t, 4> EqualUint8Test( |
| 102 | armnn::IWorkloadFactory& workloadFactory, |
| 103 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 104 | { |
| 105 | unsigned int shape[] = { 2, 2, 2, 2 }; |
| 106 | |
| 107 | // See dequantized values to the right. |
| 108 | std::vector<uint8_t> input0({ 1, 1, 1, 1, 6, 6, 6, 6, |
| 109 | 3, 3, 3, 3, 7, 7, 7, 7 }); |
| 110 | |
| 111 | std::vector<uint8_t> input1({ 2, 2, 2, 2, 6, 6, 6, 6, |
| 112 | 3, 3, 3, 3, 5, 5, 5, 5 }); |
| 113 | |
| 114 | std::vector<uint8_t> output({ 0, 0, 0, 0, 1, 1, 1, 1, |
| 115 | 1, 1, 1, 1, 0, 0, 0, 0 }); |
| 116 | |
| 117 | return ElementwiseTestHelper<4, |
| 118 | armnn::EqualQueueDescriptor, |
| 119 | armnn::DataType::QuantisedAsymm8, |
| 120 | armnn::DataType::Boolean>( |
| 121 | workloadFactory, |
| 122 | memoryManager, |
| 123 | shape, |
| 124 | input0, |
| 125 | shape, |
| 126 | input1, |
| 127 | shape, |
| 128 | output); |
| 129 | } |
| 130 | |
| 131 | LayerTestResult<uint8_t, 4> EqualBroadcast1ElementUint8Test( |
| 132 | armnn::IWorkloadFactory& workloadFactory, |
| 133 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 134 | { |
| 135 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 136 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 137 | |
| 138 | std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6, |
| 139 | 7, 8, 9, 10, 11, 12 }); |
| 140 | |
| 141 | std::vector<uint8_t> input1({ 1 }); |
| 142 | |
| 143 | std::vector<uint8_t> output({ 1, 0, 0, 0, 0, 0, |
| 144 | 0, 0, 0, 0, 0, 0 }); |
| 145 | |
| 146 | return ElementwiseTestHelper<4, |
| 147 | armnn::EqualQueueDescriptor, |
| 148 | armnn::DataType::QuantisedAsymm8, |
| 149 | armnn::DataType::Boolean>( |
| 150 | workloadFactory, |
| 151 | memoryManager, |
| 152 | shape0, |
| 153 | input0, |
| 154 | shape1, |
| 155 | input1, |
| 156 | shape0, |
| 157 | output); |
| 158 | } |
| 159 | |
| 160 | LayerTestResult<uint8_t, 4> EqualBroadcast1DVectorUint8Test( |
| 161 | armnn::IWorkloadFactory& workloadFactory, |
| 162 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 163 | { |
| 164 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 165 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 166 | |
| 167 | std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6, |
| 168 | 7, 8, 9, 10, 11, 12 }); |
| 169 | |
| 170 | std::vector<uint8_t> input1({ 1, 1, 3}); |
| 171 | |
| 172 | std::vector<uint8_t> output({ 1, 0, 1, 0, 0, 0, |
| 173 | 0, 0, 0, 0, 0, 0 }); |
| 174 | |
| 175 | return ElementwiseTestHelper<4, |
| 176 | armnn::EqualQueueDescriptor, |
| 177 | armnn::DataType::QuantisedAsymm8, |
| 178 | armnn::DataType::Boolean>( |
| 179 | workloadFactory, |
| 180 | memoryManager, |
| 181 | shape0, |
| 182 | input0, |
| 183 | shape1, |
| 184 | input1, |
| 185 | shape0, |
| 186 | output); |
| 187 | } |