aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/kernels/CLScaleKernel.cpp
diff options
context:
space:
mode:
authorSang-Hoon Park <sang-hoon.park@arm.com>2020-06-09 12:09:24 +0100
committerSang-Hoon Park <sang-hoon.park@arm.com>2020-06-12 14:51:37 +0000
commitccd94966cc58ef5148577e71ba1a4ff5aae1f3bb (patch)
tree17efa87eff3cee7d5c2f0cfe04614b2c6d87a8fc /src/core/CL/kernels/CLScaleKernel.cpp
parente1536a82dd872651551e3ce25b2bae5da8abaf14 (diff)
downloadComputeLibrary-ccd94966cc58ef5148577e71ba1a4ff5aae1f3bb.tar.gz
COMPMID-3364: use ScaleKernelInfo for Scale on OpenCL and GLES
- Make Scale and ScaleKernel (on CL and GLES) use ScaleKernelInfo - Deprecate previous configure/validate functions on NEON, CL and GLES - Make adjustments required by deprecation Change-Id: I7e81f4ee9ae919392137b92f91e9bc002b7ae277 Signed-off-by: Sang-Hoon Park <sang-hoon.park@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3317 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Diffstat (limited to 'src/core/CL/kernels/CLScaleKernel.cpp')
-rw-r--r--src/core/CL/kernels/CLScaleKernel.cpp65
1 files changed, 32 insertions, 33 deletions
diff --git a/src/core/CL/kernels/CLScaleKernel.cpp b/src/core/CL/kernels/CLScaleKernel.cpp
index e19da32ac3..872ba5b6cc 100644
--- a/src/core/CL/kernels/CLScaleKernel.cpp
+++ b/src/core/CL/kernels/CLScaleKernel.cpp
@@ -60,7 +60,7 @@ inline std::pair<float, float> calculate_scale_factors(const ITensorInfo &input,
return std::make_pair(wr, hr);
}
-Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy, SamplingPolicy sampling_policy, bool align_corners)
+Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const ScaleKernelInfo &info)
{
ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input);
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::U8, DataType::S16, DataType::F16, DataType::F32);
@@ -68,9 +68,9 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, I
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output);
ARM_COMPUTE_RETURN_ERROR_ON(output == input);
- ARM_COMPUTE_RETURN_ERROR_ON(align_corners && !is_align_corners_allowed(sampling_policy));
+ ARM_COMPUTE_RETURN_ERROR_ON(info.align_corners && !is_align_corners_allowed(info.sampling_policy));
- if(align_corners)
+ if(info.align_corners)
{
// For bilinear method with aligned corners, the resize ratio will
// be calculated by (input_size - 1)/(output_size - 1). Belows are
@@ -90,14 +90,14 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, I
float wr = 0.f;
float hr = 0.f;
- std::tie(wr, hr) = calculate_scale_factors(*input, *output, align_corners);
+ std::tie(wr, hr) = calculate_scale_factors(*input, *output, info.align_corners);
- ARM_COMPUTE_RETURN_ERROR_ON(policy == InterpolationPolicy::AREA && (wr > 1.f || hr > 1.f));
+ ARM_COMPUTE_RETURN_ERROR_ON(info.interpolation_policy == InterpolationPolicy::AREA && (wr > 1.f || hr > 1.f));
return Status{};
}
-std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy, BorderSize &border)
+std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, const ScaleKernelInfo &info, BorderSize &border)
{
Window win{};
bool window_changed{};
@@ -108,7 +108,7 @@ std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITen
{
case DataLayout::NCHW:
{
- if(border_mode == BorderMode::UNDEFINED)
+ if(info.border_mode == BorderMode::UNDEFINED)
{
border = BorderSize(0);
}
@@ -124,9 +124,9 @@ std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITen
output_access.set_valid_region(win, calculate_valid_region_scale(*(input),
output->tensor_shape(),
- policy,
- sampling_policy,
- border_mode == BorderMode::UNDEFINED));
+ info.interpolation_policy,
+ info.sampling_policy,
+ info.border_mode == BorderMode::UNDEFINED));
window_changed = update_window_and_padding(win, input_access, output_access);
}
@@ -158,13 +158,12 @@ BorderSize CLScaleKernel::border_size() const
return BorderSize(1);
}
-Status CLScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy,
- BorderMode border_mode, SamplingPolicy sampling_policy, bool align_corners)
+Status CLScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const ScaleKernelInfo &info)
{
BorderSize border = BorderSize(1);
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, policy, sampling_policy, align_corners));
- ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), policy, border_mode, sampling_policy, border).first);
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, info));
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), info, border).first);
return Status{};
}
@@ -179,27 +178,26 @@ const ICLTensor *CLScaleKernel::output() const
return _output;
}
-void CLScaleKernel::configure(const ICLTensor *input, ICLTensor *output, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy, bool align_corners)
+void CLScaleKernel::configure(const ICLTensor *input, ICLTensor *output, const ScaleKernelInfo &info)
{
- configure(CLKernelLibrary::get().get_compile_context(), input, output, policy, border_mode, sampling_policy, align_corners);
+ configure(CLKernelLibrary::get().get_compile_context(), input, output, info);
}
-void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy,
- bool align_corners)
+void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const ScaleKernelInfo &info)
{
- ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), policy, sampling_policy, align_corners));
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), info));
- _input = input;
- _output = output;
- _interpolationPolicy = policy;
- _data_layout = input->info()->data_layout();
- _align_corners = align_corners;
+ _input = input;
+ _output = output;
+ _interpolation_policy = info.interpolation_policy;
+ _data_layout = input->info()->data_layout();
+ _align_corners = info.align_corners;
float wr = 0.f;
float hr = 0.f;
std::tie(wr, hr) = calculate_scale_factors(*input->info(), *output->info(), _align_corners);
- const bool call_quantized_kernel = is_data_type_quantized_asymmetric(input->info()->data_type()) && policy == InterpolationPolicy::BILINEAR;
+ const bool call_quantized_kernel = is_data_type_quantized_asymmetric(input->info()->data_type()) && _interpolation_policy == InterpolationPolicy::BILINEAR;
const int idx_width = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
const int idx_height = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
@@ -208,14 +206,15 @@ void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICL
// Compute actual border size
BorderSize border = border_size();
+ auto interpolation_policy_to_use = _interpolation_policy;
// Area interpolation behaves as Nearest Neighbour in case of up-sampling
- if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
+ if(_interpolation_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
{
- policy = InterpolationPolicy::NEAREST_NEIGHBOR;
+ interpolation_policy_to_use = InterpolationPolicy::NEAREST_NEIGHBOR;
}
// Configure kernel window
- auto win_config = validate_and_configure_window(input->info(), output->info(), policy, border_mode, sampling_policy, border);
+ auto win_config = validate_and_configure_window(input->info(), output->info(), info, border);
ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
ICLKernel::configure_internal(win_config.second);
@@ -223,9 +222,9 @@ void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICL
CLBuildOptions build_opts;
build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
build_opts.add_option("-DBORDER_SIZE=" + support::cpp11::to_string(border.right));
- build_opts.add_option_if(border_mode == BorderMode::REPLICATE, "-DBORDER_MODE_REPLICATE");
+ build_opts.add_option_if(info.border_mode == BorderMode::REPLICATE, "-DBORDER_MODE_REPLICATE");
build_opts.add_option_if(is_nhwc, "-DDEPTH_OUT=" + support::cpp11::to_string(output->info()->dimension(2)));
- build_opts.add_option_if_else(sampling_policy == SamplingPolicy::CENTER, "-DSAMPLING_POLICY_CENTER", "-DSAMPLING_POLICY_TOP_LEFT");
+ build_opts.add_option_if_else(info.sampling_policy == SamplingPolicy::CENTER, "-DSAMPLING_POLICY_CENTER", "-DSAMPLING_POLICY_TOP_LEFT");
if(call_quantized_kernel)
{
const UniformQuantizationInfo qinfo = input->info()->quantization_info().uniform();
@@ -233,7 +232,7 @@ void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICL
build_opts.add_option("-DOFFSET=" + support::cpp11::to_string(qinfo.offset));
}
- std::string interpolation_name = string_from_interpolation_policy(policy);
+ std::string interpolation_name = string_from_interpolation_policy(interpolation_policy_to_use);
std::transform(interpolation_name.begin(), interpolation_name.end(), interpolation_name.begin(), ::tolower);
std::string kernel_name = "scale_" + interpolation_name;
kernel_name += call_quantized_kernel ? "_quantized_" : "_";
@@ -252,8 +251,8 @@ void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICL
// Set config_id for enabling LWS tuning
_config_id = "scale_";
- _config_id += (border_mode == BorderMode::REPLICATE ? "Bord_rep" : "");
- _config_id += (sampling_policy == SamplingPolicy::CENTER ? "center" : "topleft");
+ _config_id += (info.border_mode == BorderMode::REPLICATE ? "Bord_rep" : "");
+ _config_id += (info.sampling_policy == SamplingPolicy::CENTER ? "center" : "topleft");
_config_id += (is_nhwc ? "nhwc" : "nchw");
_config_id += "_";
_config_id += support::cpp11::to_string(output->info()->dimension(0));