Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "Globals.h" |
| 25 | #include "NEON/Helper.h" |
| 26 | #include "NEON/NEAccessor.h" |
Moritz Pflanzer | 5b51229 | 2017-06-21 15:54:07 +0100 | [diff] [blame] | 27 | #include "PaddingCalculator.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "TensorLibrary.h" |
| 29 | #include "TypePrinter.h" |
| 30 | #include "Utils.h" |
| 31 | #include "validation/Datasets.h" |
| 32 | #include "validation/Reference.h" |
| 33 | #include "validation/Validation.h" |
| 34 | |
| 35 | #include "arm_compute/core/Helpers.h" |
| 36 | #include "arm_compute/core/Types.h" |
| 37 | #include "arm_compute/runtime/NEON/functions/NEBitwiseOr.h" |
| 38 | #include "arm_compute/runtime/Tensor.h" |
| 39 | #include "arm_compute/runtime/TensorAllocator.h" |
| 40 | |
| 41 | #include "boost_wrapper.h" |
| 42 | |
| 43 | #include <random> |
| 44 | #include <string> |
| 45 | |
| 46 | using namespace arm_compute; |
| 47 | using namespace arm_compute::test; |
| 48 | using namespace arm_compute::test::neon; |
| 49 | using namespace arm_compute::test::validation; |
| 50 | |
| 51 | namespace |
| 52 | { |
| 53 | /** Compute Neon bitwise Or function. |
| 54 | * |
| 55 | * @param[in] shape Shape of the input and output tensors. |
| 56 | * |
| 57 | * @return Computed output tensor. |
| 58 | */ |
| 59 | Tensor compute_bitwise_or(const TensorShape &shape) |
| 60 | { |
| 61 | // Create tensors |
| 62 | Tensor src1 = create_tensor(shape, DataType::U8); |
| 63 | Tensor src2 = create_tensor(shape, DataType::U8); |
| 64 | Tensor dst = create_tensor(shape, DataType::U8); |
| 65 | |
| 66 | // Create and configure function |
| 67 | NEBitwiseOr bor; |
| 68 | bor.configure(&src1, &src2, &dst); |
| 69 | |
| 70 | // Allocate tensors |
| 71 | src1.allocator()->allocate(); |
| 72 | src2.allocator()->allocate(); |
| 73 | dst.allocator()->allocate(); |
| 74 | |
| 75 | BOOST_TEST(!src1.info()->is_resizable()); |
| 76 | BOOST_TEST(!src2.info()->is_resizable()); |
| 77 | BOOST_TEST(!dst.info()->is_resizable()); |
| 78 | |
| 79 | // Fill tensors |
| 80 | library->fill_tensor_uniform(NEAccessor(src1), 0); |
| 81 | library->fill_tensor_uniform(NEAccessor(src2), 1); |
| 82 | |
| 83 | // Compute function |
| 84 | bor.run(); |
| 85 | |
| 86 | return dst; |
| 87 | } |
| 88 | } // namespace |
| 89 | |
| 90 | #ifndef DOXYGEN_SKIP_THIS |
| 91 | BOOST_AUTO_TEST_SUITE(NEON) |
| 92 | BOOST_AUTO_TEST_SUITE(BitwiseOr) |
| 93 | |
| 94 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 95 | BOOST_DATA_TEST_CASE(Configuration, SmallShapes() + LargeShapes(), shape) |
| 96 | { |
| 97 | // Create tensors |
| 98 | Tensor src1 = create_tensor(shape, DataType::U8); |
| 99 | Tensor src2 = create_tensor(shape, DataType::U8); |
| 100 | Tensor dst = create_tensor(shape, DataType::U8); |
| 101 | |
| 102 | BOOST_TEST(src1.info()->is_resizable()); |
| 103 | BOOST_TEST(src2.info()->is_resizable()); |
| 104 | BOOST_TEST(dst.info()->is_resizable()); |
| 105 | |
| 106 | // Create and configure function |
| 107 | NEBitwiseOr bor; |
| 108 | bor.configure(&src1, &src2, &dst); |
| 109 | |
| 110 | // Validate valid region |
| 111 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 112 | validate(src1.info()->valid_region(), valid_region); |
| 113 | validate(src2.info()->valid_region(), valid_region); |
| 114 | validate(dst.info()->valid_region(), valid_region); |
| 115 | |
| 116 | // Validate padding |
Moritz Pflanzer | 2509fba | 2017-06-23 14:15:03 +0100 | [diff] [blame] | 117 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 118 | validate(src1.info()->padding(), padding); |
| 119 | validate(src2.info()->padding(), padding); |
| 120 | validate(dst.info()->padding(), padding); |
| 121 | } |
| 122 | |
| 123 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 124 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape) |
| 125 | { |
| 126 | // Compute function |
| 127 | Tensor dst = compute_bitwise_or(shape); |
| 128 | |
| 129 | // Compute reference |
| 130 | RawTensor ref_dst = Reference::compute_reference_bitwise_or(shape); |
| 131 | |
| 132 | // Validate output |
| 133 | validate(NEAccessor(dst), ref_dst); |
| 134 | } |
| 135 | |
| 136 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 137 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(), shape) |
| 138 | { |
| 139 | // Compute function |
| 140 | Tensor dst = compute_bitwise_or(shape); |
| 141 | |
| 142 | // Compute reference |
| 143 | RawTensor ref_dst = Reference::compute_reference_bitwise_or(shape); |
| 144 | |
| 145 | // Validate output |
| 146 | validate(NEAccessor(dst), ref_dst); |
| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_SUITE_END() |
| 150 | BOOST_AUTO_TEST_SUITE_END() |
| 151 | #endif |