aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp
diff options
context:
space:
mode:
authorGian Marco Iodice <gianmarco.iodice@arm.com>2019-06-10 14:46:49 +0100
committerGian Marco Iodice <gianmarco.iodice@arm.com>2019-06-11 12:08:08 +0000
commit761c8d02ff875877db7aa7c850cf8d128592e822 (patch)
tree10871f3dccfa262d4a051d3d88b899be6acac0a2 /src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp
parentd5134364fc4ca40ea65635192e7959327d690a01 (diff)
downloadComputeLibrary-761c8d02ff875877db7aa7c850cf8d128592e822.tar.gz
COMPMID-2398: Add test for CLFuseBatchNormalizationLayer
Change-Id: I786df628ce15fc33fc42c9437fe82972e02e3b16 Signed-off-by: Gian Marco Iodice <gianmarco.iodice@arm.com> Reviewed-on: https://review.mlplatform.org/c/1317 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp')
-rw-r--r--src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp66
1 files changed, 24 insertions, 42 deletions
diff --git a/src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp b/src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp
index 150d9b6d1a..16ad7d970e 100644
--- a/src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp
+++ b/src/core/CL/kernels/CLFuseBatchNormalizationKernel.cpp
@@ -48,9 +48,9 @@ Status validate_arguments(const ITensorInfo *conv_weights, const ITensorInfo *bn
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(conv_weights, 1, DataType::F16, DataType::F32);
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(bn_mean, bn_var);
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(conv_weights, bn_mean, bn_var);
-
- unsigned int kernels_idx = get_data_layout_dimension_index(conv_weights->data_layout(), DataLayoutDimension::BATCHES);
- ARM_COMPUTE_RETURN_ERROR_ON(conv_weights->dimension(kernels_idx) != bn_mean->dimension(0));
+ ARM_COMPUTE_RETURN_ERROR_ON(conv_bias == nullptr && fused_bias == nullptr);
+ ARM_COMPUTE_RETURN_ERROR_ON(conv_weights->dimension(3) != bn_mean->dimension(0));
+ ARM_COMPUTE_RETURN_ERROR_ON(bn_mean->num_dimensions() > 1);
// Validate bias
if(conv_bias != nullptr)
@@ -70,7 +70,6 @@ Status validate_arguments(const ITensorInfo *conv_weights, const ITensorInfo *bn
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(bn_mean, bn_gamma);
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(conv_weights, bn_gamma);
}
-
// Validate output weights
if(fused_weights != nullptr && fused_weights->total_size() != 0)
{
@@ -113,20 +112,18 @@ void CLFuseBatchNormalizationKernel::configure(const ICLTensor *conv_weights, co
_epsilon = epsilon;
_run_in_place_weights = (fused_weights == nullptr) || (fused_weights == conv_weights);
- _run_in_place_bias = (fused_bias == nullptr) || (conv_bias != nullptr && fused_bias == conv_bias);
+ _run_in_place_bias = (conv_bias != nullptr && fused_bias == nullptr) || (conv_bias != nullptr && fused_bias == conv_bias);
// Auto initialize outputs
if(_fused_weights != nullptr)
{
// Output tensor auto initialization if not yet initialized
auto_init_if_empty(*_fused_weights->info(), *_conv_weights->info()->clone());
- fused_weights->info()->set_valid_region(conv_weights->info()->valid_region());
}
if(_fused_bias != nullptr)
{
// Output tensor auto initialization if not yet initialized
auto_init_if_empty(*_fused_bias->info(), *_bn_mean->info()->clone());
- _fused_bias->info()->set_valid_region(bn_mean->info()->valid_region());
}
// Validate arguments
@@ -139,35 +136,22 @@ void CLFuseBatchNormalizationKernel::configure(const ICLTensor *conv_weights, co
epsilon));
// Configure kernel window
- const unsigned int num_elems_processed_per_iteration_x = 4;
- const int output_width_x = conv_weights->info()->tensor_shape().x();
- const bool multi_access_x = (output_width_x / num_elems_processed_per_iteration_x > 0);
-
Window win = calculate_max_window(*conv_weights->info());
- if(multi_access_x)
- {
- win.set(Window::DimX, Window::Dimension(win.x().start(),
- ceil_to_multiple(win.x().end(), num_elems_processed_per_iteration_x),
- num_elems_processed_per_iteration_x));
- }
ICLKernel::configure_internal(win);
// Set build options
CLBuildOptions build_opts;
build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(conv_weights->info()->data_type()));
- build_opts.add_option("-DSELECT_DATA_TYPE=" + get_cl_select_type_from_data_type(conv_weights->info()->data_type()));
- build_opts.add_option("-DNUM_CHANNELS=" + support::cpp11::to_string(conv_weights->info()->dimension(2)));
+ build_opts.add_option("-DDIM2=" + support::cpp11::to_string(conv_weights->info()->dimension(2)));
build_opts.add_option("-DEPSILON=" + float_to_string_with_full_precision(epsilon));
- build_opts.add_option_if(multi_access_x, "-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration_x));
- build_opts.add_option_if(multi_access_x, "-DLAST_ACCESSED_X=" + support::cpp11::to_string(std::max<int>(output_width_x - num_elems_processed_per_iteration_x, 0)));
build_opts.add_option_if(_run_in_place_weights, "-DIN_PLACE_W");
build_opts.add_option_if(_run_in_place_bias, "-DIN_PLACE_B");
- build_opts.add_option_if(conv_bias != nullptr, "-DHAS_BIAS");
- build_opts.add_option_if(bn_beta == nullptr, "-DUSE_DEFAULT_BETA");
- build_opts.add_option_if(bn_gamma == nullptr, "-DUSE_DEFAULT_GAMMA");
+ build_opts.add_option_if(conv_bias != nullptr, "-DBIAS");
+ build_opts.add_option_if(bn_beta != nullptr, "-DBETA");
+ build_opts.add_option_if(bn_gamma != nullptr, "-DGAMMA");
// Create kernel
- _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("fuse_batchnormalization_layer", build_opts.options()));
+ _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("fuse_batchnormalization_conv_layer", build_opts.options()));
}
Status CLFuseBatchNormalizationKernel::validate(const ITensorInfo *conv_weights, const ITensorInfo *bn_mean, const ITensorInfo *bn_var,
@@ -185,37 +169,35 @@ void CLFuseBatchNormalizationKernel::run(const arm_compute::Window &window, cl::
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
// Create window slice
- Window collapsed_window = window.collapse_if_possible(window, Window::DimZ);
- Window slice = collapsed_window.first_slice_window_4D();
-
- Window vector_slice = window.first_slice_window_1D();
- vector_slice.set(Window::DimX, Window::Dimension(0, 0, 0));
+ Window collapsed_window = window.collapse(window, Window::DimZ);
+ Window slice_1d = window.first_slice_window_1D();
+ Window slice_3d = collapsed_window.first_slice_window_3D();
// Add kernel arguments
unsigned int idx = 0;
- add_4D_tensor_argument(idx, _conv_weights, slice);
- add_1D_tensor_argument(idx, _bn_mean, vector_slice);
- add_1D_tensor_argument(idx, _bn_var, vector_slice);
- if(!_run_in_place_weights)
+ add_3D_tensor_argument(idx, _conv_weights, slice_3d);
+ if(_conv_bias != nullptr)
{
- add_4D_tensor_argument(idx, _fused_weights, slice);
+ add_1D_tensor_argument(idx, _conv_bias, slice_1d);
}
- if(!_run_in_place_bias)
+ add_1D_tensor_argument(idx, _bn_mean, slice_1d);
+ add_1D_tensor_argument(idx, _bn_var, slice_1d);
+ if(!_run_in_place_weights)
{
- add_1D_tensor_argument(idx, _fused_bias, vector_slice);
+ add_3D_tensor_argument(idx, _fused_weights, slice_3d);
}
- if(_conv_bias != nullptr)
+ if(!_run_in_place_bias)
{
- add_1D_tensor_argument(idx, _conv_bias, vector_slice);
+ add_1D_tensor_argument(idx, _fused_bias, slice_1d);
}
if(_bn_beta != nullptr)
{
- add_1D_tensor_argument(idx, _bn_beta, vector_slice);
+ add_1D_tensor_argument(idx, _bn_beta, slice_1d);
}
if(_bn_gamma != nullptr)
{
- add_1D_tensor_argument(idx, _bn_gamma, vector_slice);
+ add_1D_tensor_argument(idx, _bn_gamma, slice_1d);
}
- enqueue(queue, *this, slice);
+ enqueue(queue, *this, slice_3d);
}
} // namespace arm_compute