blob: f3cb52eb9e8d098191d8e467e421b5e8f8fc8bf5 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
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
25layout(local_size_x = LOCAL_SIZE_X, local_size_y = LOCAL_SIZE_Y, local_size_z = LOCAL_SIZE_Z) in;
26
zhenglin07d40542018-01-04 15:50:59 +080027#include "helpers_cs.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010028
zhenglin07d40542018-01-04 15:50:59 +080029/** Apply cross map normalization and in map normalization
Anthony Barbier7068f992017-10-26 15:23:08 +010030 *
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 *
zhenglin07d40542018-01-04 15:50:59 +080036 * @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 Barbier7068f992017-10-26 15:23:08 +010042 */
zhenglin07d40542018-01-04 15:50:59 +080043SHADER_PARAMS_DECLARATION
44{
45 Tensor3DAttributes src1_attrs;
46 Tensor3DAttributes src2_attrs;
47 Tensor3DAttributes dst_attrs;
48};
49TENSOR_DECLARATION(1, src1Buffer, float, src1_ptr, src1_shift, 2, readonly);
50TENSOR_DECLARATION(2, src2Buffer, float, src2_ptr, src2_shift, 2, readonly);
51TENSOR_DECLARATION(3, dstBuffer, float, dst_ptr, dst_shift, 2, writeonly);
52
53#ifdef CROSS_MAP
Anthony Barbier7068f992017-10-26 15:23:08 +010054void main(void)
55{
zhenglin07d40542018-01-04 15:50:59 +080056 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 Barbier7068f992017-10-26 15:23:08 +010059
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 {
zhenglin07d40542018-01-04 15:50:59 +080070 acc += LOAD(src2_ptr, TENSOR3D_OFFSET(src2_iter, 0, 0, i - current_slice));
Anthony Barbier7068f992017-10-26 15:23:08 +010071 }
72
73 float normalized = pow(float(KAPPA) + float(COEFF) * acc, float(BETA));
74
zhenglin07d40542018-01-04 15:50:59 +080075 float normalized_pixel = (LOAD_CURRENT_ITEM(src1_ptr, src1_iter)) / normalized;
Anthony Barbier7068f992017-10-26 15:23:08 +010076
zhenglin07d40542018-01-04 15:50:59 +080077 STORE_CURRENT_ITEM(dst_ptr, dst_iter, normalized_pixel);
Anthony Barbier7068f992017-10-26 15:23:08 +010078}
79
80#elif defined(IN_MAP_1D)
Anthony Barbier7068f992017-10-26 15:23:08 +010081void main(void)
82{
zhenglin07d40542018-01-04 15:50:59 +080083 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 Barbier7068f992017-10-26 15:23:08 +010086
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 {
zhenglin07d40542018-01-04 15:50:59 +080097 acc += LOAD(src2_ptr, TENSOR3D_OFFSET(src2_iter, i - current_pos, 0, 0));
Anthony Barbier7068f992017-10-26 15:23:08 +010098 }
99
100 float normalized = pow(float(KAPPA) + float(COEFF) * acc, float(BETA));
101
zhenglin07d40542018-01-04 15:50:59 +0800102 float normalized_pixel = (LOAD_CURRENT_ITEM(src1_ptr, src1_iter)) / normalized;
Anthony Barbier7068f992017-10-26 15:23:08 +0100103
zhenglin07d40542018-01-04 15:50:59 +0800104 STORE_CURRENT_ITEM(dst_ptr, dst_iter, normalized_pixel);
Anthony Barbier7068f992017-10-26 15:23:08 +0100105}
106#endif /*CROSS_MAP*/