Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13: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 | */ |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 28 | #include "src/core/gpu/cl/kernels/ClGemmReshapeLhsMatrixKernel.h" |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 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/GEMMReshapeLHSMatrixFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 45 | using namespace arm_compute::misc::shape_calculator; |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 46 | using namespace arm_compute::opencl::kernels; |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 47 | |
| 48 | // Initialize the output tensor with zero and fill the border with zero |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 49 | using CLGEMMReshapeLHSMatrix = CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder<ClGemmReshapeLhsMatrixKernel, 16>; |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 50 | |
| 51 | template <typename T> |
| 52 | using CLGEMMReshapeLHSMatrixFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, false>; |
| 53 | |
| 54 | // Fixture to use when the input has to be reinterpreted as 3D |
| 55 | template <typename T> |
| 56 | using CLGEMMReshapeLHSMatrix3DFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, true>; |
| 57 | |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 58 | // *INDENT-OFF* |
| 59 | // clang-format off |
| 60 | /** Data types */ |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 61 | |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 62 | namespace |
| 63 | { |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 64 | /** Batch size values to test */ |
| 65 | const auto b_values = framework::dataset::make("batchsize", 1, 3); |
| 66 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 67 | /** M0 values to test */ |
| 68 | const auto m0_values_s32 = framework::dataset::make("M0", { 2, 3 }); |
| 69 | const auto m0_values_s16 = framework::dataset::make("M0", { 4, 5 }); |
| 70 | const auto m0_values_s8 = framework::dataset::make("M0", { 6, 7, 8 }); |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 71 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 72 | /** K0 values to test */ |
| 73 | const auto k0_values_s32 = framework::dataset::make("K0", { 2, 3 }); |
| 74 | const auto k0_values_s16 = framework::dataset::make("K0", { 4, 8 }); |
| 75 | const auto k0_values_s8 = framework::dataset::make("K0", { 16 }); |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 76 | |
| 77 | /** V0 values to test */ |
| 78 | const auto v0_values = framework::dataset::make("V0", 1, 4); |
| 79 | |
| 80 | /** Interleave values to test */ |
| 81 | const auto i_values = framework::dataset::make("interleave", { true, false }); |
| 82 | |
| 83 | /** Transpose values to test */ |
| 84 | const auto t_values = framework::dataset::make("transpose", { true, false }); |
Gian Marco Iodice | 73cdaac | 2020-08-10 21:44:14 +0100 | [diff] [blame] | 85 | |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 86 | } // namespace |
| 87 | |
| 88 | TEST_SUITE(CL) |
| 89 | TEST_SUITE(GEMMReshapeLHSMatrix) |
Gian Marco Iodice | 73cdaac | 2020-08-10 21:44:14 +0100 | [diff] [blame] | 90 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 91 | FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrixFixture<int>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 92 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 93 | b_values), |
| 94 | framework::dataset::make("DataType", DataType::S32)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 95 | m0_values_s32), |
| 96 | k0_values_s32), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 97 | v0_values), |
| 98 | i_values), |
| 99 | t_values)) |
| 100 | { |
| 101 | // Validate output |
| 102 | validate(CLAccessor(_target), _reference); |
| 103 | } |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 104 | FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrixFixture<short>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 105 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 106 | b_values), |
| 107 | framework::dataset::make("DataType", DataType::S16)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 108 | m0_values_s16), |
| 109 | k0_values_s16), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 110 | v0_values), |
| 111 | i_values), |
| 112 | t_values)) |
| 113 | { |
| 114 | // Validate output |
| 115 | validate(CLAccessor(_target), _reference); |
| 116 | } |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 117 | FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrixFixture<char>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 118 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 119 | b_values), |
| 120 | framework::dataset::make("DataType", DataType::S8)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 121 | m0_values_s8), |
| 122 | k0_values_s8), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 123 | v0_values), |
| 124 | i_values), |
| 125 | t_values)) |
| 126 | { |
| 127 | // Validate output |
| 128 | validate(CLAccessor(_target), _reference); |
| 129 | } |
| 130 | |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 131 | TEST_SUITE(ReinterpretInputAs3D) |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 132 | FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrix3DFixture<int>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 133 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), |
| 134 | b_values), |
| 135 | framework::dataset::make("DataType", DataType::S32)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 136 | m0_values_s32), |
| 137 | k0_values_s32), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 138 | v0_values), |
| 139 | i_values), |
| 140 | t_values)) |
| 141 | { |
| 142 | // Validate output |
| 143 | validate(CLAccessor(_target), _reference); |
| 144 | } |
| 145 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 146 | FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrix3DFixture<short>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 147 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), |
| 148 | b_values), |
| 149 | framework::dataset::make("DataType", DataType::S16)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 150 | m0_values_s16), |
| 151 | k0_values_s16), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 152 | v0_values), |
| 153 | i_values), |
| 154 | t_values)) |
| 155 | { |
| 156 | // Validate output |
| 157 | validate(CLAccessor(_target), _reference); |
| 158 | } |
| 159 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 160 | FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrix3DFixture<char>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 161 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), |
| 162 | b_values), |
| 163 | framework::dataset::make("DataType", DataType::S8)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 164 | m0_values_s8), |
| 165 | k0_values_s8), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 166 | v0_values), |
| 167 | i_values), |
| 168 | t_values)) |
| 169 | { |
| 170 | // Validate output |
| 171 | validate(CLAccessor(_target), _reference); |
| 172 | } |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 173 | TEST_SUITE_END() // ReinterpretInputAs3D |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 174 | TEST_SUITE_END() // GEMMReshapeLHSMatrix |
| 175 | TEST_SUITE_END() // CL |
| 176 | } // namespace validation |
| 177 | } // namespace test |
Gian Marco Iodice | 73cdaac | 2020-08-10 21:44:14 +0100 | [diff] [blame] | 178 | } // namespace arm_compute |