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 "arg_max_min_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 "arg_max_min/arg_max_min_kernel_selector.h"
23 #include "arg_max_min/arg_max_min_kernel_base.h"
24 #include "kernel_runner.h"
29 struct arg_max_min_gpu : typed_primitive_gpu_impl<arg_max_min>
31 using parent = typed_primitive_gpu_impl<arg_max_min>;
36 virtual kernel::kernel_arguments_data get_arguments(typed_primitive_inst<arg_max_min>& instance, int32_t) const override
38 kernel::kernel_arguments_data args = parent::get_arguments(instance, 0);
45 static primitive_impl* create(const arg_max_min_node &arg)
47 const auto& primitive = arg.get_primitive();
49 const auto& axis = primitive->axis;
50 const auto& top_k = primitive->top_k;
51 const auto& out_type = primitive->output_type;
52 const auto& with_axis = primitive->with_axis;
54 auto argm_params = get_default_params<kernel_selector::arg_max_min_params>(arg);
55 auto argm_optional_params = get_default_optional_params<kernel_selector::arg_max_min_optional_params>(arg.get_program());
57 argm_params.topK = top_k;
61 case arg_max_min::batch:
62 argm_params.argMaxMinAxis = kernel_selector::argm_axis::BATCH;
64 case arg_max_min::feature:
65 argm_params.argMaxMinAxis = kernel_selector::argm_axis::FEATURE;
68 argm_params.argMaxMinAxis = kernel_selector::argm_axis::X;
71 argm_params.argMaxMinAxis = kernel_selector::argm_axis::Y;
78 if (out_type == primitive->max)
79 argm_params.argMaxMinOut = kernel_selector::argm_output::MAX;
81 argm_params.argMaxMinOut = kernel_selector::argm_output::MIN;
82 auto& kernel_selector = kernel_selector::arg_max_min_kernel_selector::Instance();
84 kernel_selector::KernelsData best_kernels = kernel_selector.GetBestKernels(argm_params, argm_optional_params);
86 CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
88 auto conv = new arg_max_min_gpu(arg, best_kernels[0]);
97 implementation_map<arg_max_min>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), arg_max_min_gpu::create);
98 implementation_map<arg_max_min>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), arg_max_min_gpu::create);
99 implementation_map<arg_max_min>::add(std::make_tuple(engine_types::ocl, data_types::i8, format::bfyx), arg_max_min_gpu::create);
100 implementation_map<arg_max_min>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::yxfb), arg_max_min_gpu::create);
101 implementation_map<arg_max_min>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::yxfb), arg_max_min_gpu::create);
102 implementation_map<arg_max_min>::add(std::make_tuple(engine_types::ocl, data_types::i8, format::yxfb), arg_max_min_gpu::create);