Compute Library
 22.11
ElementwiseKernelSelection.cpp
Go to the documentation of this file.
1 /*
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"
29 #include "tests/framework/Macros.h"
31 namespace arm_compute
32 {
33 namespace test
34 {
35 namespace validation
36 {
37 TEST_SUITE(NEON)
38 TEST_SUITE(KernelSelection)
39 
40 DATA_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,
45  })),
46  combine(framework::dataset::make("CpuExt", std::string("SVE")),
50  }))),
52 {
53  using namespace cpu::kernels;
54 
56  cpu_isa.neon = (cpu_ext == "NEON");
57  cpu_isa.sve = (cpu_ext == "SVE");
59 
60  const auto *selected_impl = CpuElementwiseUnaryKernel::get_implementation(DataTypeISASelectorData{ data_type, cpu_isa }, cpu::KernelSelectionType::Preferred);
61 
63 
64  std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_elementwise_unary";
65  std::string actual = selected_impl->name;
66 
68 }
69 
70 DATA_TEST_CASE(KernelSelection_elementwise_arithmetic, framework::DatasetMode::ALL, concat(concat(
71  combine(framework::dataset::make("CpuExt", std::string("NEON")),
78  })),
79  combine(framework::dataset::make("CpuExt", std::string("SVE")),
84  }))),
85  combine(framework::dataset::make("CpuExt", std::string("SVE2")),
88  }))),
90 {
91  using namespace cpu::kernels;
92 
94  cpu_isa.neon = (cpu_ext == "NEON");
95  cpu_isa.sve = (cpu_ext == "SVE");
96  cpu_isa.sve2 = (cpu_ext == "SVE2");
98 
99  const auto *selected_impl = CpuArithmeticKernel::get_implementation(
100  ElementwiseDataTypeISASelectorData{ data_type, cpu_isa, static_cast<int>(ArithmeticOperation::ADD) },
102 
104 
105  std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_arithmetic";
106  std::string actual = selected_impl->name;
107 
109 }
110 
111 DATA_TEST_CASE(KernelSelection_elementwise_comparison, framework::DatasetMode::ALL, concat(concat(
112  combine(framework::dataset::make("CpuExt", std::string("NEON")),
117  DataType::U8,
120  })),
121  combine(framework::dataset::make("CpuExt", std::string("SVE")),
127  }))),
128  combine(framework::dataset::make("CpuExt", std::string("SVE2")),
131  }))),
133 {
134  using namespace cpu::kernels;
135 
137  cpu_isa.neon = (cpu_ext == "NEON");
138  cpu_isa.sve = (cpu_ext == "SVE");
139  cpu_isa.sve2 = (cpu_ext == "SVE2");
141 
142  const auto *selected_impl = CpuComparisonKernel::get_implementation(
143  ElementwiseDataTypeISASelectorData{ data_type, cpu_isa, static_cast<int>(ComparisonOperation::Equal) },
145 
147 
148  std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_comparison";
149  std::string actual = selected_impl->name;
150 
152 }
153 
155 TEST_SUITE_END() // Neon
156 } // namespace validation
157 } // namespace test
158 } // namespace arm_compute
Retrieve the best implementation available for the given Cpu ISA, ignoring the build flags...
1 channel, 1 U8 per channel
const CpuCastKernel::CastKernel * selected_impl
Definition: Cast.cpp:205
1 channel, 1 F32 per channel
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:353
Copyright (c) 2017-2022 Arm Limited.
cpuinfo::CpuIsaInfo cpu_isa
Definition: Cast.cpp:207
std::string cpu_impl_dt(const DataType &data_type)
Returns the suffix string of CPU kernel implementation names based on the given data type...
Definition: Utils.h:1245
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
CPU ISA (Instruction Set Architecture) information.
Definition: CpuIsaInfo.h:37
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
1 channel, 1 S16 per channel
ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl)
ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS)
JoinDataset< T, U > concat(T &&dataset1, U &&dataset2)
Helper function to create a JoinDataset.
Definition: JoinDataset.h:160
quantized, asymmetric fixed-point 8-bit number signed
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65