2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Copyright (c) 2018-2020 ARM Limited.
20 * SPDX-License-Identifier: MIT
22 * Permission is hereby granted, free of charge, to any person obtaining a copy
23 * of this software and associated documentation files (the "Software"), to
24 * deal in the Software without restriction, including without limitation the
25 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
26 * sell copies of the Software, and to permit persons to whom the Software is
27 * furnished to do so, subject to the following conditions:
29 * The above copyright notice and this permission notice shall be included in all
30 * copies or substantial portions of the Software.
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 #include "arm_compute/core/CL/kernels/CLCastBoolKernel.h"
42 #include "arm_compute/core/CL/CLHelpers.h"
43 #include "arm_compute/core/CL/CLKernelLibraryEx.h"
44 #include "arm_compute/core/CL/CLValidate.h"
45 #include "arm_compute/core/CL/ICLTensor.h"
46 #include "arm_compute/core/CL/OpenCL.h"
47 #include "arm_compute/core/Error.h"
48 #include "arm_compute/core/TensorInfo.h"
49 #include "arm_compute/core/Utils.h"
50 #include "arm_compute/core/Validate.h"
51 #include "support/StringSupport.h"
61 Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
63 ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(output);
64 ARM_COMPUTE_RETURN_ERROR_ON(input == output);
65 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
66 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8, DataType::S8,
67 DataType::S16, DataType::U16, DataType::U32,
68 DataType::S32, DataType::F16, DataType::F32);
69 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == output->data_type(),
70 "Input and output data types must be different");
72 // Validate in case of configured output
73 if (output->total_size() > 0)
75 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
82 void CLCastBoolKernel::configure(const ICLTensor *input, ICLTensor *output)
84 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
86 // Auto initialize output shape if not initialized (We can only auto-configure the shape, datatype
88 set_shape_if_empty(*output->info(), input->info()->tensor_shape());
90 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
92 // Get number of elements to process per iterations
93 constexpr unsigned int num_elems_processed_per_iteration = 16;
96 CLBuildOptions build_opts;
97 build_opts.add_option("-DVEC_SIZE=" +
98 support::cpp11::to_string(num_elems_processed_per_iteration));
99 build_opts.add_option("-DDATA_TYPE_IN=" + get_cl_type_from_data_type(input->info()->data_type()));
100 build_opts.add_option("-DDATA_TYPE_OUT=" +
101 get_cl_type_from_data_type(output->info()->data_type()));
104 const std::string kernel_name = "cast_bool";
105 _kernel = static_cast<cl::Kernel>(
106 CLKernelLibraryEx::get().create_kernel(kernel_name, build_opts.options()));
109 ICLSimple2DKernel::configure(input, output, num_elems_processed_per_iteration);
112 const Window &full_window = window();
113 Window collapsed_window = full_window.collapse_if_possible(full_window, Window::DimZ);
114 ICLKernel::configure_internal(collapsed_window);
116 // Set config_id for enabling LWS tuning
117 _config_id = kernel_name;
119 _config_id += lower_string(string_from_data_type(output->info()->data_type()));
121 _config_id += support::cpp11::to_string(output->info()->dimension(0));
123 _config_id += support::cpp11::to_string(output->info()->dimension(1));
126 Status CLCastBoolKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
128 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
132 } // namespace arm_compute