Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 1 | /* |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +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_INTERLEAVE_4X4_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_GEMM_INTERLEAVE_4X4_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" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 34 | #include "tests/validation/Helpers.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 35 | #include "tests/validation/reference/GEMMInterleave4x4.h" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 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 GEMMInterleave4x4ValidationFixture : public framework::Fixture |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 47 | { |
| 48 | public: |
| 49 | template <typename...> |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 50 | void setup(size_t x, size_t y, DataType data_type) |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 51 | { |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 52 | _data_type = data_type; |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 53 | const TensorShape shape_a(x, y); |
| 54 | const TensorShape shape_b(static_cast<size_t>(x * 4.f), static_cast<size_t>(std::ceil(y / 4.f))); |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 55 | _target = compute_target(shape_a, shape_b, data_type); |
| 56 | _reference = compute_reference(shape_a, shape_b, data_type); |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +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: |
| 66 | case DataType::F32: |
| 67 | { |
| 68 | std::uniform_real_distribution<> distribution(-1.f, 1.f); |
| 69 | library->fill(tensor, distribution, i); |
| 70 | break; |
| 71 | } |
| 72 | default: |
| 73 | library->fill_tensor_uniform(tensor, i); |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 78 | TensorType compute_target(const TensorShape &shape_a, const TensorShape &shape_b, DataType data_type) |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 79 | { |
| 80 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 81 | TensorType a = create_tensor<TensorType>(shape_a, data_type, 1); |
| 82 | TensorType b = create_tensor<TensorType>(shape_b, data_type, 1); |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 83 | |
| 84 | // Create and configure function |
| 85 | FunctionType f; |
| 86 | f.configure(&a, &b); |
| 87 | |
| 88 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 89 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 90 | |
| 91 | // Allocate tensors |
| 92 | a.allocator()->allocate(); |
| 93 | b.allocator()->allocate(); |
| 94 | |
| 95 | ARM_COMPUTE_EXPECT(!a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 96 | ARM_COMPUTE_EXPECT(!b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 97 | |
| 98 | // Fill tensors |
| 99 | fill(AccessorType(a), 0); |
| 100 | fill(AccessorType(b), 0); |
| 101 | |
| 102 | // Compute GEMM function |
| 103 | f.run(); |
| 104 | return b; |
| 105 | } |
| 106 | |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 107 | SimpleTensor<T> compute_reference(const TensorShape &shape_a, const TensorShape &shape_b, DataType data_type) |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 108 | { |
| 109 | // Create reference |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 110 | SimpleTensor<T> a{ shape_a, data_type, 1 }; |
| 111 | SimpleTensor<T> b{ shape_b, data_type, 1 }; |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 112 | |
| 113 | // Fill reference |
| 114 | fill(a, 0); |
| 115 | fill(b, 0); |
| 116 | |
| 117 | return reference::gemm_interleave_4x4<T>(a, b); |
| 118 | } |
| 119 | |
| 120 | TensorType _target{}; |
| 121 | SimpleTensor<T> _reference{}; |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 122 | DataType _data_type{}; |
| 123 | }; |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 124 | } // namespace validation |
| 125 | } // namespace test |
| 126 | } // namespace arm_compute |
| 127 | #endif /* ARM_COMPUTE_TEST_GEMM_INTERLEAVE_4X4_FIXTURE */ |