aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2020-11-25 18:38:05 +0000
committerManuel Bottini <manuel.bottini@arm.com>2020-12-01 16:52:55 +0000
commita243205179b0b884d59697fd900253b8d0d96f6a (patch)
treed806122f8e2cfd62381c1fc2b8aaa30e1f53b91b
parentf605bd202afb861c95693e9cefd34f8b063f107b (diff)
downloadComputeLibrary-a243205179b0b884d59697fd900253b8d0d96f6a.tar.gz
COMPMID-3916: Remove OpenCL padding CLRangeKernel
Change-Id: Id2cc77508b0f2fa36a298059476b01704cfbdcaf Signed-off-by: Manuel Bottini <manuel.bottini@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4580 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
-rw-r--r--src/core/CL/cl_kernels/range.cl125
-rw-r--r--src/core/CL/kernels/CLRangeKernel.cpp70
2 files changed, 77 insertions, 118 deletions
diff --git a/src/core/CL/cl_kernels/range.cl b/src/core/CL/cl_kernels/range.cl
index 1e5c77b376..5569101615 100644
--- a/src/core/CL/cl_kernels/range.cl
+++ b/src/core/CL/cl_kernels/range.cl
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 Arm Limited.
+ * Copyright (c) 2018-2020 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -23,13 +23,29 @@
*/
#include "helpers.h"
-#if defined(VECTOR_SIZE) && defined(START) && defined(STEP) && defined(DATA_TYPE)
+#if defined(VECTOR_SIZE) && defined(START) && defined(STEP) && defined(DATA_TYPE) && defined(VEC_SIZE_LEFTOVER)
+
+#if !defined(OFFSET_OUT) && !defined(SCALE_OUT)
+
+#if VECTOR_SIZE == 2
+#define STEP_VEC ((VEC_DATA_TYPE(DATA_TYPE, 2))(0, STEP))
+#elif VECTOR_SIZE == 3
+#define STEP_VEC ((VEC_DATA_TYPE(DATA_TYPE, 3))(0, STEP, 2 * STEP))
+#elif VECTOR_SIZE == 4
+#define STEP_VEC ((VEC_DATA_TYPE(DATA_TYPE, 4))(0, STEP, 2 * STEP, 3 * STEP))
+#elif VECTOR_SIZE == 8
+#define STEP_VEC ((VEC_DATA_TYPE(DATA_TYPE, 8))(0, STEP, 2 * STEP, 3 * STEP, 4 * STEP, 5 * STEP, 6 * STEP, 7 * STEP))
+#elif VECTOR_SIZE == 16
+#define STEP_VEC ((VEC_DATA_TYPE(DATA_TYPE, 16))(0, STEP, 2 * STEP, 3 * STEP, 4 * STEP, 5 * STEP, 6 * STEP, 7 * STEP, 8 * STEP, 9 * STEP, 10 * STEP, 11 * STEP, 12 * STEP, 13 * STEP, 14 * STEP, 15 * STEP))
+#endif // VECTOR_SIZE == 2
+
/** Generates a sequence of numbers starting from START and extends by increments of 'STEP' up to but not including 'END'.
*
* @note starting value of the sequence must be given as a preprocessor argument using -DSTART=value. e.g. -DSTART=0
* @note difference between consequtive elements of the sequence must be given as a preprocessor argument using -DSTEP=value. e.g. -DSTEP=1
* @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short
* @note vector size supported by the device must be given as a preprocessor argument using -DVECTOR_SIZE=value. e.g. -DDATA_TYPE=4
+ * @note Leftover vector size has to be passed at compile time using -DVEC_SIZE_LEFTOVER. e.g. -DVECTOR_SIZE=3. It is defined as the remainder between the input's first dimension and VECTOR_SIZE
*
* @param[out] out_ptr Pointer to the destination tensor. Supported data types: U8/S8/U16/S16/U32/S32/F16/F32.
* @param[in] out_stride_x Stride of the destination tensor in X dimension (in bytes)
@@ -39,45 +55,34 @@
__kernel void range(
VECTOR_DECLARATION(out))
{
- uint id = get_global_id(0) * VECTOR_SIZE;
- __global void *dst_ptr = out_ptr + out_offset_first_element_in_bytes + id * sizeof(DATA_TYPE);
+ uint id = max((int)(get_global_id(0) * VECTOR_SIZE - (VECTOR_SIZE - VEC_SIZE_LEFTOVER) % VECTOR_SIZE), 0);
+ __global DATA_TYPE *dst_ptr = out_ptr + out_offset_first_element_in_bytes + id * sizeof(DATA_TYPE);
#if VECTOR_SIZE == 1
DATA_TYPE seq;
seq = (DATA_TYPE)START + (DATA_TYPE)id * (DATA_TYPE)STEP;
- *((__global DATA_TYPE *)dst_ptr) = seq;
-#else // VECTOR_SIZE == 1
+ *dst_ptr = seq;
+#else // VECTOR_SIZE == 1
VEC_DATA_TYPE(DATA_TYPE, VECTOR_SIZE)
- seq;
-
- seq.s0 = ((DATA_TYPE)START + (DATA_TYPE)id * (DATA_TYPE)STEP);
-#if VECTOR_SIZE > 1
- seq.s1 = seq.s0 + (DATA_TYPE)STEP;
-#if VECTOR_SIZE > 2
- seq.s2 = seq.s1 + (DATA_TYPE)STEP;
-#if VECTOR_SIZE > 3
- seq.s3 = seq.s2 + (DATA_TYPE)STEP;
-#if VECTOR_SIZE > 4
- seq.s4 = seq.s3 + (DATA_TYPE)STEP;
-#if VECTOR_SIZE > 5
- seq.s5 = seq.s4 + (DATA_TYPE)STEP;
-#if VECTOR_SIZE > 6
- seq.s6 = seq.s5 + (DATA_TYPE)STEP;
-#if VECTOR_SIZE > 7
- seq.s7 = seq.s6 + (DATA_TYPE)STEP;
-#endif // VECTOR_SIZE > 7
-#endif // VECTOR_SIZE > 6
-#endif // VECTOR_SIZE > 5
-#endif // VECTOR_SIZE > 4
-#endif // VECTOR_SIZE > 3
-#endif // VECTOR_SIZE > 2
-#endif // VECTOR_SIZE > 1
- VSTORE(VECTOR_SIZE)
- (seq, 0, ((__global DATA_TYPE *)dst_ptr));
+ seq0 = ((DATA_TYPE)START + (DATA_TYPE)id * (DATA_TYPE)STEP);
+ seq0 = seq0 + STEP_VEC;
+ STORE_VECTOR_SELECT(seq, DATA_TYPE, dst_ptr, VECTOR_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)
#endif //VECTOR_SIZE == 1
}
-#if defined(OFFSET_OUT) && defined(SCALE_OUT)
+#else // !defined(OFFSET_OUT) && !defined(SCALE_OUT)
+
+#if VECTOR_SIZE == 2
+#define STEP_VEC ((VEC_DATA_TYPE(float, 2))(0, STEP))
+#elif VECTOR_SIZE == 3
+#define STEP_VEC ((VEC_DATA_TYPE(float, 3))(0, STEP, 2 * STEP))
+#elif VECTOR_SIZE == 4
+#define STEP_VEC ((VEC_DATA_TYPE(float, 4))(0, STEP, 2 * STEP, 3 * STEP))
+#elif VECTOR_SIZE == 8
+#define STEP_VEC ((VEC_DATA_TYPE(float, 8))(0, STEP, 2 * STEP, 3 * STEP, 4 * STEP, 5 * STEP, 6 * STEP, 7 * STEP))
+#elif VECTOR_SIZE == 16
+#define STEP_VEC ((VEC_DATA_TYPE(float, 16))(0, STEP, 2 * STEP, 3 * STEP, 4 * STEP, 5 * STEP, 6 * STEP, 7 * STEP, 8 * STEP, 9 * STEP, 10 * STEP, 11 * STEP, 12 * STEP, 13 * STEP, 14 * STEP, 15 * STEP))
+#endif // VECTOR_SIZE == 2
#define CONVERT_RTE(x, type) (convert_##type##_rte((x)))
#define CONVERT_DOWN(x, type) CONVERT_RTE(x, type)
@@ -99,47 +104,25 @@ __kernel void range(
__kernel void range_quantized(
VECTOR_DECLARATION(out))
{
- size_t id = get_global_id(0) * VECTOR_SIZE;
- __global void *dst_ptr = out_ptr + out_offset_first_element_in_bytes + id * sizeof(DATA_TYPE);
+ uint id = max((int)(get_global_id(0) * VECTOR_SIZE - (VECTOR_SIZE - VEC_SIZE_LEFTOVER) % VECTOR_SIZE), 0);
+ __global DATA_TYPE *dst_ptr = out_ptr + out_offset_first_element_in_bytes + id * sizeof(DATA_TYPE);
#if VECTOR_SIZE == 1
- float seq;
- seq = (float)START + (float)id * (float)STEP;
- seq = (DATA_TYPE)(int)(seq / ((float)SCALE_OUT) + (float)OFFSET_OUT);
- seq = max(0.0f, min(seq, 255.0f));
- *((__global uchar *)dst_ptr) = CONVERT_SAT(CONVERT_DOWN(seq, int), uchar);
-#else // VECTOR_SIZE == 1
+ float seq;
+ seq = (float)START + (float)id * (float)STEP;
+ seq = (DATA_TYPE)(int)(seq / ((float)SCALE_OUT) + (float)OFFSET_OUT);
+ seq = max(0.0f, min(seq, 255.0f));
+ *dst_ptr = CONVERT_SAT(CONVERT_DOWN(seq, int), uchar);
+#else // VECTOR_SIZE == 1
VEC_DATA_TYPE(float, VECTOR_SIZE)
- seq;
- seq.s0 = (float)START + id * (float)STEP;
-#if VECTOR_SIZE > 1
- seq.s1 = seq.s0 + (float)STEP;
-#if VECTOR_SIZE > 2
- seq.s2 = seq.s1 + (float)STEP;
-#if VECTOR_SIZE > 3
- seq.s3 = seq.s2 + (float)STEP;
-#if VECTOR_SIZE > 4
- seq.s4 = seq.s3 + (float)STEP;
-#if VECTOR_SIZE > 5
- seq.s5 = seq.s4 + (float)STEP;
-#if VECTOR_SIZE > 6
- seq.s6 = seq.s5 + (float)STEP;
-#if VECTOR_SIZE > 7
- seq.s7 = seq.s6 + (float)STEP;
-#endif // VECTOR_SIZE > 7
-#endif // VECTOR_SIZE > 6
-#endif // VECTOR_SIZE > 5
-#endif // VECTOR_SIZE > 4
-#endif // VECTOR_SIZE > 3
-#endif // VECTOR_SIZE > 2
-#endif // VECTOR_SIZE > 1
- seq = seq / ((VEC_DATA_TYPE(float, VECTOR_SIZE))((float)SCALE_OUT)) + ((VEC_DATA_TYPE(float, VECTOR_SIZE))((float)OFFSET_OUT));
- seq = max((VEC_DATA_TYPE(float, VECTOR_SIZE))(0.0f), min(seq, (VEC_DATA_TYPE(float, VECTOR_SIZE))(255.0f)));
+ seq = (float)START + id * (float)STEP;
+ seq = seq + STEP_VEC;
+ seq = seq / ((VEC_DATA_TYPE(float, VECTOR_SIZE))((float)SCALE_OUT)) + ((VEC_DATA_TYPE(float, VECTOR_SIZE))((float)OFFSET_OUT));
+ seq = max((VEC_DATA_TYPE(float, VECTOR_SIZE))(0.0f), min(seq, (VEC_DATA_TYPE(float, VECTOR_SIZE))(255.0f)));
VEC_DATA_TYPE(uchar, VECTOR_SIZE)
- res = CONVERT_SAT(CONVERT_DOWN(seq, VEC_DATA_TYPE(int, VECTOR_SIZE)), VEC_DATA_TYPE(uchar, VECTOR_SIZE));
- VSTORE(VECTOR_SIZE)
- (res, 0, ((__global DATA_TYPE *)dst_ptr));
+ res0 = CONVERT_SAT(CONVERT_DOWN(seq, VEC_DATA_TYPE(int, VECTOR_SIZE)), VEC_DATA_TYPE(uchar, VECTOR_SIZE));
+ STORE_VECTOR_SELECT(res, DATA_TYPE, dst_ptr, VECTOR_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)
#endif // VECTOR_SIZE == 1
}
-#endif // defined(OFFSET_OUT) && defined(SCALE_OUT)
+#endif // !defined(OFFSET_OUT) && !defined(SCALE_OUT)
-#endif // defined(VECTOR_SIZE) && defined(START) && defined(STEP) && defined(DATA_TYPE)
+#endif // defined(VECTOR_SIZE) && defined(START) && defined(STEP) && defined(DATA_TYPE) && defined(VEC_SIZE_LEFTOVER)
diff --git a/src/core/CL/kernels/CLRangeKernel.cpp b/src/core/CL/kernels/CLRangeKernel.cpp
index 892f1c7c9f..85f79988c9 100644
--- a/src/core/CL/kernels/CLRangeKernel.cpp
+++ b/src/core/CL/kernels/CLRangeKernel.cpp
@@ -31,60 +31,37 @@
#include "src/core/helpers/WindowHelpers.h"
#include "support/StringSupport.h"
-using namespace arm_compute;
-
-namespace
+namespace arm_compute
{
-unsigned int get_num_elems_processed_per_iteration(const DataType dt)
+namespace
{
- unsigned int num_elems_processed_per_iteration = preferred_vector_width(CLKernelLibrary::get().get_device(), dt);
- if(num_elems_processed_per_iteration > 8)
- {
- num_elems_processed_per_iteration = 8; //kernel uses only 8 lanes.
- }
- return num_elems_processed_per_iteration;
-}
+constexpr unsigned int vector_size_byte_opencl = 16;
-Status validate_arguments(const ITensorInfo &output, const float start, const float end, const float step)
+Status validate_arguments(const ITensorInfo *output, const float start, const float end, const float step)
{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&output,
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output,
1,
DataType::U8, DataType::S8, DataType::QASYMM8,
DataType::U16, DataType::S16,
DataType::U32, DataType::S32,
DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(&output);
+ ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(output);
ARM_COMPUTE_RETURN_ERROR_ON_MSG((start == end), "start of the requested sequence must not be equal to the end");
ARM_COMPUTE_RETURN_ERROR_ON_MSG(((start < end) && (step <= 0)), "step must be greater than 0 when start < end");
ARM_COMPUTE_RETURN_ERROR_ON_MSG(((start > end) && (step >= 0)), "step must be less than 0 when start > end");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(!check_value_range(start, output.data_type(), output.quantization_info()), "start value is outside the range of the data type");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(!check_value_range(end, output.data_type(), output.quantization_info()), "end value is outside the range of the data type");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(!check_value_range(step, output.data_type(), output.quantization_info()), "step value is outside the range of the data type");
-
ARM_COMPUTE_RETURN_ERROR_ON_MSG((start == end), "start of the requested sequence must not be equal to the end");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(output.num_dimensions() != 1, "Output has to be a 1-D tensor");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(output.tensor_shape().total_size() < num_of_elements_in_range(start, end, step), "Output tensor size is incorrect");
-
- return Status{};
-}
-
-std::pair<Status, Window> validate_and_configure_window(ITensorInfo &output, const float start, const float end, const float step)
-{
- unsigned int num_elems_processed_per_iteration = get_num_elems_processed_per_iteration(output.data_type());
- // Auto initialize output if not initialized
- auto_init_if_empty(output, TensorShape(num_of_elements_in_range(start, end, step)), 1, output.data_type(), output.quantization_info());
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(!check_value_range(start, output->data_type(), output->quantization_info()), "start value is outside the range of the data type");
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(!check_value_range(end, output->data_type(), output->quantization_info()), "end value is outside the range of the data type");
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(!check_value_range(step, output->data_type(), output->quantization_info()), "step value is outside the range of the data type");
- // Configure kernel window
- Window win = calculate_max_window(output, Steps(num_elems_processed_per_iteration));
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(output->num_dimensions() != 1, "Output has to be a 1-D tensor");
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(output->tensor_shape().total_size() < num_of_elements_in_range(start, end, step), "Output tensor size is incorrect");
- AccessWindowHorizontal output_access(&output, 0, num_elems_processed_per_iteration);
- bool window_changed = update_window_and_padding(win, output_access);
- output_access.set_valid_region(win, ValidRegion(Coordinates(), TensorShape(num_of_elements_in_range(start, end, step))));
- Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
- return std::make_pair(err, win);
+ return Status{};
}
} // namespace
@@ -101,12 +78,13 @@ void CLRangeKernel::configure(ICLTensor *output, const float start, const float
void CLRangeKernel::configure(const CLCompileContext &compile_context, ICLTensor *output, const float start, const float end, const float step)
{
ARM_COMPUTE_ERROR_ON_NULLPTR(output);
-
- ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*(output->info()), start, end, step));
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(output->info(), start, end, step));
// Configure kernel window
- auto win_config = validate_and_configure_window(*(output->info()), start, end, step);
- ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
+ unsigned int num_elems_processed_per_iteration = adjust_vec_size(vector_size_byte_opencl / output->info()->element_size(), output->info()->dimension(0));
+ Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
+
+ auto padding_info = get_padding_info({ output });
_start = start;
_end = end;
@@ -115,11 +93,11 @@ void CLRangeKernel::configure(const CLCompileContext &compile_context, ICLTensor
std::string kernel_name = "range";
- unsigned int num_elems_processed_per_iteration = get_num_elems_processed_per_iteration(output->info()->data_type());
// Set build options
CLBuildOptions build_opts;
build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(output->info()->data_type()));
build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration));
+ build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(output->info()->dimension(0) % num_elems_processed_per_iteration));
build_opts.add_option("-DSTART=" + support::cpp11::to_string(start));
build_opts.add_option("-DSTEP=" + support::cpp11::to_string(step));
if(is_data_type_quantized_asymmetric(output->info()->data_type()))
@@ -131,7 +109,7 @@ void CLRangeKernel::configure(const CLCompileContext &compile_context, ICLTensor
}
// Create kernel
_kernel = create_kernel(compile_context, kernel_name, build_opts.options());
- ICLKernel::configure_internal(win_config.second);
+ ICLKernel::configure_internal(win);
// Set config_id for enabling LWS tuning
_config_id = kernel_name;
@@ -139,15 +117,12 @@ void CLRangeKernel::configure(const CLCompileContext &compile_context, ICLTensor
_config_id += lower_string(string_from_data_type(output->info()->data_type()));
_config_id += "_";
_config_id += support::cpp11::to_string(output->info()->dimension(0));
+ ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
}
Status CLRangeKernel::validate(const ITensorInfo *output, const float start, const float end, const float step)
{
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
-
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*output, start, end, step));
- ARM_COMPUTE_RETURN_ON_ERROR((validate_and_configure_window(*(output->clone()), start, end, step)).first);
-
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(output, start, end, step));
return Status{};
}
@@ -160,3 +135,4 @@ void CLRangeKernel::run(const Window &window, cl::CommandQueue &queue)
enqueue(queue, *this, window, lws_hint());
}
+} // namespace arm_compute \ No newline at end of file