Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / embed / embed_kernel_ref.cpp
1 /*
2 // Copyright (c) 2018 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 "embed_kernel_ref.h"
18 #include "kernel_selector_utils.h"
19 #include "common_tools.h"
20
21 namespace kernel_selector
22 {
23
24         ParamsKey EmbedKernelRef::GetSupportedKey() const
25         {
26                 ParamsKey k;
27                 k.EnableInputDataType(Datatype::F16);
28                 k.EnableInputDataType(Datatype::F32);
29                 k.EnableInputDataType(Datatype::INT8);
30                 k.EnableOutputDataType(Datatype::F16);
31                 k.EnableOutputDataType(Datatype::F32);
32                 k.EnableOutputDataType(Datatype::INT8);
33                 k.EnableInputWeightsType(WeightsType::F16);
34                 k.EnableInputWeightsType(WeightsType::F32);
35                 k.EnableInputWeightsType(WeightsType::INT8);
36         k.EnableAllInputLayout();
37                 k.EnableOutputLayout(DataLayout::bf);
38                 k.EnableBiasPerOutput();
39                 k.EnableBiasPerFeature();
40                 k.EnableTensorOffset();
41                 k.EnableTensorPitches();
42                 k.EnableBatching();
43         k.EnableNonBiasTerm();
44                 return k;
45         }
46
47         JitConstants EmbedKernelRef::GetJitConstants(const embed_params& params) const
48         {
49         JitConstants jit = WeightBiasKernelBase::GetJitConstants(params);
50         const auto& input = params.inputs[0];
51         const auto x_size = input.LogicalSize() / input.Batch().v;
52         const auto w_size = params.weights.OFM().v;
53         jit.AddConstant(MakeJitConstant("INPUT0_ELEMENTS_COUNT", x_size));
54         jit.AddConstant(MakeJitConstant("NUM_OUTPUT_SIZE", w_size));
55
56         return jit;
57         }
58
59         EmbedKernelRef::DispatchData EmbedKernelRef::SetDefault(const embed_params& params) const
60         {
61                 DispatchData kd;
62                 std::vector<size_t> global = { params.inputs[0].X().v , params.weights.OFM().v, params.inputs[0].Batch().v };
63                 std::vector<size_t> local = GetOptimalLocalWorkGroupSizes(global);
64
65                 kd.gws0 = global[0];
66                 kd.gws1 = global[1];
67                 kd.gws2 = global[2];
68
69                 kd.lws0 = local[0];
70                 kd.lws1 = local[1];
71                 kd.lws2 = 1;
72                 return kd;
73
74         }
75
76         KernelsData EmbedKernelRef::GetKernelsData(const Params& params, const optional_params& options) const
77         {
78                 assert(params.GetType() == KernelType::EMBED);
79
80                 const embed_params& orgParams = static_cast<const embed_params&>(params);
81
82                 const std::vector<WeightsLayout> weightsLayouts = {
83                         WeightsLayout::oiyx,
84                 };
85
86                 DispatchData runInfo = SetDefault(orgParams);
87                 KernelData kd = KernelData::Default<embed_params>(params);
88                 embed_params& newParams = *static_cast<embed_params*>(kd.params.get());
89
90                 bool succeed = UpdateWeightsParams(
91                         newParams,
92                         options,
93                         weightsLayouts,
94                         kd.weightsReorderParams);
95
96                 if (!succeed)
97                 {
98                         return{};
99                 }
100
101                 auto cldnn_jit = GetJitConstants(newParams);
102                 auto entry_point = GetEntryPoint(kernelName, newParams.layerID, options);
103                 auto jit = CreateJit(kernelName, cldnn_jit, entry_point);
104
105                 auto& kernel = kd.kernels[0];
106
107                 FillCLKernelData(kernel, runInfo, params.engineInfo, kernelName, jit, entry_point, DEFAULT, true, !newParams.bias.empty());
108
109                 kd.estimatedTime = runInfo.effiency;
110
111                 return{ kd };
112         }
113
114         
115 }