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 "kernel_selector_helper.h"
22 #include "max_unpooling/max_unpooling_kernel_selector.h"
23 #include "max_unpooling/max_unpooling_kernel_base.h"
25 namespace cldnn { namespace gpu {
27 struct max_unpooling_gpu : typed_primitive_gpu_impl<max_unpooling>
29 using parent = typed_primitive_gpu_impl<max_unpooling>;
34 virtual kernel::kernel_arguments_data get_arguments(typed_primitive_inst<max_unpooling>& instance, int32_t split) const override
36 kernel::kernel_arguments_data args = parent::get_arguments(instance, split);
37 args.inputs.push_back(&instance.dep_memory(1));
43 event_impl::ptr execute_impl(const std::vector<event_impl::ptr>& events, max_unpooling_inst& instance) override
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);
53 static primitive_impl* create(const max_unpooling_node& arg)
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());
58 max_unpooling_params.inputs.push_back(convert_data_tensor(arg.argmax().get_output_layout()));
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);
63 CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
65 auto max_unpool = new max_unpooling_gpu(arg, best_kernels[0]);
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);