Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / kernel_base.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 #pragma once
18
19 #include "kernel_selector_common.h"
20 #include "kernel_selector_params.h"
21 #include "primitive_db.h"
22
23 namespace kernel_selector 
24 {
25     using primitive_db = kernel_selector::gpu::cache::primitive_db;
26
27     class KernelBase
28     {
29     public:
30         KernelBase(const std::string name) : kernelName(name) {}
31         virtual ~KernelBase() {}
32
33         virtual KernelsData GetKernelsData(const Params& params, const optional_params& options) const = 0;
34         virtual KernelsData GetKernelsDataForAutoTune(const Params& params, const optional_params& options) const
35         {
36             return GetKernelsData(params, options);
37         }
38         virtual KernelsData GetTunedKernelsDataByIndex(const Params& params, const optional_params& options, int /*autoTuneIndex*/) const
39         {
40             return GetKernelsData(params, options);
41         }
42
43         virtual bool Supports(const Params& params, const optional_params& options) const
44         {
45             const ParamsKey requireKey = params.GetParamsKey().Merge(options.GetSupportedKey());
46             return GetSupportedKey().Support(requireKey);
47         }
48
49         bool SupportsTuning() const
50         {
51             return GetSupportedKey().TuningSupport();
52         }
53
54         virtual const std::string GetName() const { return kernelName; }
55
56         static const primitive_db& get_db() { return db; }
57     
58     protected:
59         static const primitive_db db;
60         const std::string kernelName;
61
62         static size_t UniqeID() { return counter++; } // TODO: use interlocked
63         virtual ParamsKey GetSupportedKey() const = 0;
64         
65     private:
66         static size_t counter;
67     };
68 }