blob: 192a266f0fb419bf968aa89e6bc76191480ddd9a [file] [log] [blame]
Georgios Pinitas7900a9e2018-11-23 11:44:58 +00001/*
ramelg016d891572021-09-29 10:05:09 +01002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitas7900a9e2018-11-23 11:44:58 +00003 *
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/runtime/CL/functions/CLComparison.h"
25
26#include "arm_compute/core/CL/ICLTensor.h"
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000027#include "arm_compute/core/Types.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010028#include "src/core/CL/kernels/CLComparisonKernel.h"
29#include "src/core/CL/kernels/CLFillBorderKernel.h"
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000030
ramelg016d891572021-09-29 10:05:09 +010031#include "src/common/utils/Log.h"
32
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000033namespace arm_compute
34{
35void CLComparison::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ComparisonOperation operation)
36{
Manuel Bottini2b84be52020-04-08 10:15:51 +010037 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, operation);
38}
39
40void CLComparison::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ComparisonOperation operation)
41{
ramelg016d891572021-09-29 10:05:09 +010042 ARM_COMPUTE_LOG_PARAMS(input2, input2, output, operation);
Georgios Pinitas40f51a62020-11-21 03:04:18 +000043 auto k = std::make_unique<CLComparisonKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010044 k->configure(compile_context, input1, input2, output, operation);
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000045 _kernel = std::move(k);
46
47 if(output->info()->dimension(0) > 1)
48 {
49 ICLTensor *broadcasted_info = (input1->info()->dimension(0) == 1) ? input1 : input2;
50
51 if(broadcasted_info->info()->dimension(0) == 1)
52 {
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010053 _border_handler->configure(compile_context, broadcasted_info, _kernel->border_size(), BorderMode::REPLICATE);
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000054 }
55 }
56}
57
58Status CLComparison::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation operation)
59{
60 return CLComparisonKernel::validate(input1, input2, output, operation);
61}
62
63template <ComparisonOperation COP>
64void CLComparisonStatic<COP>::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
65{
Manuel Bottini2b84be52020-04-08 10:15:51 +010066 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output);
67}
68
69template <ComparisonOperation COP>
70void CLComparisonStatic<COP>::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
71{
Georgios Pinitas40f51a62020-11-21 03:04:18 +000072 auto k = std::make_unique<CLComparisonKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010073 k->configure(compile_context, input1, input2, output, COP);
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000074 _kernel = std::move(k);
75
76 if(output->info()->dimension(0) > 1)
77 {
78 ICLTensor *broadcasted_info = (input1->info()->dimension(0) == 1) ? input1 : input2;
79
80 if(broadcasted_info->info()->dimension(0) == 1)
81 {
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010082 _border_handler->configure(compile_context, broadcasted_info, _kernel->border_size(), BorderMode::REPLICATE);
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000083 }
84 }
85}
86
87template <ComparisonOperation COP>
88Status CLComparisonStatic<COP>::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
89{
90 return CLComparisonKernel::validate(input1, input2, output, COP);
91}
Georgios Pinitas83bbf772019-01-25 16:44:07 +000092
93// Supported Specializations
94template class CLComparisonStatic<ComparisonOperation::Equal>;
95template class CLComparisonStatic<ComparisonOperation::NotEqual>;
96template class CLComparisonStatic<ComparisonOperation::Greater>;
97template class CLComparisonStatic<ComparisonOperation::GreaterEqual>;
98template class CLComparisonStatic<ComparisonOperation::Less>;
99template class CLComparisonStatic<ComparisonOperation::LessEqual>;
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000100} // namespace arm_compute