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

#include <CLMultiplyScaleFactorKernel.h>

Collaboration diagram for arm_compute::CLMultiplyScaleFactorKernel:

Public Member Functions

 CLMultiplyScaleFactorKernel ()
 
 CLMultiplyScaleFactorKernel (const CLMultiplyScaleFactorKernel &)=delete
 
CLMultiplyScaleFactorKerneloperator= (const CLMultiplyScaleFactorKernel &)=delete
 
 CLMultiplyScaleFactorKernel (CLMultiplyScaleFactorKernel &&)=default
 
CLMultiplyScaleFactorKerneloperator= (CLMultiplyScaleFactorKernel &&)=default
 
 ~CLMultiplyScaleFactorKernel ()=default
 
void configure (const ICLTensor *input, const ICLTensor *scale_factor, ICLTensor *output, float multiplier=1.f)
 
void run (const Window &window, cl::CommandQueue &queue) override
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *scale_factor, const ITensorInfo *output)
 

Detailed Description

Interface to multiply scale factor kernel.

Definition at line 51 of file CLMultiplyScaleFactorKernel.h.

Constructor & Destructor Documentation

◆ CLMultiplyScaleFactorKernel() [1/3]

CLMultiplyScaleFactorKernel::CLMultiplyScaleFactorKernel ( )

Default constructor

Definition at line 105 of file CLMultiplyScaleFactorKernel.cpp.

106 : _input(nullptr), _scale_factor(nullptr), _output(nullptr), _multiplier(1.f)
107{
108}

◆ CLMultiplyScaleFactorKernel() [2/3]

arm_compute::CLMultiplyScaleFactorKernel::CLMultiplyScaleFactorKernel ( const CLMultiplyScaleFactorKernel )
delete

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

◆ CLMultiplyScaleFactorKernel() [3/3]

arm_compute::CLMultiplyScaleFactorKernel::CLMultiplyScaleFactorKernel ( CLMultiplyScaleFactorKernel &&  )
default

Default Move Constructor.

◆ ~CLMultiplyScaleFactorKernel()

arm_compute::CLMultiplyScaleFactorKernel::~CLMultiplyScaleFactorKernel ( )
default

Default destructor

References validate().

Member Function Documentation

◆ configure()

void CLMultiplyScaleFactorKernel::configure ( const ICLTensor *  input,
const ICLTensor *  scale_factor,
ICLTensor *  output,
float  multiplier = 1.f 
)

Set input, output tensors.

Parameters
[in/out]input Source tensor. Data type supported: S32.
[in]scale_factorScale tensor. Data type supported: F16/F32.
[out]outputDestination tensor. Data type supported: Same as scale_factor.
[in]multiplierAdditional scale value.

Definition at line 110 of file CLMultiplyScaleFactorKernel.cpp.

112{
113 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
114 ARM_COMPUTE_ERROR_THROW_ON(
115 validate_arguments(input->info(), scale_factor->info(), output->info()));
116
117 _input = input;
118 _scale_factor = scale_factor;
119 _output = output;
120 _multiplier = multiplier;
121
122 const int vec_size_x = 16 / output->info()->element_size();
123 const int output_width_x = output->info()->tensor_shape().x();
124 const bool multi_access_x = (output_width_x / vec_size_x > 0);
125
126 // Create and update the window (if needed)
127 Window win = calculate_max_window(*output->info());
128 if (multi_access_x)
129 {
130 win.set(
131 Window::DimX,
132 Window::Dimension(win.x().start(), ceil_to_multiple(win.x().end(), vec_size_x), vec_size_x));
133 }
134 ICLKernel::configure_internal(win);
135
136 // Create kernel
137 CLBuildOptions build_opts;
138 build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
139 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(output->info()->data_type()));
140 build_opts.add_option_if(
141 multi_access_x, "-DLAST_ACCESSED_X=" +
142 support::cpp11::to_string(std::max<int>(output_width_x - vec_size_x, 0)));
143
144 _kernel = static_cast<cl::Kernel>(
145 CLKernelLibraryEx::get().create_kernel("multiply_scale_factor", build_opts.options()));
146}
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.

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

Referenced by arm_compute::CLFullyConnectedHybridLayer::configure().

◆ operator=() [1/2]

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

Default move assignment operator

◆ operator=() [2/2]

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

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

◆ run()

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

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.
Returns
N/A
N/A

Definition at line 158 of file CLMultiplyScaleFactorKernel.cpp.

159{
160 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
161 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
162
163 Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ);
164 Window slice = window_collapsed.first_slice_window_2D();
165
166 // Set scale_factor window
167 Window win_scale = calculate_max_window(*_scale_factor->info(), Steps());
168
169 do
170 {
171 unsigned int idx = 0;
172 add_2D_tensor_argument(idx, _input, slice);
173 add_1D_tensor_argument(idx, _scale_factor, win_scale);
174 add_2D_tensor_argument(idx, _output, slice);
175 _kernel.setArg<float>(idx++, _multiplier);
176 enqueue(queue, *this, slice, lws_hint());
177 } while (window_collapsed.slide_window_slice_2D(slice));
178}

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

◆ validate()

Status CLMultiplyScaleFactorKernel::validate ( const ITensorInfo *  input,
const ITensorInfo *  scale_factor,
const ITensorInfo *  output 
)
static

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

Parameters
[in]inputInput tensor info. Data types supported: S32.
[in]scale_factorScale tensor. Data type supported: F16/F32.
[in]outputOutput tensor info. Data types supported: Same as scale_factor.
[in]multiplierAdditional scale value.
Returns
a status

Definition at line 148 of file CLMultiplyScaleFactorKernel.cpp.

151{
152 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, scale_factor, output));
153 ARM_COMPUTE_RETURN_ON_ERROR(
154 std::get<0>(validate_and_configure_window(input->clone().get(), output->clone().get())));
155 return Status{};
156}

Referenced by arm_compute::CLFullyConnectedHybridLayer::validate(), and ~CLMultiplyScaleFactorKernel().


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