aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/kernels/CLMemsetKernel.cpp
diff options
context:
space:
mode:
authorGeorge Wort <george.wort@arm.com>2019-02-15 15:12:52 +0000
committerManuel Bottini <manuel.bottini@arm.com>2019-03-13 13:54:10 +0000
commit894066de8cc26d1a3aca62dcaa6b30a2a1116028 (patch)
tree9dcb227018ea69fcfb83f7b25be2009fdd16e18e /src/core/CL/kernels/CLMemsetKernel.cpp
parentadfb2737046028c042f0aecaff87733a442da29f (diff)
downloadComputeLibrary-894066de8cc26d1a3aca62dcaa6b30a2a1116028.tar.gz
COMPMID-1844: Implement CLCrop
Change-Id: I8822c37adc45960705dc3f32a53214795ba3cf39 Signed-off-by: George Wort <george.wort@arm.com> Reviewed-on: https://review.mlplatform.org/c/789 Reviewed-by: Manuel Bottini <manuel.bottini@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Marquez <pablo.tello@arm.com>
Diffstat (limited to 'src/core/CL/kernels/CLMemsetKernel.cpp')
-rw-r--r--src/core/CL/kernels/CLMemsetKernel.cpp47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/core/CL/kernels/CLMemsetKernel.cpp b/src/core/CL/kernels/CLMemsetKernel.cpp
index ab53897543..80caf9406e 100644
--- a/src/core/CL/kernels/CLMemsetKernel.cpp
+++ b/src/core/CL/kernels/CLMemsetKernel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 ARM Limited.
+ * Copyright (c) 2018-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -35,27 +35,38 @@
namespace arm_compute
{
CLMemsetKernel::CLMemsetKernel()
- : ICLKernel(), _tensor(nullptr)
+ : ICLKernel(), _tensor(nullptr), _full_window()
{
}
void CLMemsetKernel::configure(ICLTensor *tensor,
- const PixelValue &constant_value)
+ const PixelValue &constant_value,
+ Window *window)
{
ARM_COMPUTE_ERROR_ON_NULLPTR(tensor);
+ ARM_COMPUTE_ERROR_THROW_ON(validate(tensor->info(), constant_value, window));
+
_tensor = tensor;
- const DataType data_type = tensor->info()->data_type();
- const int vec_size_x = 16 / tensor->info()->element_size();
- const int output_width_x = tensor->info()->tensor_shape().x();
- const bool multi_access_x = (output_width_x / vec_size_x > 0);
+ const DataType data_type = tensor->info()->data_type();
+ const int vec_size_x = 16 / tensor->info()->element_size();
// Create and update the window (if needed)
- Window win = calculate_max_window(*tensor->info());
+ _full_window = calculate_max_window(*tensor->info());
+ Window win = _full_window;
+ if(window != nullptr)
+ {
+ ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(win, *window);
+ win = *window;
+ }
+
+ const int output_width_x = win.num_iterations(0);
+ const bool multi_access_x = output_width_x >= vec_size_x;
+ const bool remainder_x = output_width_x % vec_size_x > 0;
+
if(multi_access_x)
{
- win.set(Window::DimX,
- Window::Dimension(win.x().start(), ceil_to_multiple(win.x().end(), vec_size_x), vec_size_x));
+ win.set(Window::DimX, Window::Dimension(win.x().start(), ceil_to_multiple(win.x().end(), vec_size_x), vec_size_x));
}
ICLKernel::configure_internal(win);
@@ -64,14 +75,18 @@ void CLMemsetKernel::configure(ICLTensor *tensor,
build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
build_opts.add_option("-DCONSTANT_VALUE=" + string_from_pixel_value(constant_value, data_type));
build_opts.add_option_if(multi_access_x, "-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
- build_opts.add_option_if(multi_access_x, "-DLAST_ACCESSED_X=" + support::cpp11::to_string(std::max<int>(output_width_x - vec_size_x, 0)));
+ build_opts.add_option_if(multi_access_x && remainder_x, "-DLAST_ACCESSED_X=" + support::cpp11::to_string(std::max<int>(output_width_x - vec_size_x, 0)));
_kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("memset", build_opts.options()));
}
-Status CLMemsetKernel::validate(const ITensorInfo *tensor, const PixelValue &constant_value)
+Status CLMemsetKernel::validate(const ITensorInfo *tensor, const PixelValue &constant_value, Window *window)
{
ARM_COMPUTE_UNUSED(tensor);
ARM_COMPUTE_UNUSED(constant_value);
+ if(window != nullptr)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON(window->x().step() != 1);
+ }
return Status{};
}
@@ -81,15 +96,15 @@ void CLMemsetKernel::run(const Window &window, cl::CommandQueue &queue)
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
// Collapse all the batches on the third
- Window collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimY);
- Window slice = collapsed.first_slice_window_2D();
+ Window collapsed = window.collapse_if_possible(_full_window, Window::DimZ);
+ Window slice = collapsed.first_slice_window_3D();
do
{
unsigned int idx = 0;
- add_2D_tensor_argument(idx, _tensor, slice);
+ add_3D_tensor_argument(idx, _tensor, slice);
enqueue(queue, *this, slice);
}
- while(collapsed.slide_window_slice_2D(slice));
+ while(collapsed.slide_window_slice_3D(slice));
}
} // namespace arm_compute