blob: 404b46a89da03326fb19b450161172ed038a104b [file] [log] [blame]
Joel Liangf1f3ebd2017-11-10 09:59:19 +08001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef ARM_COMPUTE_HELPER_CS_H
26#define ARM_COMPUTE_HELPER_CS_H
27
28#define SHADER_PARAMS_DECLARATION \
29 layout(std140, binding = 0) uniform shader_params
30
31#define TENSOR_DECLARATION(location, buffer_type, type, ptr_name, shift_name, element_shift, access) \
32 layout(std430, binding = location) access buffer buffer_type \
33 { \
34 type ptr_name[]; \
35 }; \
36 const uint shift_name = uint(element_shift)
37
38struct VectorAttributes
39{
40 uint stride_x; /**< Stride of the vector in X dimension (in bytes) */
41 uint step_x; /**< stride_x * number of elements along X processed per workitem (in bytes) */
42 uint offset_first_element_in_bytes; /**< The offset of the first element in the vector (in bytes) */
43 uint padding; /**< The padding to rounding up the structure to a multiple of a vec4 */
44};
45
46struct ImageAttributes
47{
48 uint stride_x; /**< Stride of the image in X dimension (in bytes) */
49 uint step_x; /**< stride_x * number of elements along X processed per workitem (in bytes) */
50 uint stride_y; /**< Stride of the image in Y dimension (in bytes) */
51 uint step_y; /**< stride_y * number of elements along Y processed per workitem (in bytes) */
52 uint offset_first_element_in_bytes; /**< The offset of the first element in the image (in bytes) */
53 uint padding1; /**< The padding to rounding up the structure to a multiple of a vec4 */
54 uint padding2; /**< The padding to rounding up the structure to a multiple of a vec4 */
55 uint padding3; /**< The padding to rounding up the structure to a multiple of a vec4 */
56};
57
58struct Tensor3DAttributes
59{
60 uint stride_x; /**< Stride of the tensor in X dimension (in bytes) */
61 uint step_x; /**< stride_x * number of elements along X processed per workitem (in bytes) */
62 uint stride_y; /**< Stride of the tensor in Y dimension (in bytes) */
63 uint step_y; /**< stride_y * number of elements along Y processed per workitem (in bytes) */
64 uint stride_z; /**< Stride of the tensor in Z dimension (in bytes) */
65 uint step_z; /**< stride_z * number of elements along Z processed per workitem (in bytes) */
66 uint offset_first_element_in_bytes; /**< The offset of the first element in the tensor (in bytes) */
67 uint padding; /**< The padding to rounding up the structure to a multiple of a vec4 */
68};
69
70struct VectorIterator
71{
72 int current_offset_in_bytes; /**< Current offset of vector (in bytes) */
73 int stride_x; /**< Stride of the vector in X dimension (in bytes) */
74 int element_shift; /**< The number of bits to shift by for one element */
75};
76
77struct ImageIterator
78{
79 int current_offset_in_bytes; /**< Current offset of image (in bytes) */
80 int stride_x; /**< Stride of the image in X dimension (in bytes) */
81 int stride_y; /**< Stride of the image in Y dimension (in bytes) */
82 int element_shift; /**< The number of bits to shift by for one element */
83};
84
85struct Tensor3DIterator
86{
87 int current_offset_in_bytes; /**< Current offset of tensor (in bytes) */
88 int stride_x; /**< Stride of the tensor in X dimension (in bytes) */
89 int stride_y; /**< Stride of the tensor in Y dimension (in bytes) */
90 int stride_z; /**< Stride of the tensor in Z dimension (in bytes) */
91 int element_shift; /**< The number of bits to shift by for one element */
92};
93
94#define CONVERT_TO_VECTOR_ITERATOR(attrs, element_shift) \
95 update_vector_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
96 attrs.stride_x, attrs.step_x)
97
98#define CONVERT_TO_VECTOR_ITERATOR_NO_STEP(attrs, element_shift) \
99 update_vector_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
100 attrs.stride_x, uint(0))
101
102#define CONVERT_TO_IMAGE_ITERATOR(attrs, element_shift) \
103 update_image_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
104 attrs.stride_x, attrs.step_x, attrs.stride_y, attrs.step_y)
105
106#define CONVERT_TO_IMAGE_ITERATOR_NO_STEP(attrs, element_shift) \
107 update_image_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
108 attrs.stride_x, uint(0), attrs.stride_y, uint(0))
109
110#define CONVERT_TO_TENSOR3D_ITERATOR(attrs, element_shift) \
111 update_tensor3D_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
112 attrs.stride_x, attrs.step_x, attrs.stride_y, attrs.step_y, attrs.stride_z, attrs.step_z)
113
114#define CONVERT_TO_TENSOR3D_ITERATOR_NO_STEP(attrs, element_shift) \
115 update_tensor3D_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
116 attrs.stride_x, uint(0), attrs.stride_y, uint(0), attrs.stride_z, uint(0))
117
118#define CONVERT_TENSOR3D_TO_IMAGE_ITERATOR(attrs, element_shift) \
119 update_image_from_tensor3D_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
120 attrs.stride_x, attrs.step_x, attrs.stride_y, attrs.step_y, attrs.stride_z, attrs.step_z)
121
122#define CONVERT_TENSOR3D_TO_IMAGE_ITERATOR_NO_STEP(attrs, element_shift) \
123 update_image_from_tensor3D_iter_offset(element_shift, attrs.offset_first_element_in_bytes, \
124 attrs.stride_x, uint(0), attrs.stride_y, uint(0), attrs.stride_z, attrs.step_z)
125
126/** Wrap vector information into a VectorIterator structure, and make the offset to be this workitem's position.
127 *
128 * @param[in] element_shift The number of bits to shift by for one element
129 * @param[in] offset_first_element_in_bytes The offset of the first element in the source vector
130 * @param[in] stride_x Stride of the vector in X dimension (in bytes)
131 * @param[in] step_x stride_x * number of elements along X processed per workitem (in bytes)
132 *
133 * @return A VectorIterator object
134 */
135VectorIterator update_vector_iter_offset(uint element_shift, uint offset_first_element_in_bytes, uint stride_x, uint step_x)
136{
137 VectorIterator vector_iter;
138 vector_iter.element_shift = int(element_shift);
139 vector_iter.stride_x = int(stride_x);
140 vector_iter.current_offset_in_bytes = int(offset_first_element_in_bytes + gl_GlobalInvocationID.x * step_x);
141
142 return vector_iter;
143}
144
145/** Wrap image information into an ImageIterator structure, and make the offset to be this workitem's position.
146 *
147 * @param[in] element_shift The number of bits to shift by for one element
148 * @param[in] offset_first_element_in_bytes The offset of the first element in the source image
149 * @param[in] stride_x Stride of the image in X dimension (in bytes)
150 * @param[in] step_x stride_x * number of elements along X processed per workitem (in bytes)
151 * @param[in] stride_y Stride of the image in Y dimension (in bytes)
152 * @param[in] step_y stride_y * number of elements along Y processed per workitem (in bytes)
153 *
154 * @return An ImageIterator object
155 */
156ImageIterator update_image_iter_offset(uint element_shift, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y)
157{
158 ImageIterator image_iter;
159 image_iter.element_shift = int(element_shift);
160 image_iter.stride_x = int(stride_x);
161 image_iter.stride_y = int(stride_y);
162 image_iter.current_offset_in_bytes = int(offset_first_element_in_bytes + gl_GlobalInvocationID.x * step_x + gl_GlobalInvocationID.y * step_y);
163
164 return image_iter;
165}
166
167/** Wrap 3D tensor information into a Tensor3DIterator structure, and make the offset to be this workitem's position.
168 *
169 * @param[in] element_shift The number of bits to shift by for one element
170 * @param[in] offset_first_element_in_bytes The offset of the first element in the source tersor
171 * @param[in] stride_x Stride of the tersor in X dimension (in bytes)
172 * @param[in] step_x stride_x * number of elements along X processed per workitem (in bytes)
173 * @param[in] stride_y Stride of the tersor in Y dimension (in bytes)
174 * @param[in] step_y stride_y * number of elements along Y processed per workitem (in bytes)
175 * @param[in] stride_z Stride of the tersor in Z dimension (in bytes)
176 * @param[in] step_z stride_z * number of elements along Z processed per workitem (in bytes)
177 *
178 * @return A 3D Tensor3DIterator object
179 */
180Tensor3DIterator update_tensor3D_iter_offset(uint element_shift, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z)
181{
182 Tensor3DIterator tensor_iter;
183 tensor_iter.element_shift = int(element_shift);
184 tensor_iter.stride_x = int(stride_x);
185 tensor_iter.stride_y = int(stride_y);
186 tensor_iter.stride_z = int(stride_z);
187 tensor_iter.current_offset_in_bytes = int(offset_first_element_in_bytes + gl_GlobalInvocationID.x * step_x + gl_GlobalInvocationID.y * step_y + gl_GlobalInvocationID.z * step_z);
188
189 return tensor_iter;
190}
191
192/** Wrap 3D tensor information into an ImageIterator structure, and make the offset to be this workitem's position.
193 *
194 * @param[in] element_shift The number of bits to shift by for one element
195 * @param[in] offset_first_element_in_bytes The offset of the first element in the source tensor
196 * @param[in] stride_x Stride of the tensor in X dimension (in bytes)
197 * @param[in] step_x stride_x * number of elements along X processed per workitem (in bytes)
198 * @param[in] stride_y Stride of the tensor in Y dimension (in bytes)
199 * @param[in] step_y stride_y * number of elements along Y processed per workitem (in bytes)
200 * @param[in] stride_z Stride of the tensor in Z dimension (in bytes)
201 * @param[in] step_z stride_z * number of elements along Z processed per workitem (in bytes)
202 *
203 * @return An ImageIterator object
204 */
205ImageIterator update_image_from_tensor3D_iter_offset(uint element_shift, uint offset_first_element_in_bytes, uint stride_x, uint step_x, uint stride_y, uint step_y, uint stride_z, uint step_z)
206{
207 ImageIterator image_iter;
208 image_iter.element_shift = int(element_shift);
209 image_iter.stride_x = int(stride_x);
210 image_iter.stride_y = int(stride_y);
211 image_iter.current_offset_in_bytes = int(offset_first_element_in_bytes + gl_GlobalInvocationID.x * step_x + gl_GlobalInvocationID.y * step_y + gl_GlobalInvocationID.z * step_z);
212
213 return image_iter;
214}
215
216#define VECTOR_OFFSET(tensor_iter, x) \
217 uint(vector_offset_in_bytes(tensor_iter, int(x)) >> tensor_iter.element_shift)
218
219#define IMAGE_OFFSET(tensor_iter, x, y) \
220 uint(image_offset_in_bytes(tensor_iter, int(x), int(y)) >> tensor_iter.element_shift)
221
222#define TENSOR3D_OFFSET(tensor_iter, x, y, z) \
223 uint(tensor3D_offset_in_bytes(tensor_iter, int(x), int(y), int(z)) >> tensor_iter.element_shift)
224
zhenglin4f7f2552017-12-06 16:41:20 +0800225#define TENSOR_OFFSET_ADVANCE_IN_BYTES(tensor_iter, n) \
226 uint((tensor_iter.current_offset_in_bytes + int(n)) >> tensor_iter.element_shift)
227
Joel Liangf1f3ebd2017-11-10 09:59:19 +0800228#define CURRENT_ITEM_OFFSET(tensor_iter) \
229 uint(tensor_iter.current_offset_in_bytes >> tensor_iter.element_shift)
230
231#define CURRENT_ITEM_OFFSET_IN_BYTES(tensor_iter) \
232 uint(tensor_iter.current_offset_in_bytes)
233
234#define TENSOR_ITERATOR_ADVANCE_IN_BYTES(tensor_iter, n) \
235 tensor_iter.current_offset_in_bytes += int(n)
236
237/** Get the offset of a VectorIterator
238 *
239 * @param[in] vector_iter The VectorIterator object pointed to the starting position of the buffer
240 * @param[in] x Relative X position
241 *
242 * @return The relative offset of the VectorIterator object (in bytes)
243 */
244uint vector_offset_in_bytes(VectorIterator vector_iter, int x)
245{
246 return uint(vector_iter.current_offset_in_bytes + x * vector_iter.stride_x);
247}
248
249/** Get the offset of an ImageIterator
250 *
251 * @param[in] vector_iter The ImageIterator object pointed to the starting position of the buffer
252 * @param[in] x Relative X position
253 * @param[in] y Relative Y position
254 *
255 * @return The relative offset of the ImageIterator object (in bytes)
256 */
257uint image_offset_in_bytes(ImageIterator image_iter, int x, int y)
258{
259 return uint(image_iter.current_offset_in_bytes + x * image_iter.stride_x + y * image_iter.stride_y);
260}
261
262/** Get the offset of a Tensor3DIterator
263 *
264 * @param[in] vector_iter The Tensor3DIterator object pointed to the starting position of the buffer
265 * @param[in] x Relative X position
266 * @param[in] y Relative Y position
267 * @param[in] z Relative Z position
268 *
269 * @return The relative offset of the Tensor3DIterator object (in bytes)
270 */
271uint tensor3D_offset_in_bytes(Tensor3DIterator tensor_iter, int x, int y, int z)
272{
273 return uint(tensor_iter.current_offset_in_bytes + x * tensor_iter.stride_x + y * tensor_iter.stride_y + z * tensor_iter.stride_z);
274}
275
276#define LOAD(tensor_ptr, offset) tensor_ptr[offset]
277#define STORE(tensor_ptr, offset, data) tensor_ptr[offset] = data
278#define LOAD_CURRENT_ITEM(tensor_ptr, tensor_iter) tensor_ptr[CURRENT_ITEM_OFFSET(tensor_iter)]
279#define STORE_CURRENT_ITEM(tensor_ptr, tensor_iter, data) tensor_ptr[CURRENT_ITEM_OFFSET(tensor_iter)] = data
280
281#define VLOAD2(return_type, tensor_ptr, offset) \
282 return_type(LOAD(tensor_ptr, offset), \
283 LOAD(tensor_ptr, (offset) + uint(1)))
284
285#define VSTORE2(tensor_ptr, offset, data) \
286 STORE(tensor_ptr, offset, data[0]); \
287 STORE(tensor_ptr, (offset) + uint(1), data[1])
288
289#define VLOAD2_CURRENT_ITEM(return_type, tensor_ptr, tensor_iter) VLOAD2(return_type, tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
290#define VSTORE2_CURRENT_ITEM(tensor_ptr, tensor_iter, data) VSTORE2(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
291
292#define VLOAD3(return_type, tensor_ptr, offset) \
293 return_type(LOAD(tensor_ptr, offset), \
294 LOAD(tensor_ptr, (offset) + uint(1)), \
295 LOAD(tensor_ptr, (offset) + uint(2)))
296
297#define VSTORE3(tensor_ptr, offset, data) \
298 STORE(tensor_ptr, offset, data[0]); \
299 STORE(tensor_ptr, (offset) + uint(1), data[1]); \
300 STORE(tensor_ptr, (offset) + uint(2), data[2])
301
302#define VLOAD3_CURRENT_ITEM(return_type, tensor_ptr, tensor_iter) VLOAD3(return_type, tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
303#define VSTORE3_CURRENT_ITEM(tensor_ptr, tensor_iter, data) VSTORE3(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
304
305#define VLOAD4(return_type, tensor_ptr, offset) \
306 return_type(LOAD(tensor_ptr, offset), \
307 LOAD(tensor_ptr, (offset) + uint(1)), \
308 LOAD(tensor_ptr, (offset) + uint(2)), \
309 LOAD(tensor_ptr, (offset) + uint(3)))
310
311#define VSTORE4(tensor_ptr, offset, data) \
312 STORE(tensor_ptr, offset, data[0]); \
313 STORE(tensor_ptr, (offset) + uint(1), data[1]); \
314 STORE(tensor_ptr, (offset) + uint(2), data[2]); \
315 STORE(tensor_ptr, (offset) + uint(3), data[3])
316
317#define VLOAD4_CURRENT_ITEM(return_type, tensor_ptr, tensor_iter) VLOAD4(return_type, tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
318#define VSTORE4_CURRENT_ITEM(tensor_ptr, tensor_iter, data) VSTORE4(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
319
320/** Converting the vec4 object to 4 half-precision (16-bits) floating point values and packing into a uvec2 object
321 *
322 * @param[in] data The vec4 object to be packed
323 *
324 * @return The packed uvec2 object
325 */
326highp uvec2 pack4_half(mediump vec4 data)
327{
328 return uvec2(packHalf2x16(data.xy), packHalf2x16(data.zw));
329}
330
331/** Unpacking the uvec2 object to 4 half-precision (16-bits) floating point values and converting to a vec4 object
332 *
333 * @param[in] packed_data The uvec2 object to be unpacked
334 *
335 * @return The unpacked vec4 object
336 */
337mediump vec4 unpack4_half(highp uvec2 packed_data)
338{
339 return vec4(unpackHalf2x16(packed_data.x), unpackHalf2x16(packed_data.y));
340}
341
342/** Converting the vec4[2] object to 8 half-precision (16-bits) floating point values and packing into a uvec4 object
343 *
344 * @param[in] data The vec4[2] object to be packed
345 *
346 * @return The packed uvec4 object
347 */
348highp uvec4 pack8_half(mediump vec4 data[2])
349{
350 return uvec4(packHalf2x16(data[0].xy), packHalf2x16(data[0].zw),
351 packHalf2x16(data[1].xy), packHalf2x16(data[1].zw));
352}
353
354/** Unpacking the uvec4 object to 8 half-precision (16-bits) floating point values and converting to a vec4[2] object
355 *
356 * @param[in] packed_data The uvec4 object to be unpacked
357 *
358 * @return The unpacked vec4[2] object
359 */
360mediump vec4[2] unpack8_half(highp uvec4 packed_data)
361{
362 return vec4[2](vec4(unpackHalf2x16(packed_data.x), unpackHalf2x16(packed_data.y)),
363 vec4(unpackHalf2x16(packed_data.z), unpackHalf2x16(packed_data.w)));
364}
365
366// For half-precision (16-bits) floating point packed into a "uint" element
Joel Liangaa29fde2017-11-15 12:13:59 +0800367#define LOAD_UNPACK2_HALF(tensor_ptr, offset) unpackHalf2x16(uint(LOAD(tensor_ptr, offset)))
Joel Liangf1f3ebd2017-11-10 09:59:19 +0800368#define STORE_PACK2_HALF(tensor_ptr, offset, data) STORE(tensor_ptr, offset, packHalf2x16(data))
369#define LOAD_UNPACK2_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter) LOAD_UNPACK2_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
370#define STORE_PACK2_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter, data) STORE_PACK2_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
371
372#define VLOAD2_UNPACK4_HALF(tensor_ptr, offset) unpack4_half(VLOAD2(uvec2, tensor_ptr, offset))
373#define VSTORE2_PACK4_HALF(tensor_ptr, offset, data) VSTORE2(tensor_ptr, offset, pack4_half(data))
374#define VLOAD2_UNPACK4_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter) VLOAD2_UNPACK4_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
375#define VSTORE2_PACK4_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter, data) VSTORE2_PACK4_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
376
377#define VLOAD4_UNPACK8_HALF(tensor_ptr, offset) unpack8_half(VLOAD4(uvec4, tensor_ptr, offset))
378#define VSTORE4_PACK8_HALF(tensor_ptr, offset, data) VSTORE4(tensor_ptr, offset, pack8_half(data))
379#define VLOAD4_UNPACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter) VLOAD4_UNPACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
380#define VSTORE4_PACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter, data) VSTORE4_PACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
381
382// For half-precision (16-bits) floating point packed into a "uvec2" element
Joel Liangaa29fde2017-11-15 12:13:59 +0800383#define LOAD_UNPACK4_HALF(tensor_ptr, offset) unpack4_half(uvec2(LOAD(tensor_ptr, offset)))
Joel Liangf1f3ebd2017-11-10 09:59:19 +0800384#define STORE_PACK4_HALF(tensor_ptr, offset, data) STORE(tensor_ptr, offset, pack4_half(data))
385#define LOAD_UNPACK4_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter) LOAD_UNPACK4_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
386#define STORE_PACK4_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter, data) STORE_PACK4_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
387
388#define VLOAD2_UNPACK8_HALF(tensor_ptr, offset) unpack8_half(VLOAD2(uvec4, tensor_ptr, offset))
389#define VSTORE2_PACK8_HALF(tensor_ptr, offset, data) VSTORE2(tensor_ptr, offset, pack8_half(data))
390#define VLOAD2_UNPACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter) VLOAD2_UNPACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
391#define VSTORE2_PACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter, data) VSTORE2_PACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
392
393// For half-precision (16-bits) floating point packed into a "uvec4" element
Joel Liangaa29fde2017-11-15 12:13:59 +0800394#define LOAD_UNPACK8_HALF(tensor_ptr, offset) unpack8_half(uvec4(LOAD(tensor_ptr, offset)))
Joel Liangf1f3ebd2017-11-10 09:59:19 +0800395#define STORE_PACK8_HALF(tensor_ptr, offset, data) STORE(tensor_ptr, offset, pack8_half(data))
396#define LOAD_UNPACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter) LOAD_UNPACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
397#define STORE_PACK8_CURRENT_ITEM_HALF(tensor_ptr, tensor_iter, data) STORE_PACK8_HALF(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
398
Joel Liangc5114d32017-12-04 15:30:53 +0800399/** Converting the uvec4 object to 4 low-precision uint values and packing into a uint object
400 *
401 * @param[in] data The uvec4 object to be packed
402 *
403 * @return The packed uint object
404 */
405highp uint pack4_u8(lowp uvec4 data)
406{
407 highp uint r = uint(0);
408
409 for(int i = 0; i < 4; i++)
410 {
411 r |= data[i] << uint(i * 8);
412 }
413
414 return r;
415}
416
417/** Unpacking the uint object to 4 low-precision uint values and converting to a uvec4 object
418 *
419 * @param[in] packed_data The uint object to be unpacked
420 *
421 * @return The unpacked uvec4 object
422 */
423lowp uvec4 unpack4_u8(highp uint packed_data)
424{
425 lowp uvec4 uvec;
426
427 for(int i = 0; i < 4; i++)
428 {
429 uvec[i] = (packed_data >> uint(i * 8)) & uint(0xFF);
430 }
431
432 return uvec;
433}
434
435#define LOAD_UNPACK4_U8(tensor_ptr, offset) unpack4_u8(uint(LOAD(tensor_ptr, offset)))
436#define STORE_PACK4_U8(tensor_ptr, offset, data) STORE(tensor_ptr, offset, pack4_u8(data))
437#define LOAD_UNPACK4_CURRENT_ITEM_U8(tensor_ptr, tensor_iter) LOAD_UNPACK4_U8(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter))
438#define STORE_PACK4_CURRENT_ITEM_U8(tensor_ptr, tensor_iter, data) STORE_PACK4_U8(tensor_ptr, CURRENT_ITEM_OFFSET(tensor_iter), data)
439
Joel Liangf1f3ebd2017-11-10 09:59:19 +0800440#endif // ARM_COMPUTE_HELPER_CS_H