blob: 59fc4608694685b6a47eb52849d75db05b64ff84 [file] [log] [blame]
Pablo Tello2fdc4092017-11-23 15:50:08 +00001/*
Matthew Bentham945b8da2023-07-12 11:54:59 +00002 * Copyright (c) 2017-2021, 2023 Arm Limited.
Pablo Tello2fdc4092017-11-23 15:50:08 +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_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 Tello2fdc4092017-11-23 15:50:08 +000034#include "tests/validation/Helpers.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000035#include "tests/validation/reference/GEMMInterleave4x4.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000036
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 GEMMInterleave4x4ValidationFixture : public framework::Fixture
Pablo Tello2fdc4092017-11-23 15:50:08 +000047{
48public:
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010049 void setup(size_t x, size_t y, DataType data_type)
Pablo Tello2fdc4092017-11-23 15:50:08 +000050 {
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010051 _data_type = data_type;
Pablo Tello2fdc4092017-11-23 15:50:08 +000052 const TensorShape shape_a(x, y);
53 const TensorShape shape_b(static_cast<size_t>(x * 4.f), static_cast<size_t>(std::ceil(y / 4.f)));
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010054 _target = compute_target(shape_a, shape_b, data_type);
55 _reference = compute_reference(shape_a, shape_b, data_type);
Pablo Tello2fdc4092017-11-23 15:50:08 +000056 }
57
58protected:
59 template <typename U>
60 void fill(U &&tensor, int i)
61 {
62 switch(tensor.data_type())
63 {
64 case DataType::F16:
Giorgio Arena6aeb2172020-12-15 15:45:43 +000065 {
Giorgio Arenaa8e2aeb2021-01-06 11:34:57 +000066 arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ -1.0f, 1.0f };
Giorgio Arena6aeb2172020-12-15 15:45:43 +000067 library->fill(tensor, distribution, i);
68 break;
69 }
Pablo Tello2fdc4092017-11-23 15:50:08 +000070 case DataType::F32:
71 {
Giorgio Arena6aeb2172020-12-15 15:45:43 +000072 std::uniform_real_distribution<float> distribution(-1.0f, 1.0f);
Pablo Tello2fdc4092017-11-23 15:50:08 +000073 library->fill(tensor, distribution, i);
74 break;
75 }
76 default:
77 library->fill_tensor_uniform(tensor, i);
78 break;
79 }
80 }
81
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010082 TensorType compute_target(const TensorShape &shape_a, const TensorShape &shape_b, DataType data_type)
Pablo Tello2fdc4092017-11-23 15:50:08 +000083 {
84 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010085 TensorType a = create_tensor<TensorType>(shape_a, data_type, 1);
86 TensorType b = create_tensor<TensorType>(shape_b, data_type, 1);
Pablo Tello2fdc4092017-11-23 15:50:08 +000087
88 // Create and configure function
89 FunctionType f;
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010090 f.configure(a.info(), b.info());
Pablo Tello2fdc4092017-11-23 15:50:08 +000091
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010092 ARM_COMPUTE_ASSERT(a.info()->is_resizable());
93 ARM_COMPUTE_ASSERT(b.info()->is_resizable());
Pablo Tello2fdc4092017-11-23 15:50:08 +000094
95 // Allocate tensors
96 a.allocator()->allocate();
97 b.allocator()->allocate();
98
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010099 ARM_COMPUTE_ASSERT(!a.info()->is_resizable());
100 ARM_COMPUTE_ASSERT(!b.info()->is_resizable());
Pablo Tello2fdc4092017-11-23 15:50:08 +0000101
102 // Fill tensors
103 fill(AccessorType(a), 0);
104 fill(AccessorType(b), 0);
105
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100106 // Compute GEMM interleave kernel
107 ITensorPack tensors{ { ACL_SRC, &a }, { ACL_DST, &b } };
108 f.run(tensors);
Pablo Tello2fdc4092017-11-23 15:50:08 +0000109 return b;
110 }
111
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +0100112 SimpleTensor<T> compute_reference(const TensorShape &shape_a, const TensorShape &shape_b, DataType data_type)
Pablo Tello2fdc4092017-11-23 15:50:08 +0000113 {
114 // Create reference
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +0100115 SimpleTensor<T> a{ shape_a, data_type, 1 };
116 SimpleTensor<T> b{ shape_b, data_type, 1 };
Pablo Tello2fdc4092017-11-23 15:50:08 +0000117
118 // Fill reference
119 fill(a, 0);
120 fill(b, 0);
121
122 return reference::gemm_interleave_4x4<T>(a, b);
123 }
124
125 TensorType _target{};
126 SimpleTensor<T> _reference{};
Pablo Tello2fdc4092017-11-23 15:50:08 +0000127 DataType _data_type{};
128};
Pablo Tello2fdc4092017-11-23 15:50:08 +0000129} // namespace validation
130} // namespace test
131} // namespace arm_compute
132#endif /* ARM_COMPUTE_TEST_GEMM_INTERLEAVE_4X4_FIXTURE */