24.02.1
|
Go to the documentation of this file.
52 Status validate_matmul_kernel_info(
const MatMulKernelInfo &matmul_kernel_info)
54 const bool adj_lhs = matmul_kernel_info.adj_lhs;
55 const bool adj_rhs = matmul_kernel_info.adj_rhs;
56 const int m0 = matmul_kernel_info.m0;
57 const int n0 = matmul_kernel_info.n0;
58 const int k0 = matmul_kernel_info.k0;
66 "Only 1,2,3,4,8,16 are supported for M0 for Lhs transposed");
72 "Only 1,2,3,4,8,16 are supported for N0");
76 if (!adj_lhs || adj_rhs)
79 "Only 1,2,3,4,8,16 are supported for K0");
85 Status validate_export_to_cl_image(
const ITensorInfo *rhs,
const MatMulKernelInfo &matmul_kernel_info)
88 if (matmul_kernel_info.export_rhs_to_cl_image)
90 if (matmul_kernel_info.adj_rhs)
92 const int k0 = matmul_kernel_info.k0;
94 "K0 can only be: 4, 8, and 16 for Rhs transposed");
98 const int n0 = matmul_kernel_info.n0;
100 "N0 can only be: 4, 8, and 16 for Rhs non-transposed");
103 "Export to CLImage is not supported for this device/configuration");
133 if (
dst->total_size() != 0)
135 const TensorInfo tensor_info_dst =
dst->clone()->set_tensor_shape(expected_output_shape);
145 "First dimension of bias and output tensors must match.");
166 const int m =
dst->dimension(1);
167 const int n =
dst->dimension(0);
169 const bool adj_lhs = matmul_kernel_info.
adj_lhs;
171 int m0 = adj_lhs ?
adjust_vec_size(matmul_kernel_info.
m0, m) : std::min(matmul_kernel_info.
m0, m);
179 IClKernel::configure_internal(win);
182 const unsigned int partial_store_m0 = m % m0;
183 const unsigned int partial_store_n0 = n % n0;
194 build_opts.
add_option_if_else(_export_rhs_to_cl_image,
"-DRHS_TENSOR_TYPE=IMAGE",
"-DRHS_TENSOR_TYPE=BUFFER");
208 if (_export_rhs_to_cl_image)
247 const ICLTensor *
bias = utils::cast::polymorphic_downcast<const ICLTensor *>(
253 unsigned int idx = 0;
258 cl::Image2D rhs_cl_image;
259 if (_export_rhs_to_cl_image)
269 _kernel.setArg(idx++, rhs_cl_image);
Class to describe a number of elements in each dimension.
std::string to_string(T &&value)
Convert integer and float values to string.
void add_option_if_else(bool cond, std::string option_true, std::string option_false)
Adds first option if condition is true else the second one.
TensorShape compute_matmul_shape(const TensorShape &input0, const TensorShape &input1, const MatMulKernelInfo &matmul_info)
Calculate the matrix multiplication output shape of two tensors.
bool export_to_cl_image(const ITensorInfo *tensor)
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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)
std::string lower_string(const std::string &val)
Lower a given string.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
bool adj_rhs
Get Adjoint RHS flag value.
Interface for OpenCL tensor.
virtual const cl::Buffer & cl_buffer() const =0
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
void add_3d_tensor_nhw_argument(unsigned int &idx, const ICLTensor *tensor)
Add the passed NHW 3D tensor's parameters to the object's kernel's arguments by passing strides,...
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
std::string upper_string(const std::string &val)
Raise a given string to upper case.
int m0
Number of output rows processed by each work-item.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
#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.
Activation Layer Information class.
Status validate_matmul_input_shapes(const TensorShape &lhs_shape, const TensorShape &rhs_shape, const MatMulKernelInfo &matmul_kernel_info)
Validate the input shapes of Matmul operation.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
int k0
Number of inner accumulations.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
void add_option(std::string option)
Adds option to the existing build option list.
void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
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...
size_t total_size() const
Collapses all dimensions to a single linear total size.
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.
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)
static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *bias, const ITensorInfo *dst, const MatMulKernelInfo &matmul_kernel_info, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration.
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.
T x() const
Alias to access the size of the first dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void update_padding_for_cl_image(ITensorInfo *tensor)
Update padding required to export the OpenCL buffer to OpenCL image2d.
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.
bool adj_lhs
Get Adjoint LHS flag value.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
Store the tensor's metadata.
Describe a multidimensional execution window.
cl::Image2D create_image2d_from_buffer(const cl::Context &ctx, const cl::Buffer &buffer, const TensorShape &shape2d, DataType data_type, size_t image_row_pitch, CLImage2DType image_type)
Create a cl::Image2D object from an OpenCL buffer.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Copyright (c) 2017-2024 Arm Limited.
@ F16
16-bit floating-point number
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension,...
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
bool export_rhs_to_cl_image
Flag to know whether the RHS tensor should be exported to cl_image.
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
const std::string & string_from_activation_func(const ActivationFunction &act)
Translates a given activation function to a string.
Store the tensor's metadata.
@ F32
32-bit floating-point number
T y() const
Alias to access the size of the second dimension.
int n0
Number of output columns processed by each work-item.
void configure(const ClCompileContext &compile_context, ITensorInfo *lhs, ITensorInfo *rhs, ITensorInfo *bias, ITensorInfo *dst, const MatMulKernelInfo &matmul_kernel_info, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel's input and output.
#define ARM_COMPUTE_LOG_PARAMS(...)
virtual bool lock_paddings() const =0
Get the lock paddings flag value.
@ GEMM
GEMM CL kernel type.
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.