Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
| 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 | layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in; |
| 26 | |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 27 | #include "helpers_cs.h" |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 28 | |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 29 | /** Apply cross map normalization and in map normalization |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 30 | * |
| 31 | * @note Alpha parameter / norm_size should be given as a preprocessor argument using "#define COEFF x" |
| 32 | * @note BETA parameter in the normalization equation should be given as a preprocessor argument using "#define BETA x" |
| 33 | * @note KAPPA parameter in the normalization equation should be given as a preprocessor argument using "#define KAPPA x" |
| 34 | * @note Number of elements on the right or left side to normalize across should be given as a preprocessor argument using "#define RADIUS x" |
| 35 | * |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 36 | * @param[in] src1_ptr Pointer to the first source tensor. Supported data types: F32 |
| 37 | * @param[in] src1_attrs The attributes of the first source tensor |
| 38 | * @param[in] src2_ptr Pointer to the second source tensor. Supported data types: Same as @p src1_ptr |
| 39 | * @param[in] src2_attrs The attributes of the second source tensor |
| 40 | * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: Same as @p src1_ptr |
| 41 | * @param[in] dst_attrs The attributes of the destination tensor |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 42 | */ |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 43 | SHADER_PARAMS_DECLARATION |
| 44 | { |
| 45 | Tensor3DAttributes src1_attrs; |
| 46 | Tensor3DAttributes src2_attrs; |
| 47 | Tensor3DAttributes dst_attrs; |
| 48 | }; |
| 49 | TENSOR_DECLARATION(1, src1Buffer, float, src1_ptr, src1_shift, 2, readonly); |
| 50 | TENSOR_DECLARATION(2, src2Buffer, float, src2_ptr, src2_shift, 2, readonly); |
| 51 | TENSOR_DECLARATION(3, dstBuffer, float, dst_ptr, dst_shift, 2, writeonly); |
| 52 | |
| 53 | #ifdef CROSS_MAP |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 54 | void main(void) |
| 55 | { |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 56 | Tensor3DIterator src1_iter = CONVERT_TO_TENSOR3D_ITERATOR(src1_attrs, src1_shift); |
| 57 | Tensor3DIterator src2_iter = CONVERT_TO_TENSOR3D_ITERATOR(src2_attrs, src2_shift); |
| 58 | Tensor3DIterator dst_iter = CONVERT_TO_TENSOR3D_ITERATOR(dst_attrs, dst_shift); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 59 | |
| 60 | float acc = 0.0; |
| 61 | |
| 62 | int num_of_slices = int(gl_NumWorkGroups.z * gl_WorkGroupSize.z); |
| 63 | int current_slice = int(gl_GlobalInvocationID.z); |
| 64 | |
| 65 | int left_slice = max(current_slice - int(RADIUS), int(0)); |
| 66 | int right_slice = min(current_slice + int(RADIUS), int(num_of_slices - 1)); |
| 67 | |
| 68 | for(int i = left_slice; i <= right_slice; i++) |
| 69 | { |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 70 | acc += LOAD(src2_ptr, TENSOR3D_OFFSET(src2_iter, 0, 0, i - current_slice)); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | float normalized = pow(float(KAPPA) + float(COEFF) * acc, float(BETA)); |
| 74 | |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 75 | float normalized_pixel = (LOAD_CURRENT_ITEM(src1_ptr, src1_iter)) / normalized; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 76 | |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 77 | STORE_CURRENT_ITEM(dst_ptr, dst_iter, normalized_pixel); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | #elif defined(IN_MAP_1D) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 81 | void main(void) |
| 82 | { |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 83 | Tensor3DIterator src1_iter = CONVERT_TO_TENSOR3D_ITERATOR(src1_attrs, src1_shift); |
| 84 | Tensor3DIterator src2_iter = CONVERT_TO_TENSOR3D_ITERATOR(src2_attrs, src2_shift); |
| 85 | Tensor3DIterator dst_iter = CONVERT_TO_TENSOR3D_ITERATOR(dst_attrs, dst_shift); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 86 | |
| 87 | float acc = 0.0; |
| 88 | |
| 89 | int num_of_items_x = int(gl_NumWorkGroups.x * gl_WorkGroupSize.x); |
| 90 | int current_pos = int(gl_GlobalInvocationID.x); |
| 91 | |
| 92 | int left_pos = max(current_pos - int(RADIUS), int(0)); |
| 93 | int right_pos = min(current_pos + int(RADIUS), int(num_of_items_x + -1)); |
| 94 | |
| 95 | for(int i = left_pos; i <= right_pos; i++) |
| 96 | { |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 97 | acc += LOAD(src2_ptr, TENSOR3D_OFFSET(src2_iter, i - current_pos, 0, 0)); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | float normalized = pow(float(KAPPA) + float(COEFF) * acc, float(BETA)); |
| 101 | |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 102 | float normalized_pixel = (LOAD_CURRENT_ITEM(src1_ptr, src1_iter)) / normalized; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 103 | |
zhenglin | 07d4054 | 2018-01-04 15:50:59 +0800 | [diff] [blame^] | 104 | STORE_CURRENT_ITEM(dst_ptr, dst_iter, normalized_pixel); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 105 | } |
| 106 | #endif /*CROSS_MAP*/ |