COMPMID-3706: Add padding assert for kernels that don't have padding
authorSheri Zhang <sheri.zhang@arm.com>
Wed, 28 Oct 2020 14:01:55 +0000 (14:01 +0000)
committerSheri Zhang <sheri.zhang@arm.com>
Thu, 29 Oct 2020 10:59:49 +0000 (10:59 +0000)
Signed-off-by: Sheri Zhang <sheri.zhang@arm.com>
Change-Id: I0a3f0a989a4db9a2abc9c89429e94af4c6b6b366
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4274
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Manuel Bottini <manuel.bottini@arm.com>
Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>

src/core/CL/kernels/CLBatchToSpaceLayerKernel.cpp
src/core/CL/kernels/CLConvertFullyConnectedWeightsKernel.cpp
src/core/CL/kernels/CLDepthToSpaceLayerKernel.cpp
src/core/CL/kernels/CLDequantizationLayerKernel.cpp
src/core/CL/kernels/CLElementWiseUnaryLayerKernel.cpp
src/core/CL/kernels/CLFlattenLayerKernel.cpp
src/core/CL/kernels/CLQuantizationLayerKernel.cpp
src/core/CL/kernels/CLReshapeLayerKernel.cpp
src/core/CL/kernels/CLWeightsReshapeKernel.cpp

index 6eb22c9adad145d4b050f13ce35ca4a09a7b0d94..e5997fb4d22070a8c8ff9e7a88546e6a76ea5334 100644 (file)
@@ -93,6 +93,9 @@ void CLBatchToSpaceLayerKernel::configure(const ICLTensor *input, const ICLTenso
 void CLBatchToSpaceLayerKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *block_shape, ICLTensor *output)
 {
     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+
+    auto padding_info = get_padding_info({ input, block_shape, output });
+
     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), block_shape->info(), output->info()));
 
     _input       = input;
@@ -111,6 +114,8 @@ void CLBatchToSpaceLayerKernel::configure(const CLCompileContext &compile_contex
     // Configure kernel window
     Window win = calculate_max_window(*input->info(), Steps());
     ICLKernel::configure_internal(win);
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 void CLBatchToSpaceLayerKernel::configure(const ICLTensor *input, const int32_t block_shape_x, const int32_t block_shape_y, ICLTensor *output)
index b4e42bf3bcf3d9e32bf99398a8e72cf257ac5356..c7888c9c76a260f732e67d1787cee85212e8ae14 100644 (file)
@@ -53,6 +53,8 @@ void CLConvertFullyConnectedWeightsKernel::configure(const CLCompileContext &com
     // Output tensor auto initialisation if not yet initialized
     auto_init_if_empty(*output->info(), *input->info()->clone());
 
+    auto padding_info = get_padding_info({ input, output });
+
     ARM_COMPUTE_ERROR_THROW_ON(CLConvertFullyConnectedWeightsKernel::validate(input->info(), output->info(), original_input_shape, data_layout));
 
     _input  = input;
@@ -82,6 +84,8 @@ void CLConvertFullyConnectedWeightsKernel::configure(const CLCompileContext &com
     // Configure kernel window
     Window win = calculate_max_window(*input->info(), Steps());
     ICLKernel::configure_internal(win);
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 Status CLConvertFullyConnectedWeightsKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const TensorShape &original_input_shape,
index 50bb3b827cbcd9e59c0a55aaca49156d29f296bb..c3a40a286ad534396acdecf42de2294ef8f76202 100644 (file)
@@ -79,6 +79,8 @@ void CLDepthToSpaceLayerKernel::configure(const CLCompileContext &compile_contex
     TensorShape output_shape = compute_depth_to_space_shape(input->info()->tensor_shape(), input->info()->data_layout(), block_shape);
     auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type());
 
+    auto padding_info = get_padding_info({ input, output });
+
     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), block_shape));
 
     _input       = input;
@@ -99,6 +101,8 @@ void CLDepthToSpaceLayerKernel::configure(const CLCompileContext &compile_contex
     // Configure kernel window
     Window win = calculate_max_window(*input->info(), Steps());
     ICLKernel::configure_internal(win);
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 Status CLDepthToSpaceLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output, int32_t block_shape)
index e653c595508927cbc4a5ef587d14b46e8a709fa8..e2c49fbf6602d32b8b979170614cbd81745f6914 100644 (file)
@@ -53,22 +53,6 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
 
     return Status{};
 }
-
-std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
-{
-    // Configure kernel window
-    Window win = calculate_max_window(*input, Steps());
-
-    // Output tensor auto initialization if not yet initialized
-    auto_init_if_empty(*output, input->tensor_shape(), 1, DataType::F32);
-
-    // CLDequantizationLayerKernel doesn't need padding so update_window_and_padding() can be skipped
-    Coordinates coord;
-    coord.set_num_dimensions(output->num_dimensions());
-    output->set_valid_region(ValidRegion(coord, output->tensor_shape()));
-
-    return std::make_tuple(Status{}, win);
-}
 } // namespace
 
 CLDequantizationLayerKernel::CLDequantizationLayerKernel()
@@ -84,6 +68,12 @@ void CLDequantizationLayerKernel::configure(const ICLTensor *input, ICLTensor *o
 void CLDequantizationLayerKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
 {
     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+
+    // Output tensor auto initialization if not yet initialized
+    auto_init_if_empty(*output->info(), input->info()->tensor_shape(), 1, DataType::F32);
+
+    auto padding_info = get_padding_info({ input, output });
+
     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
 
     _input  = input;
@@ -93,15 +83,6 @@ void CLDequantizationLayerKernel::configure(const CLCompileContext &compile_cont
     const int  output_width_x = output->info()->tensor_shape().x();
     const bool multi_access_x = (output_width_x / vec_size_x > 0);
 
-    // Create and update the window (if needed)
-    Window win = calculate_max_window(*output->info());
-    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));
-    }
-    ICLKernel::configure_internal(win);
-
     const bool  is_quantized_per_channel = is_data_type_quantized_per_channel(input->info()->data_type());
     std::string kernel_name              = "dequantization_layer";
 
@@ -127,12 +108,25 @@ void CLDequantizationLayerKernel::configure(const CLCompileContext &compile_cont
 
     // Create kernel name
     _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
+
+    // Configure kernel window
+    Window win = calculate_max_window(*output->info());
+    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));
+    }
+    ICLKernel::configure_internal(win);
+
+    // Set output valid region
+    output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 Status CLDequantizationLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
 {
     ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
-    ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), output->clone().get())));
     return Status{};
 }
 
index c7f9df0baafc6d786fc012c454fda3a355f33503..bff0db07a0356863cb5b25e02314e1a176729b12 100644 (file)
@@ -60,6 +60,9 @@ void CLElementWiseUnaryLayerKernel::configure(const ITensorInfo *input, ITensorI
 void CLElementWiseUnaryLayerKernel::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output, const ElementWiseUnary &op)
 {
     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+
+    auto padding_info = get_padding_info({ input, output });
+
     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input, *output));
 
     const std::string kernel_name    = "elementwise_unary";
@@ -67,14 +70,6 @@ void CLElementWiseUnaryLayerKernel::configure(const CLCompileContext &compile_co
     const int         output_width_x = output->tensor_shape().x();
     const bool        multi_access_x = (output_width_x / vec_size_x > 0);
 
-    Window win = calculate_max_window(*output);
-    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));
-    }
-    ICLKernel::configure_internal(win);
-
     // Set kernel build options
     CLBuildOptions build_opts;
     build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->data_type()));
@@ -109,6 +104,17 @@ void CLElementWiseUnaryLayerKernel::configure(const CLCompileContext &compile_co
 
     // Create kernel
     _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
+
+    // Configure kernel window
+    Window win = calculate_max_window(*output);
+    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));
+    }
+    ICLKernel::configure_internal(win);
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 Status CLElementWiseUnaryLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const ElementWiseUnary &op)
index dc1d33869f6482b39fea3eee555aedc50df136a0..590fcee6fd48adfdb5290148e7f9ab7bbe91a7ec 100644 (file)
@@ -52,18 +52,6 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
 
     return Status{};
 }
-
-std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
-{
-    // Output tensor auto initialization if not yet initialized
-    auto_init_if_empty(*output, input->clone()->set_tensor_shape(compute_flatten_shape(input)));
-
-    Window win = calculate_max_window(*input, Steps()); // Flatten does not need paddings
-
-    output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape()));
-
-    return std::make_pair(Status{}, win);
-}
 } // namespace
 
 CLFlattenLayerKernel::CLFlattenLayerKernel()
@@ -79,16 +67,17 @@ void CLFlattenLayerKernel::configure(const ICLTensor *input, ICLTensor *output)
 void CLFlattenLayerKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
 {
     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+
+    // Output tensor auto initialization if not yet initialized
+    auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(compute_flatten_shape(input->info())));
+
+    auto padding_info = get_padding_info({ input, output });
+
     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
 
     _input  = input;
     _output = output;
 
-    // Configure kernel window
-    auto win_config = validate_and_configure_window(input->info(), output->info());
-    ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
-    ICLKernel::configure_internal(win_config.second);
-
     CLBuildOptions build_opts;
     build_opts.add_option("-DDATA_TYPE=" + get_cl_unsigned_type_from_element_size(data_size_from_type(input->info()->data_type())));
     build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input->info()->dimension(0)));
@@ -99,6 +88,14 @@ void CLFlattenLayerKernel::configure(const CLCompileContext &compile_context, co
     // Create kernel
     _kernel = create_kernel(compile_context, "flatten", build_opts.options());
 
+    // Configure kernel window
+    Window win = calculate_max_window(*input->info(), Steps());
+    ICLKernel::configure_internal(win);
+
+    output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
+
     // Set config_id for enabling LWS tuning
     _config_id = "flatten";
     _config_id += "_";
@@ -118,7 +115,6 @@ void CLFlattenLayerKernel::configure(const CLCompileContext &compile_context, co
 Status CLFlattenLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
 {
     ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
-    ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
     return Status{};
 }
 
index 983cbedc0f5bfa368cbdb0ca054fa5bce92b1ca4..44889b9407f04500dce8b2834c20686a5ea0e40d 100644 (file)
@@ -52,26 +52,6 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
 
     return Status{};
 }
-
-std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
-{
-    // Configure kernel window
-    Window win = calculate_max_window(*input, Steps());
-
-    const int  vec_size_x     = 16 / input->element_size();
-    const int  input_width_x  = input->tensor_shape().x();
-    const bool multi_access_x = (input_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));
-    }
-
-    Coordinates coord;
-    coord.set_num_dimensions(output->num_dimensions());
-    output->set_valid_region(ValidRegion(coord, output->tensor_shape()));
-
-    return std::make_pair(Status{}, win);
-}
 } // namespace
 
 CLQuantizationLayerKernel::CLQuantizationLayerKernel()
@@ -87,6 +67,9 @@ void CLQuantizationLayerKernel::configure(const ICLTensor *input, ICLTensor *out
 void CLQuantizationLayerKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
 {
     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+
+    auto padding_info = get_padding_info({ input, output });
+
     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
 
     _input  = input;
@@ -96,11 +79,6 @@ void CLQuantizationLayerKernel::configure(const CLCompileContext &compile_contex
     const int  input_width_x  = input->info()->tensor_shape().x();
     const bool multi_access_x = (input_width_x / vec_size_x > 0);
 
-    // Configure kernel window
-    auto win_config = validate_and_configure_window(input->info(), output->info());
-    ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
-    ICLKernel::configure_internal(win_config.second);
-
     const UniformQuantizationInfo qinfo            = output->info()->quantization_info().uniform();
     const DataType                output_data_type = output->info()->data_type();
 
@@ -160,13 +138,23 @@ void CLQuantizationLayerKernel::configure(const CLCompileContext &compile_contex
     build_opts.add_option("-DMAX_QUANT_VAL=" + support::cpp11::to_string(min_max_quant_values.second));
 
     _kernel = create_kernel(compile_context, "quantization_layer", build_opts.options());
+
+    // Configure kernel window
+    Window win = calculate_max_window(*input->info(), Steps());
+    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));
+    }
+    ICLKernel::configure_internal(win);
+
+    output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 Status CLQuantizationLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
 {
     ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
-    ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
-
     return Status{};
 }
 
index e08970992e29543143af85f466534f0ece3fc78c..b14013bc34c3b5ff334bb8d4f443792efcbe0a05 100644 (file)
@@ -62,6 +62,8 @@ void CLReshapeLayerKernel::configure(const CLCompileContext &compile_context, co
     ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, output));
 
+    auto padding_info = get_padding_info({ input, output });
+
     // Create kernel
     std::set<std::string> build_opts = { "-DDATA_TYPE=" + get_cl_unsigned_type_from_element_size(input->element_size()) };
     _kernel                          = create_kernel(compile_context, "reshape_layer", build_opts);
@@ -91,6 +93,8 @@ void CLReshapeLayerKernel::configure(const CLCompileContext &compile_context, co
     // Set the output valid region
     output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape()));
     ICLKernel::configure_internal(win);
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 Status CLReshapeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
index f69967265ae17cbf460c5d8ba8abc3c246aa6d47..c06c2d3ec7388c53802e5724b7052ec7c9f861d0 100644 (file)
@@ -88,6 +88,8 @@ void CLWeightsReshapeKernel::configure(const CLCompileContext &compile_context,
                                                   (biases != nullptr) ? biases->info() : nullptr,
                                                   output->info(), num_groups));
 
+    auto padding_info = get_padding_info({ input, biases, output });
+
     const DataType data_type = input->info()->data_type();
 
     _biases = biases;
@@ -108,6 +110,8 @@ void CLWeightsReshapeKernel::configure(const CLCompileContext &compile_context,
     // The CLWeightsReshapeKernel doesn't need padding so update_window_and_padding() can be skipped
     output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
     ICLKernel::configure_internal(win);
+
+    ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
 }
 
 Status CLWeightsReshapeKernel::validate(const ITensorInfo *input, const ITensorInfo *biases, const ITensorInfo *output, unsigned int num_groups)