Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / gpu / batch_norm_grad_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 "batch_norm_grad_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 "batch_norm_grad/batch_norm_grad_kernel_base.h"
23 #include "batch_norm_grad/batch_norm_grad_kernel_selector.h"
24
25 namespace cldnn {
26     namespace gpu {
27
28         struct batch_norm_grad_gpu : typed_primitive_gpu_impl<batch_norm_grad>
29         {
30             using parent = typed_primitive_gpu_impl<batch_norm_grad>;
31             using parent::parent;
32
33         protected:
34
35             virtual kernel::kernel_arguments_data get_arguments(typed_primitive_inst<batch_norm_grad>& instance, int32_t) const override
36             {
37                 kernel::kernel_arguments_data args;
38
39                 args.inputs = { &instance.input_memory(0), &instance.input_memory(1), &instance.inv_variance_memory() };
40                 args.output = &instance.output_memory();
41
42                 return args;
43             }
44
45         public:
46
47             static primitive_impl* create(const batch_norm_grad_node &arg)
48             {
49                 auto norm_params = get_default_params<kernel_selector::batch_norm_grad_params>(arg);
50                 auto norm_optional_params = get_default_optional_params<kernel_selector::batch_norm_grad_optional_params>(arg.get_program());
51
52
53                 auto& kernel_selector = kernel_selector::batch_norm_grad_kernel_selector::Instance();
54                 auto best_kernels = kernel_selector.GetBestKernels(norm_params, norm_optional_params);
55
56                 CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
57
58                 auto norm = new batch_norm_grad_gpu(arg, best_kernels[0]);
59
60                 return norm;
61             };
62         };
63
64         namespace {
65             struct attach {
66                 attach() {
67                     auto val_fw = batch_norm_grad_gpu::create;
68
69                     implementation_map<batch_norm_grad>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::yxfb), val_fw);
70                     implementation_map<batch_norm_grad>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::yxfb), val_fw);
71                     implementation_map<batch_norm_grad>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), val_fw);
72                     implementation_map<batch_norm_grad>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), val_fw);
73                     implementation_map<batch_norm_grad>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::byxf), val_fw);
74                     implementation_map<batch_norm_grad>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::byxf), val_fw);
75                 }
76                 ~attach() {}
77             };
78             attach attach_impl;
79         }
80     }
81 }