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