Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / reverse_sequence / reverse_sequence_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 "reverse_sequence_kernel_ref.h"
18 #include "kernel_selector_utils.h"
19
20 namespace kernel_selector
21 {
22     ParamsKey ReverseSequenceKernelRef::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.EnableAllInputLayout();
30         k.EnableAllOutputLayout();
31         k.EnableTensorOffset();
32         k.EnableTensorPitches();
33         k.EnableBatching();
34         k.EnableDifferentTypes();
35         return k;
36     }
37
38     CommonDispatchData ReverseSequenceKernelRef::SetDefault(const reverse_sequence_params& params, const optional_params&) const
39     {
40         CommonDispatchData runInfo;
41
42         std::vector<size_t> global = { params.output.Batch().v, params.output.Feature().v, params.output.Y().v * params.output.X().v };
43
44         auto local = GetOptimalLocalWorkGroupSizes(global);
45
46         runInfo.gws0 = global[0];
47         runInfo.gws1 = global[1];
48         runInfo.gws2 = global[2];
49
50         runInfo.lws0 = local[0];
51         runInfo.lws1 = local[1];
52         runInfo.lws2 = local[2];
53
54         return runInfo;
55     }
56
57     JitConstants ReverseSequenceKernelRef::GetJitConstants(const reverse_sequence_params& params) const
58     {
59         JitConstants jit = MakeBaseParamsJitConstants(params);
60
61         jit.AddConstant(MakeJitConstant("SEQ_AXIS", params.seq_axis));
62         jit.AddConstant(MakeJitConstant("BATCH_AXIS", params.batch_axis));
63
64         return jit;
65     }
66
67     KernelsData ReverseSequenceKernelRef::GetKernelsData(const Params& params, const optional_params& options) const
68     {
69         KernelData kd = KernelData::Default<reverse_sequence_params>(params);
70         reverse_sequence_params& newParams = *static_cast<reverse_sequence_params*>(kd.params.get());
71
72         assert(params.GetType() == KernelType::REVERSE_SEQUENCE);
73
74         auto runInfo = SetDefault(newParams, options);
75         auto entry_point = GetEntryPoint(kernelName, newParams.layerID, options);
76         auto cldnn_jit = GetJitConstants(newParams);
77         std::string jit = CreateJit(kernelName, cldnn_jit, entry_point);
78
79         auto& kernel = kd.kernels[0];
80
81         FillCLKernelData(kernel, runInfo, params.engineInfo, kernelName, jit, entry_point, "", false, false, 2);
82
83         kd.estimatedTime = DONT_USE_IF_HAVE_SOMETHING_ELSE;
84
85         return{ kd };
86     }
87 }