Publishing 2019 R2 content (#223)
[platform/upstream/dldt.git] / inference-engine / src / vpu / custom_kernels / grn.cl
1 // Copyright (C) 2019 Intel Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
16
17 __kernel void grn_NCHW(__global const half* restrict src_data,
18                        __global       half* restrict dst_data,
19                        int C,
20                        float bias)
21 {
22     int x = get_global_id(0);
23     int W = get_global_size(0);
24
25     int y = get_global_id(1);
26     int H = get_global_size(1);
27
28     float variance = bias + 1e-9f;
29
30     #pragma unroll 4
31     for (int c = 0; c < C; c++)
32     {
33         float val = (float)src_data[c*H*W + y*W + x];
34         variance += val * val;
35     }
36
37     variance = 1.f / native_sqrt(variance);
38
39     #pragma unroll 4
40     for (int c = 0; c < C; c++)
41     {
42         float val = (float)src_data[c*H*W + y*W + x];
43         dst_data[c*H*W + y*W + x] = (half)(val * variance);
44     }
45 }