Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / gpu / max_unpooling_gpu.cpp
1 /*
2 // Copyright (c) 2018 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 "max_unpooling_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 "max_unpooling/max_unpooling_kernel_selector.h"
23 #include "max_unpooling/max_unpooling_kernel_base.h"
24
25 namespace cldnn { namespace gpu {
26
27 struct max_unpooling_gpu : typed_primitive_gpu_impl<max_unpooling>
28 {
29     using parent = typed_primitive_gpu_impl<max_unpooling>;
30     using parent::parent;
31
32 protected:
33
34     virtual kernel::kernel_arguments_data get_arguments(typed_primitive_inst<max_unpooling>& instance, int32_t split) const override
35     {
36         kernel::kernel_arguments_data args = parent::get_arguments(instance, split);
37         args.inputs.push_back(&instance.dep_memory(1));
38         return args;
39     }
40
41 public:
42
43     event_impl::ptr execute_impl(const std::vector<event_impl::ptr>& events, max_unpooling_inst& instance) override
44     {
45         //clear output buffer
46         std::vector<event_impl::ptr> tmp_events(events);
47         auto ev = instance.get_network().get_engine().create_user_event(false);
48         instance.output_memory().fill(0, ev);
49         tmp_events.push_back(ev);
50         return parent::execute_impl(tmp_events, instance);
51     }
52
53     static primitive_impl* create(const max_unpooling_node& arg)
54     {
55         auto max_unpooling_params = get_default_params<kernel_selector::max_unpooling_params>(arg);
56         auto max_unpooling_optional_params = get_default_optional_params<kernel_selector::max_unpooling_optional_params>(arg.get_program());
57
58         max_unpooling_params.inputs.push_back(convert_data_tensor(arg.argmax().get_output_layout()));
59
60         auto& kernel_selector   = kernel_selector::max_unpooling_kernel_selector::Instance();
61         auto best_kernels       = kernel_selector.GetBestKernels(max_unpooling_params, max_unpooling_optional_params);
62
63         CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
64
65         auto max_unpool = new max_unpooling_gpu(arg, best_kernels[0]);
66
67         return max_unpool;
68     }
69 };
70
71 namespace {
72     struct attach {
73         attach()
74         {
75             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::yxfb), max_unpooling_gpu::create);
76             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::yxfb), max_unpooling_gpu::create);
77             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), max_unpooling_gpu::create);
78             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), max_unpooling_gpu::create);
79             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::i8, format::bfyx), max_unpooling_gpu::create);
80             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::i8, format::yxfb), max_unpooling_gpu::create);
81             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::byxf), max_unpooling_gpu::create);
82             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::byxf), max_unpooling_gpu::create);
83             implementation_map<max_unpooling>::add(std::make_tuple(engine_types::ocl, data_types::i8, format::byxf), max_unpooling_gpu::create);
84         }
85         ~attach() {}
86     };
87     attach attach_impl;
88 }
89 } }