42 Status
validate_arguments(
const ITensorInfo *input_weights,
const ITensorInfo *bn_mean,
const ITensorInfo *bn_var,
43 const ITensorInfo *fused_weights,
const ITensorInfo *fused_bias,
44 const ITensorInfo *input_bias,
const ITensorInfo *bn_beta,
const ITensorInfo *bn_gamma,
67 if(input_bias !=
nullptr)
73 if(bn_beta !=
nullptr)
79 if(bn_gamma !=
nullptr)
85 if(fused_weights !=
nullptr && fused_weights->total_size() != 0)
92 if(fused_bias !=
nullptr && fused_bias->total_size() != 0)
103 : _input_weights(nullptr), _input_bias(nullptr), _bn_mean(nullptr), _bn_var(nullptr), _bn_gamma(nullptr), _bn_beta(nullptr), _fused_weights(nullptr), _fused_bias(nullptr), _epsilon(),
104 _run_in_place_weights(false), _run_in_place_bias(false)
113 configure(
CLKernelLibrary::get().get_compile_context(), input_weights, bn_mean, bn_var, fused_weights, fused_bias, input_bias, bn_beta, bn_gamma,
epsilon, fbn_type);
123 auto padding_info =
get_padding_info({ input_weights, bn_mean, bn_var, fused_weights, fused_bias, input_bias, bn_beta, bn_gamma });
125 _input_weights = input_weights;
126 _input_bias = input_bias;
130 _bn_gamma = bn_gamma;
131 _fused_weights = fused_weights;
132 _fused_bias = fused_bias;
135 _run_in_place_weights = (fused_weights ==
nullptr) || (fused_weights == input_weights);
136 _run_in_place_bias = (input_bias !=
nullptr && fused_bias ==
nullptr) || (input_bias !=
nullptr && fused_bias == input_bias);
139 if(_fused_weights !=
nullptr)
144 if(_fused_bias !=
nullptr)
152 (fused_weights !=
nullptr) ? fused_weights->
info() :
nullptr,
153 (fused_bias !=
nullptr) ? fused_bias->
info() :
nullptr,
154 (input_bias !=
nullptr) ? input_bias->
info() :
nullptr,
155 (bn_beta !=
nullptr) ? bn_beta->
info() :
nullptr,
156 (bn_gamma !=
nullptr) ? bn_gamma->
info() :
nullptr,
161 ICLKernel::configure_internal(win);
169 build_opts.
add_option_if(_run_in_place_weights,
"-DIN_PLACE_W");
170 build_opts.
add_option_if(_run_in_place_bias,
"-DIN_PLACE_B");
176 _kernel =
create_kernel(compile_context,
"fuse_batchnormalization_layer", build_opts.
options());
201 unsigned int idx = 0;
203 if(_input_bias !=
nullptr)
209 if(!_run_in_place_weights)
213 if(!_run_in_place_bias)
217 if(_bn_beta !=
nullptr)
221 if(_bn_gamma !=
nullptr)
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
const Window & window() const
The maximum window the kernel can be executed on.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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.
const StringSet & options() const
Gets the current options list set.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
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...
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
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.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
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.
void add_option(std::string option)
Adds option to the existing build option list.
FuseBatchNormalizationType
Available FuseBatchNormalizationType.
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
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.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
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...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
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.
Interface for OpenCL tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Num samples, height, width, channels.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
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.
Window first_slice_window_3D() const
First 3D slice of the window.
CLFuseBatchNormalizationKernel()
Default constructor.
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Window first_slice_window_1D() const
First 1D slice of the window.