blob: 78adc747fd28f571a5d82c791667046ef5a4ea79 [file] [log] [blame]
Dana Zlotnik6a2df882022-01-17 09:54:26 +02001/*
2 * Copyright (c) 2022 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#include "arm_compute/core/Types.h"
25#include "src/common/cpuinfo/CpuIsaInfo.h"
26#include "src/cpu/kernels/CpuElementwiseKernel.h"
27#include "src/cpu/kernels/CpuElementwiseUnaryKernel.h"
28#include "tests/framework/Asserts.h"
29#include "tests/framework/Macros.h"
30#include "tests/framework/datasets/Datasets.h"
31namespace arm_compute
32{
33namespace test
34{
35namespace validation
36{
37TEST_SUITE(NEON)
38TEST_SUITE(KernelSelection)
39
40DATA_TEST_CASE(KernelSelection_elementwise_unary, framework::DatasetMode::ALL, concat(
41 combine(framework::dataset::make("CpuExt", std::string("NEON")),
42 framework::dataset::make("DataType", { DataType::F32,
43 DataType::F16,
44 DataType::S32
45 })),
46 combine(framework::dataset::make("CpuExt", std::string("SVE")),
47 framework::dataset::make("DataType", { DataType::F32,
48 DataType::F16,
49 DataType::S32
50 }))),
51 cpu_ext, data_type)
52{
53 using namespace cpu::kernels;
54
55 cpuinfo::CpuIsaInfo cpu_isa{};
56 cpu_isa.neon = (cpu_ext == "NEON");
57 cpu_isa.sve = (cpu_ext == "SVE");
58 cpu_isa.fp16 = (data_type == DataType::F16);
59
60 const auto *selected_impl = CpuElementwiseUnaryKernel::get_implementation(DataTypeISASelectorData{ data_type, cpu_isa }, cpu::KernelSelectionType::Preferred);
61
62 ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl);
63
64 std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_elementwise_unary";
65 std::string actual = selected_impl->name;
66
67 ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS);
68}
69
70DATA_TEST_CASE(KernelSelection_elementwise_arithmetic, framework::DatasetMode::ALL, concat(concat(
71 combine(framework::dataset::make("CpuExt", std::string("NEON")),
72 framework::dataset::make("DataType", { DataType::F32,
73 DataType::F16,
74 DataType::S32,
75 DataType::S16,
76 DataType::QASYMM8,
77 DataType::QASYMM8_SIGNED
78 })),
79 combine(framework::dataset::make("CpuExt", std::string("SVE")),
80 framework::dataset::make("DataType", { DataType::F32,
81 DataType::F16,
82 DataType::S32,
83 DataType::S16
84 }))),
85 combine(framework::dataset::make("CpuExt", std::string("SVE2")),
86 framework::dataset::make("DataType", { DataType::QASYMM8,
87 DataType::QASYMM8_SIGNED
88 }))),
89 cpu_ext, data_type)
90{
91 using namespace cpu::kernels;
92
93 cpuinfo::CpuIsaInfo cpu_isa{};
94 cpu_isa.neon = (cpu_ext == "NEON");
95 cpu_isa.sve = (cpu_ext == "SVE");
96 cpu_isa.sve2 = (cpu_ext == "SVE2");
97 cpu_isa.fp16 = (data_type == DataType::F16);
98
99 const auto *selected_impl = CpuArithmeticKernel::get_implementation(
100 ElementwiseDataTypeISASelectorData{ data_type, cpu_isa, static_cast<int>(ArithmeticOperation::ADD) },
101 cpu::KernelSelectionType::Preferred);
102
103 ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl);
104
105 std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_arithmetic";
106 std::string actual = selected_impl->name;
107
108 ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS);
109}
110
111DATA_TEST_CASE(KernelSelection_elementwise_comparison, framework::DatasetMode::ALL, concat(concat(
112 combine(framework::dataset::make("CpuExt", std::string("NEON")),
113 framework::dataset::make("DataType", { DataType::F32,
114 DataType::F16,
115 DataType::S32,
116 DataType::S16,
117 DataType::U8,
118 DataType::QASYMM8,
119 DataType::QASYMM8_SIGNED
120 })),
121 combine(framework::dataset::make("CpuExt", std::string("SVE")),
122 framework::dataset::make("DataType", { DataType::F32,
123 DataType::F16,
124 DataType::S32,
125 DataType::S16,
126 DataType::U8
127 }))),
128 combine(framework::dataset::make("CpuExt", std::string("SVE2")),
129 framework::dataset::make("DataType", { DataType::QASYMM8,
130 DataType::QASYMM8_SIGNED
131 }))),
132 cpu_ext, data_type)
133{
134 using namespace cpu::kernels;
135
136 cpuinfo::CpuIsaInfo cpu_isa{};
137 cpu_isa.neon = (cpu_ext == "NEON");
138 cpu_isa.sve = (cpu_ext == "SVE");
139 cpu_isa.sve2 = (cpu_ext == "SVE2");
140 cpu_isa.fp16 = (data_type == DataType::F16);
141
142 const auto *selected_impl = CpuComparisonKernel::get_implementation(
143 ElementwiseDataTypeISASelectorData{ data_type, cpu_isa, static_cast<int>(ComparisonOperation::Equal) },
144 cpu::KernelSelectionType::Preferred);
145
146 ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl);
147
148 std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_comparison";
149 std::string actual = selected_impl->name;
150
151 ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS);
152}
153
154TEST_SUITE_END()
155TEST_SUITE_END() // Neon
156} // namespace validation
157} // namespace test
158} // namespace arm_compute