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

#include <CLMemsetKernel.h>

Collaboration diagram for arm_compute::CLMemsetKernel:

Public Member Functions

 CLMemsetKernel ()
 
 CLMemsetKernel (const CLMemsetKernel &)=delete
 
CLMemsetKerneloperator= (const CLMemsetKernel &)=delete
 
 CLMemsetKernel (CLMemsetKernel &&)=default
 
CLMemsetKerneloperator= (CLMemsetKernel &&)=default
 
 ~CLMemsetKernel ()=default
 
void configure (ICLTensor *tensor, const PixelValue &constant_value, Window *window=nullptr)
 
void configure (const CLCompileContext &compile_context, ICLTensor *tensor, const PixelValue &constant_value, Window *window=nullptr)
 
void run (const Window &window, cl::CommandQueue &queue) override
 

Static Public Member Functions

static Status validate (const ITensorInfo *tensor, const PixelValue &constant_value, Window *window=nullptr)
 

Detailed Description

Interface for filling the planes of a tensor

Definition at line 52 of file CLMemsetKernel.h.

Constructor & Destructor Documentation

◆ CLMemsetKernel() [1/3]

arm_compute::CLMemsetKernel::CLMemsetKernel ( )

Default constructor

Definition at line 52 of file CLMemsetKernel.cpp.

52: ICLKernel(), _tensor(nullptr), _full_window() {}

◆ CLMemsetKernel() [2/3]

arm_compute::CLMemsetKernel::CLMemsetKernel ( const CLMemsetKernel )
delete

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

◆ CLMemsetKernel() [3/3]

arm_compute::CLMemsetKernel::CLMemsetKernel ( CLMemsetKernel &&  )
default

Allow instances of this class to be moved

◆ ~CLMemsetKernel()

arm_compute::CLMemsetKernel::~CLMemsetKernel ( )
default

Default destructor

References validate().

Member Function Documentation

◆ configure() [1/2]

void arm_compute::CLMemsetKernel::configure ( const CLCompileContext &  compile_context,
ICLTensor *  tensor,
const PixelValue &  constant_value,
Window *  window = nullptr 
)

Initialise the kernel's tensor and filling value

Parameters
[in]compile_contextThe compile context to be used.
[in,out]tensorInput tensor to fill. Supported data types: All.
[in]constant_valueThe value used to fill the planes of the tensor
[in]windowWindow to be used in case setting only part of a tensor. Default is nullptr.

Definition at line 59 of file CLMemsetKernel.cpp.

61{
62 ARM_COMPUTE_UNUSED(compile_context);
63 ARM_COMPUTE_ERROR_ON_NULLPTR(tensor);
64 ARM_COMPUTE_ERROR_THROW_ON(validate(tensor->info(), constant_value, window));
65
66 _tensor = tensor;
67
68 const DataType data_type = tensor->info()->data_type();
69 const int vec_size_x = 16 / tensor->info()->element_size();
70
71 // Create and update the window (if needed)
72 _full_window = calculate_max_window(*tensor->info());
73 Window win = _full_window;
74 if (window != nullptr)
75 {
76 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(win, *window);
77 win = *window;
78 }
79
80 const int output_width_x = win.num_iterations(0);
81 const bool multi_access_x = output_width_x >= vec_size_x;
82 const bool remainder_x = output_width_x % vec_size_x > 0;
83
84 if (multi_access_x)
85 {
86 win.set(
87 Window::DimX,
88 Window::Dimension(win.x().start(), ceil_to_multiple(win.x().end(), vec_size_x), vec_size_x));
89 }
90 ICLKernel::configure_internal(win);
91
92 // Create kernel
93 CLBuildOptions build_opts;
94 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
95 build_opts.add_option("-DCONSTANT_VALUE=" + string_from_pixel_value(constant_value, data_type));
96 build_opts.add_option_if(multi_access_x, "-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
97 build_opts.add_option_if(multi_access_x && remainder_x,
98 "-DLAST_ACCESSED_X=" + support::cpp11::to_string(
99 std::max<int>(output_width_x - vec_size_x, 0)));
100
101 _kernel =
102 static_cast<cl::Kernel>(CLKernelLibraryEx::get().create_kernel("memset", build_opts.options()));
103}
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.
static Status validate(const ITensorInfo *tensor, const PixelValue &constant_value, Window *window=nullptr)
DataType
"scalar" value type
Definition DataType.h:27

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

◆ configure() [2/2]

void arm_compute::CLMemsetKernel::configure ( ICLTensor *  tensor,
const PixelValue &  constant_value,
Window *  window = nullptr 
)

Initialise the kernel's tensor and filling value

Parameters
[in,out]tensorInput tensor to fill. Supported data types: All.
[in]constant_valueThe value used to fill the planes of the tensor
[in]windowWindow to be used in case setting only part of a tensor. Default is nullptr.

Definition at line 54 of file CLMemsetKernel.cpp.

55{
56 configure(CLKernelLibrary::get().get_compile_context(), tensor, constant_value, window);
57}
void configure(ICLTensor *tensor, const PixelValue &constant_value, Window *window=nullptr)

References configure().

Referenced by arm_compute::CLOneHot::configure(), and configure().

◆ operator=() [1/2]

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

Allow instances of this class to be moved

◆ operator=() [2/2]

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

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

◆ run()

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

Definition at line 117 of file CLMemsetKernel.cpp.

118{
119 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
120 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
121
122 // Collapse all the batches on the third
123 Window collapsed = window.collapse_if_possible(_full_window, Window::DimZ);
124 Window slice = collapsed.first_slice_window_3D();
125
126 do
127 {
128 unsigned int idx = 0;
129 add_3D_tensor_argument(idx, _tensor, slice);
130 enqueue(queue, *this, slice, lws_hint());
131 } while (collapsed.slide_window_slice_3D(slice));
132}

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

◆ validate()

Status arm_compute::CLMemsetKernel::validate ( const ITensorInfo *  tensor,
const PixelValue &  constant_value,
Window *  window = nullptr 
)
static

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

Parameters
[in]tensorSource tensor info. Data types supported: All.
[in]constant_valueThe value used to fill the planes of the tensor
[in]windowWindow to be used in case setting only part of a tensor. Default is nullptr.
Returns
a status

Definition at line 105 of file CLMemsetKernel.cpp.

107{
108 ARM_COMPUTE_UNUSED(tensor);
109 ARM_COMPUTE_UNUSED(constant_value);
110 if (window != nullptr)
111 {
112 ARM_COMPUTE_RETURN_ERROR_ON(window->x().step() != 1);
113 }
114 return Status{};
115}

Referenced by configure(), and ~CLMemsetKernel().


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