7ddc661e8fe4c01f8de79203dbfa955491528201
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / reorder / reorder_kernel_binary.cpp
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 "reorder_kernel_binary.h"
17 #include "kernel_selector_utils.h"
18 #include <vector>
19
20 namespace kernel_selector {
21 ParamsKey ReorderKernelBinary::GetSupportedKey() const {
22     ParamsKey k;
23     k.EnableInputDataType(Datatype::F16);
24     k.EnableInputDataType(Datatype::F32);
25     k.EnableInputDataType(Datatype::BINARY);
26     k.EnableOutputDataType(Datatype::BINARY);
27     k.EnableOutputDataType(Datatype::F32);
28     k.EnableOutputDataType(Datatype::F16);
29     k.EnableDifferentTypes();
30     k.EnableInputLayout(DataLayout::bfyx);
31     k.EnableInputLayout(DataLayout::b_fs_yx_32fp);
32     k.EnableOutputLayout(DataLayout::b_fs_yx_32fp);
33     k.EnableOutputLayout(DataLayout::bfyx);
34     k.EnableTensorOffset();
35     k.EnableTensorPitches();
36     k.EnableBatching();
37     return k;
38 }
39
40 JitConstants ReorderKernelBinary::GetJitConstants(const reorder_params& params) const {
41     auto jit = ReorderKernelBase::GetJitConstants(params);
42     KernelData kd = KernelData::Default<reorder_params>(params);
43     reorder_params& newParams = *static_cast<reorder_params*>(kd.params.get());
44
45     const auto& input = newParams.inputs[0];
46     jit.AddConstant(MakeJitConstant("ELEMENTS_COUNT", input.LogicalSize()));
47     jit.AddConstant(MakeJitConstant("IFM_PACK_SIZE", 32));
48
49     if (input.GetDType() == Datatype::BINARY) {
50         jit.AddConstant(MakeJitConstant("BINARY_INPUT", 1));
51         jit.AddConstant(MakeJitConstant("INPUT_PACKED_FEATURES_NUM", CeilDiv(input.Feature().v, 16)));
52     }
53
54     if (params.output.GetDType() == Datatype::BINARY) {
55         jit.AddConstant(MakeJitConstant("BINARY_OUTPUT", 1));
56         jit.AddConstant(MakeJitConstant("OUTPUT_PACKED_FEATURES_NUM", CeilDiv(params.output.Feature().v, 32)));
57     }
58
59     return jit;
60 }
61
62 ReorderKernelBinary::DispatchData ReorderKernelBinary::SetDefault(const reorder_params& params) const {
63     DispatchData kd;
64
65     const auto& input = params.inputs[0];
66
67     std::vector<size_t> global{input.Batch().v, CeilDiv(input.Feature().v, 32), input.Y().v * input.X().v};
68     auto local = GetOptimalLocalWorkGroupSizes(global);
69
70     kd.gws0 = global[0];
71     kd.gws1 = global[1];
72     kd.gws2 = global[2];
73
74     kd.lws0 = local[0];
75     kd.lws1 = local[1];
76     kd.lws2 = local[2];
77
78     return kd;
79 }
80
81 KernelsData ReorderKernelBinary::GetKernelsData(const Params& params, const optional_params& options) const {
82     assert(params.GetType() == KernelType::REORDER);
83
84     const reorder_params& orgParams = static_cast<const reorder_params&>(params);
85
86     if (orgParams.inputs[0].GetDType() != Datatype::BINARY &&
87         orgParams.output.GetDType() != Datatype::BINARY)
88         return {};
89
90     if (orgParams.inputs[0].GetDType() == Datatype::BINARY &&
91         orgParams.inputs[0].GetLayout() != DataLayout::b_fs_yx_32fp)
92         return {};
93
94     if (orgParams.output.GetDType() == Datatype::BINARY &&
95         orgParams.output.GetLayout() != DataLayout::b_fs_yx_32fp)
96         return {};
97
98     auto estimatedTime = FORCE_PRIORITY_6;
99
100     return GetCommonKernelsData(orgParams, options, estimatedTime);
101 }
102 }  // namespace kernel_selector