27 #define POOL_OP(x, y) ((x) + (y)) 29 #define POOL_OP(x, y) (max((x), (y))) 32 #define DIV_OP(x, y) (x * (1.f / y)) 34 #define DIV_OP_NHWC(x, y) (convert_float8(x) * (float8)(1.f / y)) 37 #error "L2 pooling is not supported" 40 int calculate_avg_scale(
const int pool_size_x,
const int pool_size_y,
const int upper_bound_w,
const int upper_bound_h,
41 const int pad_x,
const int pad_y,
const int stride_x,
const int stride_y)
43 int start_x = get_global_id(0) * stride_x - pad_x;
44 int start_y = get_global_id(1) * stride_y - pad_y;
45 const int end_x =
min(start_x + pool_size_x, upper_bound_w);
46 const int end_y =
min(start_y + pool_size_y, upper_bound_h);
47 #if defined(EXCLUDE_PADDING) 48 start_x =
max(0, start_x);
49 start_y =
max(0, start_y);
51 return ((end_y - start_y) * (end_x - start_x));
92 for(
int y = 0; y < POOL_SIZE_Y; y++)
95 for(; x <= ((int)POOL_SIZE_X - 8); x += 8)
97 uchar8 data = vload8(0, (__global uchar *)
tensor3D_offset(&input, x, y, 0));
98 int8 data0 = convert_int8(data);
103 for(; x < (int)POOL_SIZE_X; ++x)
106 int data0 = convert_int(data);
112 int4 reduce4 =
POOL_OP(vdata.s0123, vdata.s4567);
113 int2 reduce2 =
POOL_OP(reduce4.s01, reduce4.s23);
114 int res =
POOL_OP(reduce2.s0, reduce2.s1);
117 #if defined(POOL_AVG) 122 *(__global uchar *)output.
ptr = convert_uchar(res);
126 const int pad_x,
const int pad_y,
const int stride_x,
const int stride_y)
128 int start_x = get_global_id(1) * stride_x - pad_x;
129 int start_y = get_global_id(2) * stride_y - pad_y;
131 const int end_x =
min(start_x + pool_size_x, upper_bound_w);
132 const int end_y =
min(start_y + pool_size_y, upper_bound_h);
134 start_x =
max(0, start_x);
135 start_y =
max(0, start_y);
137 return ((end_y - start_y) * (end_x - start_x));
176 const int idx_width = get_global_id(1) * STRIDE_X;
177 const int idx_height = get_global_id(2) * STRIDE_Y;
179 for(
int y = 0; y < POOL_SIZE_Y; ++y)
181 int y1 = select(y, PAD_Y - idx_height, y + idx_height < PAD_Y || y + idx_height > MAX_HEIGHT);
182 for(
int x = 0; x < POOL_SIZE_X; ++x)
184 int x1 = select(x, PAD_X - idx_width - 1, x + idx_width < PAD_X || x + idx_width > MAX_WIDTH);
185 x1 = select(x1, PAD_X - idx_width - 1, y != y1);
186 uchar8 data = vload8(0, (__global uchar *)
tensor3D_offset(&input, 0, x1 - PAD_X, y1 - PAD_Y));
187 int8 data0 = convert_int8(data);
192 #if defined(POOL_AVG) 198 vstore8(convert_uchar8(vdata), 0, (__global uchar *)output.
ptr);
fixed_point< T > min(fixed_point< T > x, fixed_point< T > y)
#define CONVERT_TO_TENSOR3D_STRUCT(name)
__kernel void pooling_layer_MxN_quantized_nchw(__global uchar *input_ptr, uint input_stride_x, uint input_step_x, uint input_stride_y, uint input_step_y, uint input_stride_z, uint input_step_z, uint input_offset_first_element_in_bytes, __global uchar *output_ptr, uint output_stride_x, uint output_step_x, uint output_stride_y, uint output_step_y, uint output_stride_z, uint output_step_z, uint output_offset_first_element_in_bytes)
Performs a pooling function of pool size equal to N (NCHW)
Structure to hold 3D tensor information.
__kernel void pooling_layer_MxN_quantized_nhwc(__global uchar *input_ptr, uint input_stride_x, uint input_step_x, uint input_stride_y, uint input_step_y, uint input_stride_z, uint input_step_z, uint input_offset_first_element_in_bytes, __global uchar *output_ptr, uint output_stride_x, uint output_step_x, uint output_stride_y, uint output_step_y, uint output_stride_z, uint output_step_z, uint output_offset_first_element_in_bytes)
Performs a pooling function of pool size equal to N (NHWC)
int calculate_avg_scale_nhwc(const int pool_size_x, const int pool_size_y, int upper_bound_w, int upper_bound_h, const int pad_x, const int pad_y, const int stride_x, const int stride_y)
__global const uchar * tensor3D_offset(const Tensor3D *tensor, int x, int y, int z)
Get the pointer position of a Tensor3D.
#define TENSOR3D_DECLARATION(name)
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
__global uchar * ptr
Pointer to the starting postion of the buffer.
#define DIV_OP_NHWC(x, y)
fixed_point< T > max(fixed_point< T > x, fixed_point< T > y)
int calculate_avg_scale(const int pool_size_x, const int pool_size_y, const int upper_bound_w, const int upper_bound_h, const int pad_x, const int pad_y, const int stride_x, const int stride_y)