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.
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"
25 namespace cldnn { namespace gpu {
28 struct lrn_gpu : typed_primitive_gpu_impl<lrn>
30 using parent = typed_primitive_gpu_impl<lrn>;
33 static primitive_impl* create(const lrn_node& arg)
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());
38 const auto& primitive = arg.get_primitive();
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;
46 primitive->norm_region == cldnn_lrn_norm_region_within_channel ?
47 kernel_selector::lrn_mode::WITHIN_CHANNEL :
48 kernel_selector::lrn_mode::ACROSS_CHANNEL;
51 auto& kernel_selector = kernel_selector::lrn_kernel_selector::Instance();
52 auto best_kernels = kernel_selector.GetBestKernels(lrn_params, lrn_optional_params);
54 CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
56 auto lrn = new lrn_gpu(arg, best_kernels[0]);
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);