Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / gpu / lrn_gpu.cpp
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 #include "lrn_inst.h"
18 #include "primitive_gpu_base.h"
19 #include "implementation_map.h"
20 #include "error_handler.h"
21 #include "kernel_selector_helper.h"
22 #include "lrn/lrn_kernel_selector.h"
23 #include "lrn/lrn_kernel_base.h"
24
25 namespace cldnn { namespace gpu {
26
27     
28 struct lrn_gpu : typed_primitive_gpu_impl<lrn>
29 {
30     using parent = typed_primitive_gpu_impl<lrn>;
31     using parent::parent;
32
33     static primitive_impl* create(const lrn_node& arg) 
34     {
35         auto lrn_params = get_default_params<kernel_selector::lrn_params>(arg);
36         auto lrn_optional_params = get_default_optional_params<kernel_selector::lrn_optional_params>(arg.get_program());
37
38         const auto& primitive = arg.get_primitive();
39
40         lrn_params.alpha      = primitive->alpha;
41         lrn_params.beta       = primitive->beta;
42         lrn_params.k          = primitive->k;
43         lrn_params.localSize  = primitive->size;
44         lrn_params.divMode    = kernel_selector::kernel_divider_mode::FIXED;
45         lrn_params.normMode   = 
46             primitive->norm_region == cldnn_lrn_norm_region_within_channel ? 
47             kernel_selector::lrn_mode::WITHIN_CHANNEL :
48             kernel_selector::lrn_mode::ACROSS_CHANNEL;
49     
50
51         auto& kernel_selector = kernel_selector::lrn_kernel_selector::Instance();
52         auto best_kernels = kernel_selector.GetBestKernels(lrn_params, lrn_optional_params);
53
54         CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
55
56         auto lrn = new lrn_gpu(arg, best_kernels[0]);
57
58         return lrn;
59     }
60
61 };
62
63 namespace {
64     struct attach {
65         attach() {
66             implementation_map<lrn>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::yxfb), lrn_gpu::create);
67             implementation_map<lrn>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::yxfb), lrn_gpu::create);
68             implementation_map<lrn>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), lrn_gpu::create);
69             implementation_map<lrn>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), lrn_gpu::create);
70             implementation_map<lrn>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::byxf), lrn_gpu::create);
71             implementation_map<lrn>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::byxf), lrn_gpu::create);
72         }
73         ~attach() {}
74     };
75     attach attach_impl;
76 }
77 } }