aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/kernels/CLBitwiseKernel.cpp
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2020-12-02 13:22:14 +0000
committerManuel Bottini <manuel.bottini@arm.com>2020-12-10 12:46:00 +0000
commit63bb7ca40e30b2db48d7bdd1adbc8223b53ac23c (patch)
treed831c217690d6d155c5ef426e42ee361d570ec59 /src/core/CL/kernels/CLBitwiseKernel.cpp
parent0b1c2db5c29ed80b7f4dd0c4fd6d4ed91b3d1538 (diff)
downloadComputeLibrary-63bb7ca40e30b2db48d7bdd1adbc8223b53ac23c.tar.gz
COMPMID-3921: Remove OpenCL Padding CLBitwiseKernel
Adding BitwiseOperation enum class Generalizing CL Bitwise kernels with a single CLBitwiseKernel Removing CL padding from CLBitwiseKernel Change-Id: I79cd79c1e425b6da7d52308a420edf8cfb7a5a36 Signed-off-by: Manuel Bottini <manuel.bottini@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4646 Reviewed-by: Giorgio Arena <giorgio.arena@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/CL/kernels/CLBitwiseKernel.cpp')
-rw-r--r--src/core/CL/kernels/CLBitwiseKernel.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/core/CL/kernels/CLBitwiseKernel.cpp b/src/core/CL/kernels/CLBitwiseKernel.cpp
new file mode 100644
index 0000000000..b1f7c00fac
--- /dev/null
+++ b/src/core/CL/kernels/CLBitwiseKernel.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2020 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "src/core/CL/kernels/CLBitwiseKernel.h"
+
+#include "arm_compute/core/CL/CLKernelLibrary.h"
+#include "arm_compute/core/CL/ICLTensor.h"
+#include "arm_compute/core/CL/OpenCL.h"
+#include "arm_compute/core/Helpers.h"
+#include "arm_compute/core/Validate.h"
+#include "src/core/helpers/AutoConfiguration.h"
+#include "src/core/helpers/WindowHelpers.h"
+#include "support/StringSupport.h"
+
+namespace arm_compute
+{
+CLBitwiseKernel::CLBitwiseKernel()
+ : _input1(nullptr), _input2(nullptr), _output(nullptr)
+{
+}
+
+void CLBitwiseKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, BitwiseOperation op)
+{
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input1);
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::U8);
+ if(op != BitwiseOperation::NOT)
+ {
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input2);
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input2, 1, DataType::U8);
+ }
+ ARM_COMPUTE_ERROR_ON_NULLPTR(output);
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8);
+
+ // Output auto inizialitation if not yet initialized
+ auto_init_if_empty(*(output->info()), *(input1->info()));
+ auto padding_info = get_padding_info({ input1, input2, output });
+
+ // Configure kernel window
+ const unsigned int vec_size_x = adjust_vec_size(16 / output->info()->element_size(), output->info()->dimension(0));
+ Window win = calculate_max_window(*output->info(), Steps(vec_size_x));
+
+ _input1 = input1;
+ _input2 = input2;
+ _output = output;
+
+ // Create kernel
+ std::string kernel_name = "";
+ switch(op)
+ {
+ case BitwiseOperation::AND:
+ kernel_name = "bitwise_and";
+ break;
+ case BitwiseOperation::NOT:
+ kernel_name = "bitwise_not";
+ break;
+ case BitwiseOperation::OR:
+ kernel_name = "bitwise_or";
+ break;
+ case BitwiseOperation::XOR:
+ kernel_name = "bitwise_xor";
+ break;
+ default:
+ ARM_COMPUTE_ERROR("Bitwise operation not supported");
+ }
+
+ CLBuildOptions build_opts;
+ const int vec_size_x_leftovers = output->info()->dimension(0) % vec_size_x;
+ build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
+ build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_x_leftovers));
+ _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
+
+ ICLKernel::configure_internal(win);
+ ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
+}
+
+void CLBitwiseKernel::run(const Window &window, cl::CommandQueue &queue)
+{
+ ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
+ ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
+
+ Window slice = window.first_slice_window_2D();
+
+ do
+ {
+ unsigned int idx = 0;
+ add_2D_tensor_argument(idx, _input1, slice);
+ if(_input2 != nullptr)
+ {
+ add_2D_tensor_argument(idx, _input2, slice);
+ }
+ add_2D_tensor_argument(idx, _output, slice);
+ enqueue(queue, *this, slice, lws_hint());
+ }
+ while(window.slide_window_slice_2D(slice));
+}
+} // namespace arm_compute \ No newline at end of file