26 #define SUB(x, y) (x - y)
27 #define ADD(x, y) (x + y)
28 #define MAX(x, y) max((x), (y))
29 #define MIN(x, y) min((x), (y))
30 #define SQUARED_DIFF(x, y) (x - y) * (x - y)
31 #define PRELU(x, y) (select(y * x, x, CONVERT((x > (DATA_TYPE)0), SELECT_VEC_DATA_TYPE(float, VEC_SIZE_OUT))))
32 #define DIV(x, y) (x / y)
34 #define CONVERT_RTE(x, type) (convert_##type##_rte((x)))
35 #define CONVERT_DOWN(x, type) CONVERT_RTE(x, type)
37 #define OP_FUN_NAME_STR(op) elementwise_operation_##op##_quantized
38 #define OP_FUN_NAME(op) OP_FUN_NAME_STR(op)
40 #if defined(OP) && defined(VEC_SIZE_IN1) && defined(VEC_SIZE_IN2) && defined(VEC_SIZE_OUT) && defined(OFFSET_IN1) && defined(OFFSET_IN2) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_IN2) && defined(SCALE_OUT) && defined(DATA_TYPE)
42 #define VEC_FLOAT VEC_DATA_TYPE(float, VEC_SIZE_OUT)
43 #define VEC_INT VEC_DATA_TYPE(int, VEC_SIZE_OUT)
44 #define VEC_TYPE VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE_OUT)
90 #if !defined(IN_PLACE)
93 #endif // !defined(IN_PLACE)
98 #else // VEC_SIZE_IN1 == 1
99 uint in1_x_offs = max((
int)(get_global_id(0) * VEC_SIZE_IN1 - (VEC_SIZE_IN1 - VEC_SIZE_LEFTOVER) % VEC_SIZE_IN1), 0);
100 #endif // VEC_SIZE_IN1 == 1
101 #if VEC_SIZE_IN2 == 1
103 #else // VEC_SIZE_IN2 == 1
104 uint in2_x_offs = max((
int)(get_global_id(0) * VEC_SIZE_IN2 - (VEC_SIZE_IN2 - VEC_SIZE_LEFTOVER) % VEC_SIZE_IN2), 0);
105 #endif // VEC_SIZE_IN2 == 1
106 #if !defined(IN_PLACE)
107 uint out_x_offs = max((
int)(get_global_id(0) * VEC_SIZE_OUT - (VEC_SIZE_OUT - VEC_SIZE_LEFTOVER) % VEC_SIZE_OUT), 0);
108 #endif // !defined(IN_PLACE)
111 __global uchar *in1_addr = in1_ptr + in1_offset_first_element_in_bytes + in1_x_offs *
sizeof(DATA_TYPE) + get_global_id(1) * in1_step_y + get_global_id(2) * in1_step_z;
112 __global uchar *in2_addr = in2_ptr + in2_offset_first_element_in_bytes + in2_x_offs *
sizeof(DATA_TYPE) + get_global_id(1) * in2_step_y + get_global_id(2) * in2_step_z;
114 #if !defined(IN_PLACE)
115 out_addr = out_ptr + out_offset_first_element_in_bytes + out_x_offs *
sizeof(DATA_TYPE) + get_global_id(1) * out_step_y + get_global_id(2) * out_step_z;
116 #else // !defined(IN_PLACE)
117 #if defined(SRC1_IN_PLACE)
119 #else //defined(SRC1_IN_PLACE)
121 #endif //defined(SRC1_IN_PLACE)
122 #endif // !defined(IN_PLACE)
124 VEC_INT in_a =
CONVERT((
VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE_OUT))(
VLOAD(VEC_SIZE_IN1)(0, (__global DATA_TYPE *)in1_addr)), VEC_INT);
125 VEC_INT in_b =
CONVERT((
VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE_OUT))(
VLOAD(VEC_SIZE_IN2)(0, (__global DATA_TYPE *)in2_addr)), VEC_INT);
127 in_a =
SUB(in_a, (VEC_INT)((
int)OFFSET_IN1));
128 in_b =
SUB(in_b, (VEC_INT)((
int)OFFSET_IN2));
136 STORE_VECTOR_SELECT(res, DATA_TYPE, out_addr, VEC_SIZE_OUT, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)