24.02.1
|
Go to the documentation of this file.
44 const ITensorInfo *bn_mean,
45 const ITensorInfo *bn_var,
46 const ITensorInfo *fused_weights,
47 const ITensorInfo *fused_bias,
48 const ITensorInfo *input_bias,
49 const ITensorInfo *bn_beta,
50 const ITensorInfo *bn_gamma,
75 if (input_bias !=
nullptr)
81 if (bn_beta !=
nullptr)
87 if (bn_gamma !=
nullptr)
93 if (fused_weights !=
nullptr && fused_weights->total_size() != 0)
100 if (fused_bias !=
nullptr && fused_bias->total_size() != 0)
111 : _input_weights(nullptr),
112 _input_bias(nullptr),
117 _fused_weights(nullptr),
118 _fused_bias(nullptr),
120 _run_in_place_weights(false),
121 _run_in_place_bias(false)
156 get_padding_info({input_weights, bn_mean, bn_var, fused_weights, fused_bias, input_bias, bn_beta, bn_gamma});
158 _input_weights = input_weights;
159 _input_bias = input_bias;
163 _bn_gamma = bn_gamma;
164 _fused_weights = fused_weights;
165 _fused_bias = fused_bias;
168 _run_in_place_weights = (fused_weights ==
nullptr) || (fused_weights == input_weights);
170 (input_bias !=
nullptr && fused_bias ==
nullptr) || (input_bias !=
nullptr && fused_bias == input_bias);
173 if (_fused_weights !=
nullptr)
178 if (_fused_bias !=
nullptr)
187 (fused_weights !=
nullptr) ? fused_weights->
info() :
nullptr,
188 (fused_bias !=
nullptr) ? fused_bias->
info() :
nullptr, (input_bias !=
nullptr) ? input_bias->
info() :
nullptr,
189 (bn_beta !=
nullptr) ? bn_beta->
info() :
nullptr, (bn_gamma !=
nullptr) ? bn_gamma->
info() :
nullptr,
epsilon,
194 ICLKernel::configure_internal(win);
203 build_opts.
add_option_if(_run_in_place_weights,
"-DIN_PLACE_W");
204 build_opts.
add_option_if(_run_in_place_bias,
"-DIN_PLACE_B");
210 _kernel =
create_kernel(compile_context,
"fuse_batchnormalization_layer", build_opts.
options());
242 unsigned int idx = 0;
244 if (_input_bias !=
nullptr)
250 if (!_run_in_place_weights)
254 if (!_run_in_place_bias)
258 if (_bn_beta !=
nullptr)
262 if (_bn_gamma !=
nullptr)
std::string to_string(T &&value)
Convert integer and float values to string.
void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx.
FuseBatchNormalizationType fbn_type
const StringSet & options() const
Gets the current options list set.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
@ NHWC
Num samples, height, width, channels.
static Status validate(const ITensorInfo *input_weights, const ITensorInfo *bn_mean, const ITensorInfo *bn_var, const ITensorInfo *fused_weights, const ITensorInfo *fused_bias, const ITensorInfo *input_bias=nullptr, const ITensorInfo *bn_beta=nullptr, const ITensorInfo *bn_gamma=nullptr, float epsilon=0.001f, FuseBatchNormalizationType fbn_type=FuseBatchNormalizationType::CONVOLUTION)
Static function to check if given info will lead to a valid configuration of CLFuseBatchNormalization...
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Interface for OpenCL tensor.
Window first_slice_window_1D() const
First 1D slice of the window.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
void configure(const ICLTensor *input_weights, const ICLTensor *bn_mean, const ICLTensor *bn_var, ICLTensor *fused_weights, ICLTensor *fused_bias, const ICLTensor *input_bias=nullptr, const ICLTensor *bn_beta=nullptr, const ICLTensor *bn_gamma=nullptr, float epsilon=0.001f, FuseBatchNormalizationType fbn_type=FuseBatchNormalizationType::CONVOLUTION)
Set the source, destination of the kernel.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
FuseBatchNormalizationType
Available FuseBatchNormalizationType.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
void add_option(std::string option)
Adds option to the existing build option list.
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
@ CONVOLUTION
For Convolution weights.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Window first_slice_window_3D() const
First 3D slice of the window.
const Window & window() const
The maximum window the kernel can be executed on.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Describe a multidimensional execution window.
@ ELEMENTWISE
Elementwise CL kernel type.
Copyright (c) 2017-2024 Arm Limited.
@ F16
16-bit floating-point number
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Store the tensor's metadata.
@ F32
32-bit floating-point number
CLFuseBatchNormalizationKernel()
Default constructor.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.