Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / cl_kernels / shuffle_channels_ref.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
16 #include "include/include_all.cl"
17
18 KERNEL(shuffle_channels_ref)(const __global UNIT_TYPE* input, __global UNIT_TYPE* output)
19 {
20     const uint batch = get_global_id(0);
21     const uint feature = get_global_id(1);
22     const uint y = get_global_id(2) / OUTPUT_SIZE_X;
23     const uint x = get_global_id(2) % OUTPUT_SIZE_X;
24     const uint dimensions[] = { batch, feature, y, x };
25
26     const uint current_group = dimensions[AXIS] / GROUP_SIZE;
27     const uint position_in_group = dimensions[AXIS] % GROUP_SIZE;
28     const uint input_index = INPUT0_OFFSET + (batch * INPUT0_BATCH_PITCH) + (feature * INPUT0_FEATURE_PITCH) + (y * INPUT0_Y_PITCH) + x;
29
30     uint output_index = OUTPUT_OFFSET;
31
32     for (uint i = 0; i < AXIS; ++i) {
33         output_index += dimensions[i] * INPUT0_PITCHES[INPUT0_DIMS - i - 1];
34     }
35
36     output_index += (position_in_group * GROUPS_NUMBER + current_group) * INPUT0_PITCHES[INPUT0_DIMS - AXIS - 1];
37
38     for (uint i = AXIS + 1; i < INPUT0_DIMS; ++i) {
39         output_index += dimensions[i] * INPUT0_PITCHES[INPUT0_DIMS - i - 1];
40     }
41
42     output[output_index] = input[input_index];
43 }