2 // Copyright (c) 2018 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "embed_kernel_ref.h"
18 #include "kernel_selector_utils.h"
19 #include "common_tools.h"
21 namespace kernel_selector
24 ParamsKey EmbedKernelRef::GetSupportedKey() const
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();
43 k.EnableNonBiasTerm();
47 JitConstants EmbedKernelRef::GetJitConstants(const embed_params& params) const
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));
59 EmbedKernelRef::DispatchData EmbedKernelRef::SetDefault(const embed_params& params) const
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);
76 KernelsData EmbedKernelRef::GetKernelsData(const Params& params, const optional_params& options) const
78 assert(params.GetType() == KernelType::EMBED);
80 const embed_params& orgParams = static_cast<const embed_params&>(params);
82 const std::vector<WeightsLayout> weightsLayouts = {
86 DispatchData runInfo = SetDefault(orgParams);
87 KernelData kd = KernelData::Default<embed_params>(params);
88 embed_params& newParams = *static_cast<embed_params*>(kd.params.get());
90 bool succeed = UpdateWeightsParams(
94 kd.weightsReorderParams);
101 auto cldnn_jit = GetJitConstants(newParams);
102 auto entry_point = GetEntryPoint(kernelName, newParams.layerID, options);
103 auto jit = CreateJit(kernelName, cldnn_jit, entry_point);
105 auto& kernel = kd.kernels[0];
107 FillCLKernelData(kernel, runInfo, params.engineInfo, kernelName, jit, entry_point, DEFAULT, true, !newParams.bias.empty());
109 kd.estimatedTime = runInfo.effiency;