blob: 08f478fe2be81acfcd26daa0e7e6e92be1998912 [file] [log] [blame]
Pablo Tello088cc7f2017-12-07 15:20:55 +00001/*
Giorgio Arenab309fc22021-01-05 09:46:16 +00002 * Copyright (c) 2017-2021 Arm Limited.
Pablo Tello088cc7f2017-12-07 15:20:55 +00003 *
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
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Giorgio Arenac3b2e072018-08-10 16:27:11 +010046class GEMMTranspose1xWValidationFixture : public framework::Fixture
Pablo Tello088cc7f2017-12-07 15:20:55 +000047{
48public:
49 template <typename...>
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010050 void setup(size_t x, size_t y, DataType data_type)
Pablo Tello088cc7f2017-12-07 15:20:55 +000051 {
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010052 _data_type = data_type;
Pablo Tello088cc7f2017-12-07 15:20:55 +000053 const TensorShape shape_a(x, y);
54 const unsigned int transpose_w = 16 / data_size_from_type(data_type);
55 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 Loganathan014333d2018-07-02 09:13:49 +010056 _target = compute_target(shape_a, shape_b, data_type);
Michalis Spyrou6bff1952019-10-02 17:22:11 +010057 _reference = compute_reference(shape_a, data_type);
Pablo Tello088cc7f2017-12-07 15:20:55 +000058 }
59
60protected:
61 template <typename U>
62 void fill(U &&tensor, int i)
63 {
64 switch(tensor.data_type())
65 {
66 case DataType::F16:
Giorgio Arena6aeb2172020-12-15 15:45:43 +000067 {
Giorgio Arenaa8e2aeb2021-01-06 11:34:57 +000068 arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ -1.0f, 1.0f };
Giorgio Arena6aeb2172020-12-15 15:45:43 +000069 library->fill(tensor, distribution, i);
70 break;
71 }
Pablo Tello088cc7f2017-12-07 15:20:55 +000072 case DataType::F32:
73 {
Giorgio Arena6aeb2172020-12-15 15:45:43 +000074 std::uniform_real_distribution<float> distribution(-1.0f, 1.0f);
Pablo Tello088cc7f2017-12-07 15:20:55 +000075 library->fill(tensor, distribution, i);
76 break;
77 }
78 default:
79 library->fill_tensor_uniform(tensor, i);
80 break;
81 }
82 }
83
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010084 TensorType compute_target(const TensorShape &shape_a, const TensorShape &shape_b, DataType data_type)
Pablo Tello088cc7f2017-12-07 15:20:55 +000085 {
86 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010087 TensorType a = create_tensor<TensorType>(shape_a, data_type, 1);
88 TensorType b = create_tensor<TensorType>(shape_b, data_type, 1);
Pablo Tello088cc7f2017-12-07 15:20:55 +000089
90 // Create and configure function
91 FunctionType f;
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010092 f.configure(a.info(), b.info());
Pablo Tello088cc7f2017-12-07 15:20:55 +000093
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010094 ARM_COMPUTE_ASSERT(a.info()->is_resizable());
95 ARM_COMPUTE_ASSERT(b.info()->is_resizable());
Pablo Tello088cc7f2017-12-07 15:20:55 +000096
97 // Allocate tensors
98 a.allocator()->allocate();
99 b.allocator()->allocate();
100
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +0100101 ARM_COMPUTE_ASSERT(!a.info()->is_resizable());
102 ARM_COMPUTE_ASSERT(!b.info()->is_resizable());
Pablo Tello088cc7f2017-12-07 15:20:55 +0000103
104 // Fill tensors
105 fill(AccessorType(a), 0);
106 fill(AccessorType(b), 1);
107
108 // Compute GEMM function
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100109 ITensorPack tensors{ { ACL_SRC, &a }, { ACL_DST, &b } };
110 f.run(tensors);
Pablo Tello088cc7f2017-12-07 15:20:55 +0000111
112 return b;
113 }
114
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100115 SimpleTensor<T> compute_reference(const TensorShape &shape_a, DataType data_type)
Pablo Tello088cc7f2017-12-07 15:20:55 +0000116 {
117 // Create reference
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +0100118 SimpleTensor<T> a{ shape_a, data_type, 1 };
Pablo Tello088cc7f2017-12-07 15:20:55 +0000119
120 // Fill reference
121 fill(a, 0);
122
123 return reference::gemm_transpose_1xW<T>(a);
124 }
125
126 TensorType _target{};
127 SimpleTensor<T> _reference{};
Pablo Tello088cc7f2017-12-07 15:20:55 +0000128 DataType _data_type{};
129};
Pablo Tello088cc7f2017-12-07 15:20:55 +0000130} // namespace validation
131} // namespace test
132} // namespace arm_compute
133#endif /* ARM_COMPUTE_TEST_GEMM_TRANSPOSE_1XW_FIXTURE */