1 // Copyright (c) 2018 Intel Corporation
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "include/include_all.cl"
18 KERNEL(average_unpooling_gpu)(const __global UNIT_TYPE* input, __global UNIT_TYPE* output)
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;
34 if (x >= INPUT0_SIZE_X)
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));
44 const uint window_x = x_end - x_begin;
45 const uint window_y = y_end - y_begin;
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);
51 for(uint j = 0; j < window_y; j++)
53 for(uint i = 0; i < window_x; i++)
55 output[out_index] += ACTIVATION(out_val, NL_M ,NL_N);
56 out_index += OUTPUT_X_PITCH;
58 out_index += OUTPUT_Y_PITCH - window_x * OUTPUT_X_PITCH;