Compute Library
 22.11
cast.cl File Reference
#include "helpers.h"

Go to the source code of this file.

Macros

#define CONVERT_DOWN(x, type)   CONVERT(x, type)
 
#define CONVERT_UP(x, type)   CONVERT(x, type)
 

Functions

__kernel void cast_down (__global uchar *in_ptr, uint in_stride_x, uint in_step_x, uint in_stride_y, uint in_step_y, uint in_stride_z, uint in_step_z, uint in_offset_first_element_in_bytes, __global uchar *out_ptr, uint out_stride_x, uint out_step_x, uint out_stride_y, uint out_step_y, uint out_stride_z, uint out_step_z, uint out_offset_first_element_in_bytes)
 This function performs a down-casting. More...
 
__kernel void cast_up (__global uchar *in_ptr, uint in_stride_x, uint in_step_x, uint in_stride_y, uint in_step_y, uint in_stride_z, uint in_step_z, uint in_offset_first_element_in_bytes, __global uchar *out_ptr, uint out_stride_x, uint out_step_x, uint out_stride_y, uint out_step_y, uint out_stride_z, uint out_step_z, uint out_offset_first_element_in_bytes)
 This function performs a up-casting. More...
 

Macro Definition Documentation

◆ CONVERT_DOWN

#define CONVERT_DOWN (   x,
  type 
)    CONVERT(x, type)

Definition at line 29 of file cast.cl.

Referenced by cast_down().

◆ CONVERT_UP

#define CONVERT_UP (   x,
  type 
)    CONVERT(x, type)

Definition at line 32 of file cast.cl.

Referenced by cast_up().

Function Documentation

◆ cast_down()

__kernel void cast_down ( __global uchar *  in_ptr,
uint  in_stride_x,
uint  in_step_x,
uint  in_stride_y,
uint  in_step_y,
uint  in_stride_z,
uint  in_step_z,
uint  in_offset_first_element_in_bytes,
__global uchar *  out_ptr,
uint  out_stride_x,
uint  out_step_x,
uint  out_stride_y,
uint  out_step_y,
uint  out_stride_z,
uint  out_step_z,
uint  out_offset_first_element_in_bytes 
)

This function performs a down-casting.

Attention
For QSYMM8_PER_CHANNEL -> QASYMM8, it is user's responsibility to keep track of the quantization info.
Note
The input and output data_types need to be passed at compile time using -DDATA_TYPE_IN and -DDATA_TYPE_OUT: e.g. -DDATA_TYPE_IN=uchar -DDATA_TYPE_OUT=short
Vector size should be given as a preprocessor argument using -DVEC_SIZE=size. e.g. -DVEC_SIZE=16
Leftover vector size has to be passed at compile time using -DVEC_SIZE_LEFTOVER. e.g. -DVEC_SIZE_LEFTOVER=3. It is defined as the remainder between the input's first dimension and VEC_SIZE
Parameters
[in]in_ptrPointer to the source image. Supported data types: U8/S8/QSYMM8_PER_CHANNEL/U16/S16/U32/S32/F16/F32
[in]in_stride_xStride of the source image in X dimension (in bytes)
[in]in_step_xin_stride_x * number of elements along X processed per workitem(in bytes)
[in]in_stride_yStride of the source image in Y dimension (in bytes)
[in]in_step_yin_stride_y * number of elements along Y processed per workitem(in bytes)
[in]in_stride_zStride of the source tensor in Z dimension (in bytes)
[in]in_step_zin_stride_z * number of elements along Z processed per workitem(in bytes)
[in]in_offset_first_element_in_bytesThe offset of the first element in the source image
[out]out_ptrPointer to the destination image. Supported data types: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[in]out_stride_xStride of the destination image in X dimension (in bytes)
[in]out_step_xout_stride_x * number of elements along X processed per workitem(in bytes)
[in]out_stride_yStride of the destination image in Y dimension (in bytes)
[in]out_step_yout_stride_y * number of elements along Y processed per workitem(in bytes)
[in]out_stride_zStride of the source tensor in Z dimension (in bytes)
[in]out_step_zout_stride_z * number of elements along Z processed per workitem(in bytes)
[in]out_offset_first_element_in_bytesThe offset of the first element in the destination image

Definition at line 60 of file cast.cl.

References CONVERT_DOWN, STORE_VECTOR_SELECT, VEC_DATA_TYPE, VEC_SIZE, and VLOAD.

63 {
64  int x_offs = max((int)(get_global_id(0) * VEC_SIZE - (VEC_SIZE - VEC_SIZE_LEFTOVER) % VEC_SIZE), 0);
65 
66  __global uchar *in_addr = in_ptr + in_offset_first_element_in_bytes + sizeof(DATA_TYPE_IN) * x_offs + get_global_id(1) * in_stride_y + get_global_id(2) * in_stride_z;
67  __global uchar *out_addr = out_ptr + out_offset_first_element_in_bytes + sizeof(DATA_TYPE_OUT) * x_offs + get_global_id(1) * out_stride_y + get_global_id(2) * out_stride_z;
68 
69  // Load data
70  VEC_DATA_TYPE(DATA_TYPE_IN, VEC_SIZE)
71  in_data = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE_IN *)in_addr);
72 
73 #if defined(IS_DATA_TYPE_QUANTIZED)
74  in_data ^= (VEC_DATA_TYPE(DATA_TYPE_IN, VEC_SIZE))0x80;
75 #endif // defined(IS_DATA_TYPE_QUANTIZED)
76 
77 #if defined(IS_DATA_TYPE_FLOAT)
78  VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE)
79  res0 = CONVERT_DOWN(in_data, VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE));
80  STORE_VECTOR_SELECT(res, DATA_TYPE_OUT, out_addr, VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)
81 #else /* defined(IS_DATA_TYPE_FLOAT) */
82  VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE)
83  res0 = CONVERT_DOWN(in_data, VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE));
84  STORE_VECTOR_SELECT(res, DATA_TYPE_OUT, out_addr, VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)
85 #endif /* defined(IS_DATA_TYPE_FLOAT) */
86 }
#define VEC_SIZE
#define STORE_VECTOR_SELECT(basename, data_type, ptr, vec_size, leftover, cond)
Store a vector that can only be partial in x.
#define CONVERT_DOWN(x, type)
Definition: cast.cl:29
#define VLOAD(size)
Definition: helpers.h:204
#define VEC_DATA_TYPE(type, size)
Definition: helpers.h:728

◆ cast_up()

__kernel void cast_up ( __global uchar *  in_ptr,
uint  in_stride_x,
uint  in_step_x,
uint  in_stride_y,
uint  in_step_y,
uint  in_stride_z,
uint  in_step_z,
uint  in_offset_first_element_in_bytes,
__global uchar *  out_ptr,
uint  out_stride_x,
uint  out_step_x,
uint  out_stride_y,
uint  out_step_y,
uint  out_stride_z,
uint  out_step_z,
uint  out_offset_first_element_in_bytes 
)

This function performs a up-casting.

Note
The input and output data_types need to be passed at compile time using -DDATA_TYPE_IN and -DDATA_TYPE_OUT: e.g. -DDATA_TYPE_IN=uchar -DDATA_TYPE_OUT=short
Vector size should be given as a preprocessor argument using -DVEC_SIZE=size. e.g. -DVEC_SIZE=16
Leftover vector size has to be passed at compile time using -DVEC_SIZE_LEFTOVER. e.g. -DVEC_SIZE_LEFTOVER=3. It is defined as the remainder between the input's first dimension and VEC_SIZE
Parameters
[in]in_ptrPointer to the source image. Supported data types: U8/S8/U16/S16/U32/S32/F16/F32
[in]in_stride_xStride of the source image in X dimension (in bytes)
[in]in_step_xin_stride_x * number of elements along X processed per workitem(in bytes)
[in]in_stride_yStride of the source image in Y dimension (in bytes)
[in]in_step_yin_stride_y * number of elements along Y processed per workitem(in bytes)
[in]in_stride_zStride of the source tensor in Z dimension (in bytes)
[in]in_step_zin_stride_z * number of elements along Z processed per workitem(in bytes)
[in]in_offset_first_element_in_bytesThe offset of the first element in the source image
[out]out_ptrPointer to the destination image. Supported data types: U8/U16/S16/U32/S32/F16/F32
[in]out_stride_xStride of the destination image in X dimension (in bytes)
[in]out_step_xout_stride_x * number of elements along X processed per workitem(in bytes)
[in]out_stride_yStride of the destination image in Y dimension (in bytes)
[in]out_step_yout_stride_y * number of elements along Y processed per workitem(in bytes)
[in]out_stride_zStride of the source tensor in Z dimension (in bytes)
[in]out_step_zout_stride_z * number of elements along Z processed per workitem(in bytes)
[in]out_offset_first_element_in_bytesThe offset of the first element in the destination image

Definition at line 112 of file cast.cl.

References CONVERT_UP, STORE_VECTOR_SELECT, VEC_DATA_TYPE, VEC_SIZE, and VLOAD.

115 {
116  int x_offs = max((int)(get_global_id(0) * VEC_SIZE - (VEC_SIZE - VEC_SIZE_LEFTOVER) % VEC_SIZE), 0);
117 
118  __global uchar *in_addr = in_ptr + in_offset_first_element_in_bytes + sizeof(DATA_TYPE_IN) * x_offs + get_global_id(1) * in_stride_y + get_global_id(2) * in_stride_z;
119  __global uchar *out_addr = out_ptr + out_offset_first_element_in_bytes + sizeof(DATA_TYPE_OUT) * x_offs + get_global_id(1) * out_stride_y + get_global_id(2) * out_stride_z;
120 
121  // Load data
122  VEC_DATA_TYPE(DATA_TYPE_IN, VEC_SIZE)
123  in_data = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE_IN *)in_addr);
124 
125 #if defined(IS_DATA_TYPE_FLOAT)
126  VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE)
127  res0 = CONVERT_UP(in_data, VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE));
128  STORE_VECTOR_SELECT(res, DATA_TYPE_OUT, out_addr, VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)
129 #else /* defined(IS_DATA_TYPE_FLOAT) */
130  VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE)
131  res0 = CONVERT_UP(in_data, VEC_DATA_TYPE(DATA_TYPE_OUT, VEC_SIZE));
132  STORE_VECTOR_SELECT(res, DATA_TYPE_OUT, out_addr, VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)
133 #endif /* defined(IS_DATA_TYPE_FLOAT) */
134 }
#define VEC_SIZE
#define CONVERT_UP(x, type)
Definition: cast.cl:32
#define STORE_VECTOR_SELECT(basename, data_type, ptr, vec_size, leftover, cond)
Store a vector that can only be partial in x.
#define VLOAD(size)
Definition: helpers.h:204
#define VEC_DATA_TYPE(type, size)
Definition: helpers.h:728