2 // Copyright (c) 2018 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.
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"
30 struct max_unpooling_gpu : typed_primitive_gpu_impl<max_unpooling> {
31 using parent = typed_primitive_gpu_impl<max_unpooling>;
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));
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);
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());
57 max_unpooling_params.inputs.push_back(convert_data_tensor(arg.argmax().get_output_layout()));
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);
62 CLDNN_ERROR_BOOL(arg.id(),
63 "Best_kernel.empty()",
65 "Cannot find a proper kernel with this arguments");
67 auto max_unpool = new max_unpooling_gpu(arg, best_kernels[0]);
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);