Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 ARM Limited. |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 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 "arm_compute/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h" |
| 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 28 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/CL/Helper.h" |
| 31 | #include "tests/PaddingCalculator.h" |
| 32 | #include "tests/datasets/ShapeDatasets.h" |
| 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Macros.h" |
| 35 | #include "tests/framework/datasets/Datasets.h" |
| 36 | #include "tests/validation/Validation.h" |
| 37 | #include "tests/validation/fixtures/GEMMReshapeRHSMatrixFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | // *INDENT-OFF* |
| 48 | // clang-format off |
| 49 | /** Data types */ |
| 50 | const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 }); |
| 51 | |
| 52 | /** Batch size values to test */ |
| 53 | const auto b_values = framework::dataset::make("batchsize", 1, 3); |
| 54 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 55 | /** N0 values to test */ |
| 56 | const auto n0_values_nt_s32 = framework::dataset::make("N0", { 1, 2, 3 }); |
| 57 | const auto n0_values_nt_s16 = framework::dataset::make("N0", { 4, 8 }); |
| 58 | const auto n0_values_nt_s8 = framework::dataset::make("N0", { 16 }); |
| 59 | const auto n0_values_t_s32 = framework::dataset::make("N0", { 4, 8 }); |
| 60 | const auto n0_values_t_s16 = framework::dataset::make("N0", { 16 }); |
| 61 | const auto n0_values_t_s8 = framework::dataset::make("N0", { 2, 3 }); |
Gian Marco Iodice | 8912434 | 2018-12-19 14:17:22 +0000 | [diff] [blame] | 62 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 63 | /** K0 values to test */ |
| 64 | const auto k0_values_nt_s32 = framework::dataset::make("K0", { 1, 2 }); |
| 65 | const auto k0_values_nt_s16 = framework::dataset::make("K0", { 16 }); |
| 66 | const auto k0_values_nt_s8 = framework::dataset::make("K0", { 3,4 }); |
| 67 | const auto k0_values_t_s32 = framework::dataset::make("K0", { 2, 3 }); |
| 68 | const auto k0_values_t_s16 = framework::dataset::make("K0", { 4, 8 }); |
| 69 | const auto k0_values_t_s8 = framework::dataset::make("K0", { 16 }); |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 70 | |
| 71 | /** H0 values to test */ |
| 72 | const auto h0_values = framework::dataset::make("H0", 1, 4); |
| 73 | |
| 74 | /** Interleave values to test */ |
| 75 | const auto i_values = framework::dataset::make("interleave", { true, false }); |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 76 | } // namespace |
| 77 | |
| 78 | using namespace arm_compute::misc::shape_calculator; |
| 79 | |
| 80 | // Initialize the output tensor with zero and fill the border with zero |
| 81 | using CLGEMMReshapeRHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeRHSMatrixKernel, 16>; |
| 82 | |
| 83 | template <typename T> |
| 84 | using CLGEMMReshapeRHSMatrixFixture = GEMMReshapeRHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, T>; |
| 85 | |
| 86 | TEST_SUITE(CL) |
| 87 | TEST_SUITE(GEMMReshapeRHSMatrix) |
| 88 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 89 | // *INDENT-OFF* |
| 90 | // clang-format off |
| 91 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 92 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), |
| 93 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Mismatching data types |
| 94 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong n0 value |
| 95 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong k0 value |
| 96 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong h0 value |
| 97 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // n0 > 16 |
| 98 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 > 16 |
| 99 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 == 1 && transpose |
| 100 | }), |
| 101 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(64U, 2U, 2U), 1, DataType::F32), |
| 102 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F16), |
| 103 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 104 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 105 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 106 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 107 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 108 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 109 | })), |
| 110 | framework::dataset::make("N0",{ 4, 0, 4, 4, 4, 17, 4, 4 })), |
| 111 | framework::dataset::make("K0",{ 4, 4, 0, 4, 4, 4, 17, 1 })), |
| 112 | framework::dataset::make("H0",{ 4, 4, 4, 0, 4, 4, 4, 4 })), |
| 113 | framework::dataset::make("Expected", { false, false, false, false, false, false, false})), |
| 114 | input_info, output_info, n0, k0, h0, expected) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 115 | { |
| 116 | GEMMRHSMatrixInfo rhs_info; |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 117 | rhs_info.n0 = n0; |
| 118 | rhs_info.k0 = k0; |
| 119 | rhs_info.h0 = h0; |
| 120 | rhs_info.transpose = true; |
| 121 | rhs_info.interleave = true; |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 122 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 123 | bool has_error = bool(CLGEMMReshapeRHSMatrixKernel::validate(&input_info.clone()->set_is_resizable(false), (output_info.total_size() == 0) ? nullptr : &output_info.clone()->set_is_resizable(false), rhs_info)); |
| 124 | ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS); |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 125 | } |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 126 | // clang-format on |
| 127 | // *INDENT-ON* |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 128 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 129 | // Run S32 tests only for transpose = false |
| 130 | FIXTURE_DATA_TEST_CASE(S32_NT, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL, |
| 131 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 132 | b_values), |
| 133 | framework::dataset::make("DataType", DataType::S32)), |
| 134 | n0_values_nt_s32), |
| 135 | k0_values_nt_s32), |
| 136 | h0_values), |
| 137 | i_values), |
| 138 | framework::dataset::make("transpose", false))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 139 | { |
| 140 | // Validate output |
| 141 | validate(CLAccessor(_target), _reference); |
| 142 | } |
| 143 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 144 | // Run S32 tests only for transpose = true |
| 145 | FIXTURE_DATA_TEST_CASE(S32_T, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL, |
| 146 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 147 | b_values), |
| 148 | framework::dataset::make("DataType", DataType::S32)), |
| 149 | n0_values_t_s32), |
| 150 | k0_values_t_s32), |
| 151 | h0_values), |
| 152 | i_values), |
| 153 | framework::dataset::make("transpose", true))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 154 | { |
| 155 | // Validate output |
| 156 | validate(CLAccessor(_target), _reference); |
| 157 | } |
| 158 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 159 | // Run S16 tests only for transpose = false |
| 160 | FIXTURE_DATA_TEST_CASE(S16_NT, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL, |
| 161 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 162 | b_values), |
| 163 | framework::dataset::make("DataType", DataType::S16)), |
| 164 | n0_values_nt_s16), |
| 165 | k0_values_nt_s16), |
| 166 | h0_values), |
| 167 | i_values), |
| 168 | framework::dataset::make("transpose", false))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 169 | { |
| 170 | // Validate output |
| 171 | validate(CLAccessor(_target), _reference); |
| 172 | } |
| 173 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 174 | // Run S16 tests only for transpose = true |
| 175 | FIXTURE_DATA_TEST_CASE(S16_T, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL, |
| 176 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 177 | b_values), |
| 178 | framework::dataset::make("DataType", DataType::S16)), |
| 179 | n0_values_t_s16), |
| 180 | k0_values_t_s16), |
| 181 | h0_values), |
| 182 | i_values), |
| 183 | framework::dataset::make("transpose", true))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 184 | { |
| 185 | // Validate output |
| 186 | validate(CLAccessor(_target), _reference); |
| 187 | } |
| 188 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 189 | // Run S8 tests only for transpose = false |
| 190 | FIXTURE_DATA_TEST_CASE(S8_NT, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL, |
| 191 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 192 | b_values), |
| 193 | framework::dataset::make("DataType", DataType::S8)), |
| 194 | n0_values_nt_s8), |
| 195 | k0_values_nt_s8), |
| 196 | h0_values), |
| 197 | i_values), |
| 198 | framework::dataset::make("transpose", false))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 199 | { |
| 200 | // Validate output |
| 201 | validate(CLAccessor(_target), _reference); |
| 202 | } |
| 203 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 204 | // Run S8 tests only for transpose = true |
| 205 | FIXTURE_DATA_TEST_CASE(S8_T, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL, |
| 206 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 207 | b_values), |
| 208 | framework::dataset::make("DataType", DataType::S8)), |
| 209 | n0_values_t_s8), |
| 210 | k0_values_t_s8), |
| 211 | h0_values), |
| 212 | i_values), |
| 213 | framework::dataset::make("transpose", true))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 214 | { |
| 215 | // Validate output |
| 216 | validate(CLAccessor(_target), _reference); |
| 217 | } |
| 218 | |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 219 | TEST_SUITE_END() // GEMMReshapeRHSMatrix |
| 220 | TEST_SUITE_END() // CL |
| 221 | } // namespace validation |
| 222 | } // namespace test |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 223 | } // namespace arm_compute |