Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / shuffle_channels / shuffle_channels_kernel_ref.cpp
1 /*
2 // Copyright (c) 2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include "shuffle_channels_kernel_ref.h"
18 #include "kernel_selector_utils.h"
19
20 namespace kernel_selector
21 {
22     ParamsKey ShuffleChannelsKernelRef::GetSupportedKey() const
23     {
24         ParamsKey k;
25         k.EnableInputDataType(Datatype::F16);
26         k.EnableInputDataType(Datatype::F32);
27         k.EnableOutputDataType(Datatype::F16);
28         k.EnableOutputDataType(Datatype::F32);
29         k.EnableInputLayout(DataLayout::bfyx);
30         k.EnableOutputLayout(DataLayout::bfyx);
31         k.EnableTensorOffset();
32         k.EnableTensorPitches();
33         k.EnableBatching();
34         return k;
35     }
36
37     CommonDispatchData ShuffleChannelsKernelRef::SetDefault(const shuffle_channels_params& params, const optional_params&) const
38     {
39         CommonDispatchData runInfo;
40
41         std::vector<size_t> global = { params.output.Batch().v, params.output.Feature().v, params.output.Y().v * params.output.X().v };
42
43         auto local = GetOptimalLocalWorkGroupSizes(global);
44
45         runInfo.gws0 = global[0];
46         runInfo.gws1 = global[1];
47         runInfo.gws2 = global[2];
48
49         runInfo.lws0 = local[0];
50         runInfo.lws1 = local[1];
51         runInfo.lws2 = local[2];
52
53         return runInfo;
54     }
55
56     JitConstants ShuffleChannelsKernelRef::GetJitConstants(const shuffle_channels_params& params) const
57     {
58         JitConstants jit = MakeBaseParamsJitConstants(params);
59
60         jit.AddConstant(MakeJitConstant("GROUPS_NUMBER", params.group));
61
62         auto getDimSizeByAxis = [](const shuffle_channels_params& params) -> size_t {
63             switch (params.axis) {
64                 case 0:
65                     return params.inputs[0].Batch().v;
66                 case 1:
67                     return params.inputs[0].Feature().v;
68                 case 2:
69                     return params.inputs[0].Y().v;
70                 case 3:
71                     return params.inputs[0].X().v;
72             }
73             return 0;
74         };
75
76         jit.AddConstant(MakeJitConstant("GROUP_SIZE", getDimSizeByAxis(params) / params.group));
77         jit.AddConstant(MakeJitConstant("AXIS", params.axis));
78
79         return jit;
80     }
81
82     KernelsData ShuffleChannelsKernelRef::GetKernelsData(const Params& params, const optional_params& options) const
83     {
84         KernelData kd = KernelData::Default<shuffle_channels_params>(params);
85         shuffle_channels_params& newParams = *static_cast<shuffle_channels_params*>(kd.params.get());
86
87         assert(params.GetType() == KernelType::SHUFFLE_CHANNELS);
88
89         auto runInfo = SetDefault(newParams, options);
90         auto entry_point = GetEntryPoint(kernelName, newParams.layerID, options);
91         auto cldnn_jit = GetJitConstants(newParams);
92         std::string jit = CreateJit(kernelName, cldnn_jit, entry_point);
93
94         auto& kernel = kd.kernels[0];
95
96         FillCLKernelData(kernel, runInfo, params.engineInfo, kernelName, jit, entry_point);
97
98         kd.estimatedTime = DONT_USE_IF_HAVE_SOMETHING_ELSE;
99
100         return{ kd };
101     }
102 }