ONE - On-device Neural Engine
Loading...
Searching...
No Matches
arm_compute::CLInstanceNormalizationLayerKernelEx Class Reference

#include <CLInstanceNormalizationLayerKernelEx.h>

Collaboration diagram for arm_compute::CLInstanceNormalizationLayerKernelEx:

Public Member Functions

 CLInstanceNormalizationLayerKernelEx ()
 
 CLInstanceNormalizationLayerKernelEx (const CLInstanceNormalizationLayerKernelEx &)=delete
 
CLInstanceNormalizationLayerKernelExoperator= (const CLInstanceNormalizationLayerKernelEx &)=delete
 
 CLInstanceNormalizationLayerKernelEx (CLInstanceNormalizationLayerKernelEx &&)=default
 
CLInstanceNormalizationLayerKernelExoperator= (CLInstanceNormalizationLayerKernelEx &&)=default
 
 ~CLInstanceNormalizationLayerKernelEx ()=default
 
void configure (ICLTensor *input, ICLTensor *output, ICLTensor *gamma=nullptr, ICLTensor *beta=nullptr, float epsilon=1e-12f)
 
void run (const Window &window, cl::CommandQueue &queue) override
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const ITensorInfo *gamma=nullptr, const ITensorInfo *beta=nullptr, float epsilon=1e-12f)
 

Detailed Description

Interface for performing an instance normalization

Definition at line 51 of file CLInstanceNormalizationLayerKernelEx.h.

Constructor & Destructor Documentation

◆ CLInstanceNormalizationLayerKernelEx() [1/3]

arm_compute::CLInstanceNormalizationLayerKernelEx::CLInstanceNormalizationLayerKernelEx ( )

Constructor

Definition at line 100 of file CLInstanceNormalizationLayerKernelEx.cpp.

101 : _input(nullptr), _output(nullptr), _gamma(nullptr), _beta(nullptr), _epsilon(1e-12),
102 _run_in_place(false)
103{
104}

◆ CLInstanceNormalizationLayerKernelEx() [2/3]

arm_compute::CLInstanceNormalizationLayerKernelEx::CLInstanceNormalizationLayerKernelEx ( const CLInstanceNormalizationLayerKernelEx )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ CLInstanceNormalizationLayerKernelEx() [3/3]

arm_compute::CLInstanceNormalizationLayerKernelEx::CLInstanceNormalizationLayerKernelEx ( CLInstanceNormalizationLayerKernelEx &&  )
default

Default Move Constructor.

◆ ~CLInstanceNormalizationLayerKernelEx()

arm_compute::CLInstanceNormalizationLayerKernelEx::~CLInstanceNormalizationLayerKernelEx ( )
default

Default destructor

References validate().

Member Function Documentation

◆ configure()

void arm_compute::CLInstanceNormalizationLayerKernelEx::configure ( ICLTensor *  input,
ICLTensor *  output,
ICLTensor *  gamma = nullptr,
ICLTensor *  beta = nullptr,
float  epsilon = 1e-12f 
)

Set the input and output tensors.

Parameters
[in,out]inputSource tensor. Data types supported: F16/F32. Data layout supported: NCHW
[out]outputDestination tensor. Data types and data layouts supported: same as input.
[in]gamma(Optional) The scale tensor applied to the normalized tensor. Defaults to nullptr
[in]beta(Optional) The offset tensor applied to the normalized tensor. Defaults to nullptr
[in]epsilon(Optional) Lower bound value for the normalization. Defaults to 1e-12

Definition at line 106 of file CLInstanceNormalizationLayerKernelEx.cpp.

109{
110 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
111
112 _input = input;
113 _output = output == nullptr ? input : output;
114 _gamma = gamma;
115 _beta = beta;
116 _epsilon = epsilon;
117
118 _run_in_place = (output == nullptr) || (output == input);
119 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(_input->info(), _output->info(),
120 gamma ? gamma->info() : nullptr,
121 beta ? beta->info() : nullptr, epsilon));
122 const unsigned int num_elems_processed_per_iteration = 16 / input->info()->element_size();
123
124 CLBuildOptions build_opts;
125 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
126 build_opts.add_option("-DVEC_SIZE=" +
127 support::cpp11::to_string(num_elems_processed_per_iteration));
128 build_opts.add_option("-DDIM_X=" + support::cpp11::to_string(input->info()->dimension(0)));
129 build_opts.add_option("-DDIM_Y=" + support::cpp11::to_string(input->info()->dimension(1)));
130 build_opts.add_option("-DDIM_Z=" + support::cpp11::to_string(input->info()->dimension(2)));
131 build_opts.add_option("-DEPSILON=" + float_to_string_with_full_precision(epsilon));
132 build_opts.add_option_if(gamma, "-DGAMMA");
133 build_opts.add_option_if(beta, "-DBETA");
134 build_opts.add_option_if(_run_in_place, "-DIN_PLACE");
135 build_opts.add_option_if(_input->info()->data_layout() == DataLayout::NHWC, "-DNHWC");
136
137 // Create kernel
138 _kernel = static_cast<cl::Kernel>(
139 CLKernelLibraryEx::get().create_kernel("instance_normalization_ex", build_opts.options()));
140
141 // Configure kernel window
142 auto win_config = validate_and_configure_window(_input->info(), _output->info());
143 ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config));
144 ICLKernel::configure_internal(std::get<1>(win_config));
145}
static CLKernelLibraryEx & get()
Get the KernelLibrary singleton.
Kernel create_kernel(const std::string &kernel_name, const StringSet &build_options_set={}) const
Create a kernel from the kernel library.
volatile const char info[]

References arm_compute::CLKernelLibraryEx::create_kernel(), and arm_compute::CLKernelLibraryEx::get().

◆ operator=() [1/2]

CLInstanceNormalizationLayerKernelEx & arm_compute::CLInstanceNormalizationLayerKernelEx::operator= ( CLInstanceNormalizationLayerKernelEx &&  )
default

Default move assignment operator

◆ operator=() [2/2]

CLInstanceNormalizationLayerKernelEx & arm_compute::CLInstanceNormalizationLayerKernelEx::operator= ( const CLInstanceNormalizationLayerKernelEx )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ run()

void arm_compute::CLInstanceNormalizationLayerKernelEx::run ( const Window &  window,
cl::CommandQueue &  queue 
)
override

Definition at line 158 of file CLInstanceNormalizationLayerKernelEx.cpp.

159{
160 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
161 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
162
163 Window collapsed_window = window.collapse(window, Window::DimZ);
164
165 // We will process the planes together
166 if (_input->info()->data_layout() == DataLayout::NCHW)
167 {
168 collapsed_window.set(Window::DimX, Window::Dimension(0, 1, 1));
169 collapsed_window.set(Window::DimY, Window::Dimension(0, 1, 1));
170 }
171 else
172 {
173 collapsed_window.set(Window::DimY, Window::Dimension(0, 1, 1));
174 collapsed_window.set(Window::DimZ, Window::Dimension(0, _input->info()->dimension(3), 1));
175 }
176
177 Window vec_window;
178 vec_window.set(Window::DimX, Window::Dimension(0, 0, 0));
179
180 unsigned int idx = 0;
181 add_4D_tensor_argument(idx, _input, collapsed_window);
182 if (!_run_in_place)
183 {
184 add_4D_tensor_argument(idx, _output, collapsed_window);
185 }
186 if (_gamma)
187 {
188 add_1D_tensor_argument(idx, _gamma, vec_window);
189 }
190 if (_beta)
191 {
192 add_1D_tensor_argument(idx, _beta, vec_window);
193 }
194
195 enqueue(queue, *this, collapsed_window, lws_hint());
196}

Referenced by package.infer.session::inference().

◆ validate()

Status arm_compute::CLInstanceNormalizationLayerKernelEx::validate ( const ITensorInfo *  input,
const ITensorInfo *  output,
const ITensorInfo *  gamma = nullptr,
const ITensorInfo *  beta = nullptr,
float  epsilon = 1e-12f 
)
static

Static function to check if given info will lead to a valid configuration of CLInstanceNormalizationLayerEx.

Parameters
[in]inputSource tensor info. In case of output tensor = nullptr this tensor will store the result of the normalization. Data types supported: F16/F32. Data layout supported: NHWC, NCHW
[in]outputDestination tensor info. Data types and data layouts supported: same as input.
[in]gamma(Optional) The scale tensor applied to the normalized tensor. Defaults to nullptr
[in]beta(Optional) The offset tensor applied to the normalized tensor. Defaults to nullptr
[in]epsilon(Optional) Lower bound value for the normalization. Defaults to 1e-12
Returns
a status

Definition at line 147 of file CLInstanceNormalizationLayerKernelEx.cpp.

151{
152 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, gamma, beta, epsilon));
153 ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(
154 input->clone().get(), (output == nullptr ? input->clone().get() : output->clone().get()))));
155 return Status{};
156}
KnobTrait< K >::ValueType get(void)
luci::CircleConst * clone(luci::CircleConst *node)
Return cloned object of CircleConst node.

Referenced by arm_compute::CLInstanceNormalizationLayerEx::validate(), and ~CLInstanceNormalizationLayerKernelEx().


The documentation for this class was generated from the following files: