blob: 4a09d53f7315f7f1968d6004096d7bbaebea094f [file] [log] [blame]
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +00001/*
2 * Copyright (c) 2023 Arm Limited.
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 COMPUTE_KERNEL_WRITER_TESTS_UTILSTEST_HPP
25#define COMPUTE_KERNEL_WRITER_TESTS_UTILSTEST_HPP
26
27#include "ckw/TensorInfo.h"
28#include "src/TensorUtils.h"
29#include "common/Common.h"
30
31#include <vector>
32
33namespace ckw
34{
35class UtilsTest : public ITest
36{
37public:
38 UtilsTest()
39 {
40 _layout.push_back(TensorDataLayout::Nhwc);
41 _layout.push_back(TensorDataLayout::Nhwc);
42 _layout.push_back(TensorDataLayout::Nhwc);
43 _layout.push_back(TensorDataLayout::Nhwc);
44 _layout.push_back(TensorDataLayout::Ndhwc);
45 _layout.push_back(TensorDataLayout::Ndhwc);
46 _layout.push_back(TensorDataLayout::Ndhwc);
47 _layout.push_back(TensorDataLayout::Ndhwc);
48 _layout.push_back(TensorDataLayout::Ndhwc);
49
50 _component.push_back(TensorDataLayoutComponent::N);
51 _component.push_back(TensorDataLayoutComponent::H);
52 _component.push_back(TensorDataLayoutComponent::W);
53 _component.push_back(TensorDataLayoutComponent::C);
54 _component.push_back(TensorDataLayoutComponent::N);
55 _component.push_back(TensorDataLayoutComponent::D);
56 _component.push_back(TensorDataLayoutComponent::H);
57 _component.push_back(TensorDataLayoutComponent::W);
58 _component.push_back(TensorDataLayoutComponent::C);
59
60 _expected.push_back(TensorComponent::Dim3);
61 _expected.push_back(TensorComponent::Dim2);
62 _expected.push_back(TensorComponent::Dim1);
63 _expected.push_back(TensorComponent::Dim0);
64 _expected.push_back(TensorComponent::Dim4);
65 _expected.push_back(TensorComponent::Dim3);
66 _expected.push_back(TensorComponent::Dim2);
67 _expected.push_back(TensorComponent::Dim1);
68 _expected.push_back(TensorComponent::Dim0);
69 }
70
71 bool run() override
72 {
73 // The status of this variable can change in VALIDATE_TEST()
74 bool all_tests_passed = true;
75
76 VALIDATE_ON_MSG(_layout.size() == _component.size(), "The number of layouts and components does not match");
77 VALIDATE_ON_MSG(_layout.size() == _expected.size(), "The number of layouts and expected outputs does not match");
78 const size_t num_tests = _layout.size();
79 for(size_t i = 0; i < num_tests; ++i)
80 {
81 const TensorDataLayout layout = _layout[i];
82 const TensorDataLayoutComponent component = _component[i];
83 const TensorComponent expected = _expected[i];
84 const TensorComponent out = get_tensor_dimension(layout, component);
85 VALIDATE_TEST(out == expected, all_tests_passed, i);
86 }
87 return all_tests_passed;
88 }
89
90 std::string name() override
91 {
92 return "UtilsTest";
93 }
94
95private:
96 std::vector<TensorDataLayout> _layout {};
97 std::vector<TensorDataLayoutComponent> _component {};
98 std::vector<TensorComponent> _expected {};
99};
100}
101
102#endif /* COMPUTE_KERNEL_WRITER_TESTS_UTILSTEST_HPP */