Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / gpu / kernel.h
1 /*
2 // Copyright (c) 2016 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 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #pragma once
19
20 #include "ocl_toolkit.h"
21 #include "memory_impl.h"
22 #include "kernels_cache.h"
23 #include "event_impl.h"
24
25 #include "kernel_selector_helper.h"
26
27 namespace cldnn { namespace gpu {
28
29 class kernel : public context_holder 
30 {
31     kernels_cache::kernel_id _kernel_id;
32     bool _one_time_kernel; //If this flag is true, the kernel is intended to be executed only once (can be removed later from the cache).
33
34 public:
35     explicit kernel(std::shared_ptr<gpu_toolkit> context, const std::shared_ptr<kernel_selector::kernel_string>& kernel_string, bool dump_custom_program = false, bool one_time_kernel = false)
36         : context_holder(context)
37         , _kernel_id(context->get_kernels_cache().set_kernel_source(kernel_string, dump_custom_program, one_time_kernel)) 
38                 , _one_time_kernel(one_time_kernel)
39     {}
40
41     kernel(const kernel& other) : context_holder(other.context()), _kernel_id(other._kernel_id), _one_time_kernel(other._one_time_kernel) {}
42
43     kernel& operator=(const kernel& other) 
44     {
45         if (this == &other)
46         {
47             return *this;
48         }
49
50         _kernel_id = other._kernel_id;
51         _one_time_kernel = other._one_time_kernel;
52
53         return *this;
54     }
55
56     struct kernel_arguments_data
57     {
58         std::vector<memory_impl::cptr> inputs;
59         std::vector<memory_impl::cptr> intermediates;
60         memory_impl::cptr output;
61         memory_impl::cptr weights;
62         memory_impl::cptr recurrent;
63         memory_impl::cptr hidden;
64         memory_impl::cptr cell;
65         memory_impl::cptr bias;
66         memory_impl::cptr weights_quantization_factors;
67         memory_impl::cptr output_calibration_factors;
68         memory_impl::cptr lookup_table;
69         memory_impl::cptr scale_table;
70         memory_impl::cptr slope;
71         memory_impl::cptr prev_weights_grad;
72         memory_impl::cptr prev_bias_grad;
73         // used for fused primitives
74         std::vector<memory_impl::cptr> fused_op_calibration_factors;
75         int32_t           split          = 0;
76         float             lr;
77         const kernel_selector::kernel_scalar_arguments* scalars = nullptr;
78     };
79
80     void set_output_event(bool is_out_event) { context()->set_output_event(is_out_event); }
81
82     event_impl::ptr run(
83         const kernel_selector::cl_kernel_data& kernel_data,
84         const std::vector<event_impl::ptr>& dependencies,
85         const kernel_arguments_data& args) const;
86 };
87
88 } }