Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / lstm / lstm_gemm_kernel_base.h
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 #pragma once
18
19 #include "common_kernel_base.h"
20 #include "kernel_selector_params.h"
21
22 namespace kernel_selector
23 {
24     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25     // lstm_gemm_params
26     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27     struct lstm_gemm_params : public base_params
28     {
29         lstm_gemm_params() : base_params(KernelType::LSTM_GEMM) {}
30
31         DataTensor weights;
32         DataTensor recurrent;
33         DataTensor bias;
34         DataTensor hidden;
35         bool hasBias = false;
36         bool hasHidden = false;
37
38         void SetBias(const DataTensor& v) {
39             bias = v;
40             hasBias = true;
41         }
42
43         void SetHidden(const DataTensor& v) {
44             hidden = v;
45             hasHidden = true;
46         }
47
48         virtual ParamsKey GetParamsKey() const override
49         {
50             ParamsKey k = base_params::GetParamsKey();
51
52             if (hasBias)
53             {
54                 k.EnableLSTMGEMMBias();
55             }
56
57             if (hasHidden)
58             {
59                 k.EnableLSTMGEMMHidden();
60             }
61
62             return k;
63         }
64     };
65
66     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67     // lstm_gemm_optional_params
68     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69     struct lstm_gemm_optional_params : optional_params
70     {
71         lstm_gemm_optional_params() : optional_params(KernelType::LSTM_GEMM) {}
72     };
73
74     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75     // LSTMGemmKernelBase
76     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77     class LSTMGemmKernelBase : public common_kernel_base
78     {
79     public:
80                 using common_kernel_base::common_kernel_base;
81         virtual ~LSTMGemmKernelBase() {}
82
83         struct DispatchData : public CommonDispatchData
84         {};
85
86     protected:
87         virtual JitConstants GetJitConstants(const lstm_gemm_params& params) const;
88         KernelsData GetCommonKernelsData(const Params& params, const optional_params& optParams) const;
89
90         bool Validate(const Params& p, const optional_params&) const override
91         {
92             if (p.GetType() != KernelType::LSTM_GEMM)
93             {
94                 return false;
95             }
96
97             return true;
98         }
99     };
100 }