Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018 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 | layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in; |
| 26 | |
| 27 | #include "helpers_cs.h" |
| 28 | |
| 29 | #if defined(DATA_TYPE_FP16) |
| 30 | precision mediump float; |
| 31 | #endif // DATA_TYPE_FP16 |
| 32 | |
| 33 | /** This kernel performs a shift to move "pad_x" columns to the right. |
| 34 | * |
| 35 | * @note The data type must be passed at compile time using "#define DATA_TYPE_NAME". e.g. "#define DATA_TYPE_FP32" |
| 36 | * @note The width must be passed at compile time using "#define WIDTH n" e.g. "#define WIDTH 1" |
| 37 | * |
| 38 | * @param[in,out] src_ptr Pointer to the source tensor slice. Supported data types: F16/F32 |
| 39 | * @param[in] src_attrs The attributes of the source tensor |
| 40 | * @param[in] pad_x The padding of the source tensor in x dimension |
| 41 | */ |
| 42 | SHADER_PARAMS_DECLARATION |
| 43 | { |
| 44 | Tensor3DAttributes src_attrs; |
| 45 | uint pad_x; |
| 46 | }; |
| 47 | |
| 48 | #if defined(DATA_TYPE_FP16) |
| 49 | TENSOR_DECLARATION(1, srcBuffer, uint, src_ptr, src_shift, 2, restrict); |
| 50 | |
| 51 | void main() |
| 52 | { |
| 53 | Tensor3DIterator src_iter = CONVERT_TO_TENSOR3D_ITERATOR(src_attrs, src_shift); |
| 54 | int n = int(pad_x) % 2; |
| 55 | |
| 56 | if(n == 1) |
| 57 | { |
| 58 | int i = 0; |
| 59 | if((WIDTH % 2) == 1) |
| 60 | { |
| 61 | i = WIDTH + int(pad_x) - 2; |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | vec2 s0_end = LOAD_UNPACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * (WIDTH - 2)))); |
| 66 | vec2 s_end = vec2(s0_end.y, 0.f); |
| 67 | STORE_PACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * (WIDTH + int(pad_x) - 1))), s_end); |
| 68 | i = WIDTH + int(pad_x) - 3; |
| 69 | } |
| 70 | for(; i >= (int(pad_x) + 1); i = i - 2) |
| 71 | { |
| 72 | vec2 s0 = LOAD_UNPACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * (i - int(pad_x) - 1)))); |
| 73 | vec2 s1 = LOAD_UNPACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * (i - int(pad_x) + 1)))); |
| 74 | vec2 s = vec2(s0.y, s1.x); |
| 75 | STORE_PACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * i)), s); |
| 76 | } |
| 77 | for(int j = 0; j < (int(pad_x) - 1); j = j + 2) |
| 78 | { |
| 79 | vec2 s_origin = vec2(0.f); |
| 80 | STORE_PACK2_CURRENT_ITEM_HALF(src_ptr, src_iter, s_origin); |
| 81 | TENSOR_ITERATOR_ADVANCE_IN_BYTES(src_iter, 4); |
| 82 | } |
| 83 | vec2 s0_origin = LOAD_UNPACK2_CURRENT_ITEM_HALF(src_ptr, src_iter); |
| 84 | vec2 s_origin = vec2(0.f, s0_origin.x); |
| 85 | STORE_PACK2_CURRENT_ITEM_HALF(src_ptr, src_iter, s_origin); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | int i = 0; |
| 90 | if((WIDTH % 2) == 0) |
| 91 | { |
| 92 | i = WIDTH + int(pad_x) - 2; |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | vec2 s0_end = LOAD_UNPACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * (WIDTH - 1)))); |
| 97 | vec2 s_end = vec2(s0_end.x, 0.f); |
| 98 | STORE_PACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * (WIDTH + int(pad_x) - 1))), s_end); |
| 99 | i = WIDTH + int(pad_x) - 3; |
| 100 | } |
| 101 | for(; i >= (int(pad_x)); i = i - 2) |
| 102 | { |
| 103 | vec2 s = LOAD_UNPACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * (i - int(pad_x))))); |
| 104 | STORE_PACK2_HALF(src_ptr, TENSOR_OFFSET_ADVANCE_IN_BYTES(src_iter, (2 * i)), s); |
| 105 | } |
| 106 | for(int j = 0; j < int(pad_x); j = j + 2) |
| 107 | { |
| 108 | vec2 s = vec2(0.f); |
| 109 | STORE_PACK2_CURRENT_ITEM_HALF(src_ptr, src_iter, s); |
| 110 | TENSOR_ITERATOR_ADVANCE_IN_BYTES(src_iter, 4); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | #elif defined(DATA_TYPE_FP32) |
| 115 | TENSOR_DECLARATION(1, srcBuffer, float, src_ptr, src_shift, 2, restrict); |
| 116 | |
| 117 | void main() |
| 118 | { |
| 119 | Tensor3DIterator src_iter = CONVERT_TO_TENSOR3D_ITERATOR(src_attrs, src_shift); |
| 120 | |
| 121 | for(int i = (WIDTH + int(pad_x) - 1); i >= int(pad_x); i--) |
| 122 | { |
| 123 | float sorigin = LOAD(src_ptr, TENSOR_OFFSET_ADVANCE(src_iter, (i - int(pad_x)))); |
| 124 | STORE(src_ptr, TENSOR_OFFSET_ADVANCE(src_iter, i), sorigin); |
| 125 | } |
| 126 | for(int j = 0; j < int(pad_x); j++) |
| 127 | { |
| 128 | STORE_CURRENT_ITEM(src_ptr, src_iter, 0.f); |
| 129 | TENSOR_ITERATOR_ADVANCE_IN_BYTES(src_iter, 4); |
| 130 | } |
| 131 | } |
| 132 | #else /* DATA_TYPE_FP16 */ |
| 133 | #error Data type not supported |
| 134 | #endif /* DATA_TYPE_FP16 */ |