0fc69e9bd7f503b28741481b16f883c2085634f4
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / gpu / select_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 "select_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 "select/select_kernel_selector.h"
23 #include "select/select_kernel_base.h"
24
25 namespace cldnn {
26 namespace gpu {
27
28 struct select_gpu : typed_primitive_gpu_impl<select> {
29     using parent = typed_primitive_gpu_impl<select>;
30     using parent::parent;
31
32 public:
33     static primitive_impl* create(const select_node& arg) {
34         auto select_params = get_default_params<kernel_selector::select_params>(arg);
35         auto select_optional_params =
36             get_default_optional_params<kernel_selector::select_optional_params>(arg.get_program());
37
38         for (size_t i = 1; i < arg.inputs_count(); i++) {
39             select_params.inputs.push_back(convert_data_tensor(arg.input(i).get_output_layout()));
40         }
41
42         auto& kernel_selector = kernel_selector::select_kernel_selector::Instance();
43         auto best_kernels = kernel_selector.GetBestKernels(select_params, select_optional_params);
44
45         CLDNN_ERROR_BOOL(arg.id(),
46                          "Best_kernel.empty()",
47                          best_kernels.empty(),
48                          "Cannot find a proper kernel with this arguments");
49
50         auto select = new select_gpu(arg, best_kernels[0]);
51
52         return select;
53     }
54 };
55
56 namespace {
57 struct attach {
58     attach() {
59         implementation_map<select>::add(
60             {{std::make_tuple(engine_types::ocl, data_types::f32, format::yxfb), select_gpu::create},
61              {std::make_tuple(engine_types::ocl, data_types::f16, format::yxfb), select_gpu::create},
62              {std::make_tuple(engine_types::ocl, data_types::i8, format::yxfb), select_gpu::create},
63              {std::make_tuple(engine_types::ocl, data_types::u8, format::yxfb), select_gpu::create},
64
65              {std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), select_gpu::create},
66              {std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), select_gpu::create},
67              {std::make_tuple(engine_types::ocl, data_types::i8, format::bfyx), select_gpu::create},
68              {std::make_tuple(engine_types::ocl, data_types::u8, format::bfyx), select_gpu::create},
69
70              {std::make_tuple(engine_types::ocl, data_types::f32, format::byxf), select_gpu::create},
71              {std::make_tuple(engine_types::ocl, data_types::f16, format::byxf), select_gpu::create},
72              {std::make_tuple(engine_types::ocl, data_types::i8, format::byxf), select_gpu::create},
73              {std::make_tuple(engine_types::ocl, data_types::u8, format::byxf), select_gpu::create}});
74     }
75
76     ~attach() {}
77 };
78 attach attach_impl;
79 }  // namespace
80 }  // namespace gpu
81 }  // namespace cldnn