Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / cl_kernels / broadcast_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 #include "include/include_all.cl"
16
17
18 KERNEL(broadcast_gpu_ref)(
19     const __global INPUT0_TYPE* input,
20     __global INPUT0_TYPE* output)
21 {
22     // [CONSTEXPR]
23     // Input sizes:
24     uint4 input_indices;
25     input_indices[0] = INPUT0_BATCH_NUM;
26     input_indices[1] = INPUT0_FEATURE_NUM;
27     input_indices[2] = INPUT0_SIZE_Y;
28     input_indices[3] = INPUT0_SIZE_X;
29
30     const uint in_sx = input_indices[BROADCAST_ORDER[3]];
31     const uint in_sy = input_indices[BROADCAST_ORDER[2]];
32     const uint in_sf = input_indices[BROADCAST_ORDER[1]];
33     const uint in_sb = input_indices[BROADCAST_ORDER[0]];
34
35     const uint out_x  = (uint) get_global_id(0);
36     const uint out_y  = (uint) get_global_id(1);
37     const uint out_fb = (uint) get_global_id(2);
38
39     const uint out_f  = out_fb % OUTPUT_FEATURE_NUM;
40     const uint out_b  = out_fb / OUTPUT_FEATURE_NUM;
41
42
43     const uint in_x = out_x % in_sx;
44     const uint in_y = out_y % in_sy;
45     const uint in_f = out_f % in_sf;
46     const uint in_b = out_b % in_sb;
47
48     const uint in_pos =  INPUT0_OFFSET + in_x + in_sx * (in_y + in_sy * (in_f + in_sf * in_b));
49     const uint out_pos = GET_DATA_INDEX(OUTPUT, out_b, out_f, out_y, out_x);
50
51     output[out_pos] = input[in_pos];
52 }