2 // Copyright (c) 2016 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 ///////////////////////////////////////////////////////////////////////////////////////////////////
20 #include "ocl_toolkit.h"
21 #include "memory_impl.h"
22 #include "kernels_cache.h"
23 #include "event_impl.h"
25 #include "kernel_selector_helper.h"
27 namespace cldnn { namespace gpu {
29 class kernel : public context_holder
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).
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)
41 kernel(const kernel& other) : context_holder(other.context()), _kernel_id(other._kernel_id), _one_time_kernel(other._one_time_kernel) {}
43 kernel& operator=(const kernel& other)
50 _kernel_id = other._kernel_id;
51 _one_time_kernel = other._one_time_kernel;
56 struct kernel_arguments_data
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;
77 const kernel_selector::kernel_scalar_arguments* scalars = nullptr;
80 void set_output_event(bool is_out_event) { context()->set_output_event(is_out_event); }
83 const kernel_selector::cl_kernel_data& kernel_data,
84 const std::vector<event_impl::ptr>& dependencies,
85 const kernel_arguments_data& args) const;