Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / cl_kernels / one_hot_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 #include "include/include_all.cl"
16
17 #define GET_COORDS_INDEX(prefix, coords) GET_DATA_INDEX(prefix, coords[0], coords[1], coords[2], coords[3])
18
19 KERNEL(one_hot_ref)(
20     const __global INPUT0_TYPE* input,
21     __global INPUT0_TYPE* output)
22 {
23     uint in_coords[4] = { 0, get_global_id(0), get_global_id(1), get_global_id(2) };
24     uint out_coords[4] = { 0, get_global_id(0), get_global_id(1), get_global_id(2) };
25     for (uint i = 0; i < ONE_HOT_AXIS; ++i)
26         out_coords[i] = out_coords[i + 1];
27
28     // Fill the output with 0
29     for (out_coords[ONE_HOT_AXIS] = 0; out_coords[ONE_HOT_AXIS] < ONE_HOT_LIMIT; ++out_coords[ONE_HOT_AXIS])
30         output[GET_COORDS_INDEX(OUTPUT, out_coords)] = 0;
31
32     // Put in the 1; ignore bad input values
33     INPUT0_TYPE val = input[GET_COORDS_INDEX(INPUT0, in_coords)];
34     if (val >= 0 && val < ONE_HOT_LIMIT)
35     {
36         out_coords[ONE_HOT_AXIS] = val;
37         output[GET_COORDS_INDEX(OUTPUT, out_coords)] = 1;
38     }
39 }