Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | 945b8da | 2023-07-12 11:54:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, 2023 Arm Limited. |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +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 | #ifndef ARM_COMPUTE_TEST_GEMM_TRANSPOSE_1XW_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_GEMM_TRANSPOSE_1XW_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "tests/AssetsLibrary.h" |
| 30 | #include "tests/Globals.h" |
| 31 | #include "tests/IAccessor.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Fixture.h" |
| 34 | #include "tests/validation/Helpers.h" |
| 35 | #include "tests/validation/reference/GEMMTranspose1xW.h" |
| 36 | |
| 37 | #include <random> |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
Giorgio Arena | c3b2e07 | 2018-08-10 16:27:11 +0100 | [diff] [blame] | 46 | class GEMMTranspose1xWValidationFixture : public framework::Fixture |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 47 | { |
| 48 | public: |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 49 | void setup(size_t x, size_t y, DataType data_type) |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 50 | { |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 51 | _data_type = data_type; |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 52 | const TensorShape shape_a(x, y); |
| 53 | const unsigned int transpose_w = 16 / data_size_from_type(data_type); |
| 54 | const TensorShape shape_b(static_cast<size_t>(y * transpose_w), static_cast<size_t>(std::ceil(x / static_cast<float>(transpose_w)))); |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 55 | _target = compute_target(shape_a, shape_b, data_type); |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 56 | _reference = compute_reference(shape_a, data_type); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | protected: |
| 60 | template <typename U> |
| 61 | void fill(U &&tensor, int i) |
| 62 | { |
| 63 | switch(tensor.data_type()) |
| 64 | { |
| 65 | case DataType::F16: |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 66 | { |
Giorgio Arena | a8e2aeb | 2021-01-06 11:34:57 +0000 | [diff] [blame] | 67 | arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ -1.0f, 1.0f }; |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 68 | library->fill(tensor, distribution, i); |
| 69 | break; |
| 70 | } |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 71 | case DataType::F32: |
| 72 | { |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 73 | std::uniform_real_distribution<float> distribution(-1.0f, 1.0f); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 74 | library->fill(tensor, distribution, i); |
| 75 | break; |
| 76 | } |
| 77 | default: |
| 78 | library->fill_tensor_uniform(tensor, i); |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 83 | TensorType compute_target(const TensorShape &shape_a, const TensorShape &shape_b, DataType data_type) |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 84 | { |
| 85 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 86 | TensorType a = create_tensor<TensorType>(shape_a, data_type, 1); |
| 87 | TensorType b = create_tensor<TensorType>(shape_b, data_type, 1); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 88 | |
| 89 | // Create and configure function |
| 90 | FunctionType f; |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 91 | f.configure(a.info(), b.info()); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 92 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 93 | ARM_COMPUTE_ASSERT(a.info()->is_resizable()); |
| 94 | ARM_COMPUTE_ASSERT(b.info()->is_resizable()); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 95 | |
| 96 | // Allocate tensors |
| 97 | a.allocator()->allocate(); |
| 98 | b.allocator()->allocate(); |
| 99 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 100 | ARM_COMPUTE_ASSERT(!a.info()->is_resizable()); |
| 101 | ARM_COMPUTE_ASSERT(!b.info()->is_resizable()); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 102 | |
| 103 | // Fill tensors |
| 104 | fill(AccessorType(a), 0); |
| 105 | fill(AccessorType(b), 1); |
| 106 | |
| 107 | // Compute GEMM function |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 108 | ITensorPack tensors{ { ACL_SRC, &a }, { ACL_DST, &b } }; |
| 109 | f.run(tensors); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 110 | |
| 111 | return b; |
| 112 | } |
| 113 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 114 | SimpleTensor<T> compute_reference(const TensorShape &shape_a, DataType data_type) |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 115 | { |
| 116 | // Create reference |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 117 | SimpleTensor<T> a{ shape_a, data_type, 1 }; |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 118 | |
| 119 | // Fill reference |
| 120 | fill(a, 0); |
| 121 | |
| 122 | return reference::gemm_transpose_1xW<T>(a); |
| 123 | } |
| 124 | |
| 125 | TensorType _target{}; |
| 126 | SimpleTensor<T> _reference{}; |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 127 | DataType _data_type{}; |
| 128 | }; |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 129 | } // namespace validation |
| 130 | } // namespace test |
| 131 | } // namespace arm_compute |
| 132 | #endif /* ARM_COMPUTE_TEST_GEMM_TRANSPOSE_1XW_FIXTURE */ |