blob: db1c8fd4ae8c3e4a48f4b46ed4637afeb4cc5341 [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"
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000028#include "common/Common.h"
Nikolaj Jensenacea4072023-07-03 09:44:42 +010029#include "src/TensorUtils.h"
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000030
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");
Nikolaj Jensenacea4072023-07-03 09:44:42 +010077 VALIDATE_ON_MSG(_layout.size() == _expected.size(),
78 "The number of layouts and expected outputs does not match");
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000079 const size_t num_tests = _layout.size();
80 for(size_t i = 0; i < num_tests; ++i)
81 {
82 const TensorDataLayout layout = _layout[i];
83 const TensorDataLayoutComponent component = _component[i];
84 const TensorComponent expected = _expected[i];
Nikolaj Jensenacea4072023-07-03 09:44:42 +010085 const TensorComponent out = get_tensor_dimension(layout, component);
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000086 VALIDATE_TEST(out == expected, all_tests_passed, i);
87 }
88 return all_tests_passed;
89 }
90
91 std::string name() override
92 {
93 return "UtilsTest";
94 }
95
96private:
Nikolaj Jensenacea4072023-07-03 09:44:42 +010097 std::vector<TensorDataLayout> _layout{};
98 std::vector<TensorDataLayoutComponent> _component{};
99 std::vector<TensorComponent> _expected{};
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000100};
Nikolaj Jensenacea4072023-07-03 09:44:42 +0100101} // namespace ckw
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000102
103#endif /* COMPUTE_KERNEL_WRITER_TESTS_UTILSTEST_HPP */