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