Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / cl_kernels / average_unpooling_gpu_ref.cl
1 // Copyright (c) 2018 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
16 #include "include/include_all.cl"
17
18 KERNEL(average_unpooling_gpu)(const __global UNIT_TYPE* input, __global UNIT_TYPE* output)
19 {
20 #if OUTPUT_LAYOUT_BFYX  || OUTPUT_LAYOUT_BYXF
21     const uint x    = (uint)get_global_id(0);
22     const uint y    = (uint)get_global_id(1);
23     const uint bf   = (uint)get_global_id(2);
24     const uint f    = bf % INPUT0_FEATURE_NUM;
25     const uint b    = bf / INPUT0_FEATURE_NUM;    
26 #elif OUTPUT_LAYOUT_YXFB
27     const uint x    = (uint)get_global_id(1);
28     const uint y    = (uint)get_global_id(2);
29     const uint bf   = (uint)get_global_id(0);
30     const uint f    = bf / INPUT0_BATCH_NUM;
31     const uint b    = bf % INPUT0_BATCH_NUM;
32 #endif
33
34     if (x >= INPUT0_SIZE_X)
35     {
36         return;
37     }
38     
39     const uint x_begin = x * STRIDE_SIZE_X;
40     const uint y_begin = y * STRIDE_SIZE_Y;
41     const uint x_end = min((uint)(x_begin + UNPOOL_SIZE_X), (uint)(OUTPUT_SIZE_X));
42     const uint y_end = min((uint)(y_begin + UNPOOL_SIZE_Y), (uint)(OUTPUT_SIZE_Y));
43
44     const uint window_x = x_end - x_begin;
45     const uint window_y = y_end - y_begin;
46
47     const uint input_offset = GET_DATA_INDEX(INPUT0, b, f, y, x);
48     uint out_index = GET_DATA_INDEX(OUTPUT, b, f, y_begin, x_begin);
49     UNIT_TYPE out_val = input[input_offset] / (window_x * window_y);
50
51     for(uint j = 0; j < window_y; j++)
52     {
53         for(uint i = 0; i < window_x; i++)
54         {
55             output[out_index] += ACTIVATION(out_val, NL_M ,NL_N);
56             out_index += OUTPUT_X_PITCH;
57         }
58         out_index += OUTPUT_Y_PITCH - window_x * OUTPUT_X_PITCH;
59     }
60 }