From 5e52d519eaa7fcc6d53a0500a894db048e796880 Mon Sep 17 00:00:00 2001 From: Roman Lyamin Date: Thu, 28 Jul 2022 09:15:41 +0400 Subject: [PATCH] [GPU] Align TopK parameters with ngraph (#12278) --- .../intel_gpu/primitives/arg_max_min.hpp | 38 +- .../intel_gpu/src/graph/arg_max_min.cpp | 105 +---- .../src/graph/impls/ocl/arg_max_min.cpp | 51 +-- .../graph/include/kernel_selector_helper.h | 1 - .../src/kernel_selector/common/common_types.h | 25 +- .../arg_max_min/arg_max_min_kernel_base.h | 2 +- .../arg_max_min_kernel_gpu_ref.cpp | 1 - .../arg_max_min/arg_max_min_kernel_opt.cpp | 1 - .../core/kernel_selector_common.cpp | 12 - .../core/kernel_selector_common.h | 1 - .../core/kernel_selector_params.cpp | 32 -- .../core/kernel_selector_params.h | 12 - .../ops/experimental_detectron_topk_rois.cpp | 4 +- src/plugins/intel_gpu/src/plugin/ops/topk.cpp | 48 +-- .../tests/test_cases/arg_max_gpu_test.cpp | 388 ++---------------- .../tests/test_cases/command_queue_test.cpp | 36 +- .../test_cases/set_output_memory_gpu_test.cpp | 6 +- 17 files changed, 106 insertions(+), 657 deletions(-) diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/arg_max_min.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/arg_max_min.hpp index 7ffbd8afaea..9cf0d2bf7a9 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/arg_max_min.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/arg_max_min.hpp @@ -5,6 +5,8 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// #pragma once #include "primitive.hpp" +#include "openvino/op/util/attr_types.hpp" + #include #include @@ -24,52 +26,38 @@ namespace cldnn { struct arg_max_min : public primitive_base { CLDNN_DECLARE_PRIMITIVE(arg_max_min) - /// @brief Enum type to specify axis to return values from. - enum out_type { - max, - min, - }; - - /// @brief Enum type to specify axis to maximize/minimize along. - enum axis_name { batch, feature, x, y, z, xyf }; - - /// @brief Enum type to specify sort by values or indices. - enum sort_type { sort_by_values, sort_by_indices }; - /// @brief Constructs arg_max_min primitive. /// @param id This primitive id. /// @param input Input primitive id. - /// @param out_type Type of output - max or min. + /// @param mode Type of output - max or min. /// @param top_k Number of indices to output. /// @param axis Axis to maximize/minimize along. + /// @param sort Type of sorting - by values or indices. arg_max_min(const primitive_id& id, const std::vector& input, - out_type output_type, - uint32_t top_k = 1, - axis_name axis = axis_name::xyf, - sort_type sort = sort_type::sort_by_values, + ov::op::TopKMode mode, + uint32_t top_k, + int64_t axis, + ov::op::TopKSortType sort = ov::op::TopKSortType::SORT_VALUES, bool values_first = false, const primitive_id& ext_prim_id = "", const padding& output_padding = padding(), data_types output_data_type = data_types::f32) : primitive_base(id, {input}, ext_prim_id, output_padding, optional_data_type {output_data_type}), + mode(mode), top_k(top_k), - output_type(output_type), axis(axis), sort(sort), - with_axis(axis == axis_name::xyf ? false : true), values_first(values_first) {} + /// @brief Type of output - max or min. + ov::op::TopKMode mode; /// @brief Number of indices to output. uint32_t top_k; - /// @brief Type of output - max or min. - out_type output_type; /// @brief Axis to maximize/minimize along. If not set, maximize the flattened trailing dimensions for each index of the batch dimension. - axis_name axis; + int64_t axis; /// @brief Type of sorting - by values or indices. - sort_type sort; - /// @brief Indicates that the primitive has user defined axis to maximize/minimize along; - bool with_axis; + ov::op::TopKSortType sort; /// @brief Sets output order: if True than first output contains values and second (optional) - indices. bool values_first; }; diff --git a/src/plugins/intel_gpu/src/graph/arg_max_min.cpp b/src/plugins/intel_gpu/src/graph/arg_max_min.cpp index aa936824eb4..8d269930dd8 100644 --- a/src/plugins/intel_gpu/src/graph/arg_max_min.cpp +++ b/src/plugins/intel_gpu/src/graph/arg_max_min.cpp @@ -56,110 +56,29 @@ layout arg_max_min_inst::calc_output_layout(arg_max_min_node const& node) { "Current output data type is unable to hold maximum index of a tensor."); } }; - auto format = input_layout.format; - if (desc->with_axis) { - switch (desc->axis) { - case arg_max_min::x: - size_check(input_layout.spatial(0)); - if (format == cldnn::format::bfzyx) - return layout{output_data_type, - format::bfzyx, - tensor{input_layout.batch(), - input_layout.feature(), - (int32_t)desc->top_k, - input_layout.spatial(1), - input_layout.spatial(2)}}; - else - return layout{output_data_type, - format, - tensor{input_layout.batch(), - input_layout.feature(), - (int32_t)desc->top_k, - input_layout.spatial(1)}}; - case arg_max_min::y: - size_check(input_layout.spatial(1)); - if (format == cldnn::format::bfzyx) - return layout{output_data_type, - format::bfzyx, - tensor{input_layout.batch(), - input_layout.feature(), - input_layout.spatial(0), - (int32_t)desc->top_k, - input_layout.spatial(2)}}; - else - return layout{output_data_type, - format, - tensor{input_layout.batch(), - input_layout.feature(), - input_layout.spatial(0), - (int32_t)desc->top_k}}; - case arg_max_min::feature: - size_check(input_layout.feature()); - if (format == cldnn::format::bfzyx) - return layout{output_data_type, - format::bfzyx, - tensor{input_layout.batch(), - (int32_t)desc->top_k, - input_layout.spatial(0), - input_layout.spatial(1), - input_layout.spatial(2)}}; - else - return layout{output_data_type, - format, - tensor{input_layout.batch(), - (int32_t)desc->top_k, - input_layout.spatial(0), - input_layout.spatial(1)}}; - case arg_max_min::batch: - size_check(input_layout.batch()); - if (format == cldnn::format::bfzyx) - return layout{output_data_type, - format::bfzyx, - tensor{(int32_t)desc->top_k, - input_layout.feature(), - input_layout.spatial(0), - input_layout.spatial(1), - input_layout.spatial(2)}}; - else - return layout{output_data_type, - format, - tensor{(int32_t)desc->top_k, - input_layout.feature(), - input_layout.spatial(0), - input_layout.spatial(1)}}; - case arg_max_min::z: - size_check(input_layout.spatial(2)); - return layout{output_data_type, - format::bfzyx, - tensor{input_layout.batch(), - input_layout.feature(), - input_layout.spatial(0), - input_layout.spatial(1), - (int32_t)desc->top_k}}; - default: - break; - } + for (auto dim : input_layout.get_dims()) { + size_check(dim); } - size_check(input_layout.feature() * input_layout.spatial(0) * input_layout.spatial(1)); - return layout{output_data_type, - input_layout.format, - tensor{input_layout.batch(), 1, (int32_t)desc->top_k, 1}}; + auto format = input_layout.format; + auto sizes = input_layout.get_dims(); + if (desc->axis >= static_cast(sizes.size()) || desc->axis < 0) { + IE_THROW() << "Incorrect arg_max_min axis."; + } + sizes[desc->axis] = desc->top_k; + return layout{output_data_type, format, tensor(format::get_default_format(input_layout.get_rank()), sizes)}; } std::string arg_max_min_inst::to_string(arg_max_min_node const& node) { auto desc = node.get_primitive(); auto node_info = node.desc_to_json(); - auto axis = desc->with_axis ? "true" : "false"; - auto out_type = desc->output_type ? "max" : "min"; std::stringstream primitive_description; json_composite conv_info; conv_info.add("top_k", desc->top_k); - conv_info.add("with axis", axis); - if (desc->with_axis) - conv_info.add("axis", desc->axis); - conv_info.add("output type", out_type); + conv_info.add("axis", desc->axis); + conv_info.add("output type", desc->mode); + conv_info.add("sort type", desc->sort); node_info->add("arg_max_min info", conv_info); node_info->dump(primitive_description); diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/arg_max_min.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/arg_max_min.cpp index 641affe72ed..a6b9cb2f8da 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/arg_max_min.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/arg_max_min.cpp @@ -14,6 +14,28 @@ namespace cldnn { namespace ocl { +static inline kernel_selector::argm_axis GetArgMaxMinAxis(int64_t axis, size_t rank) { + if (axis < 0) { + axis += rank; + } + switch (axis) { + case 0: return kernel_selector::argm_axis::BATCH; + case 1: return kernel_selector::argm_axis::FEATURE; + case 2: + if (rank > 4) + return kernel_selector::argm_axis::Z; + else + return kernel_selector::argm_axis::Y; + case 3: + if (rank > 4) + return kernel_selector::argm_axis::Y; + else + return kernel_selector::argm_axis::X; + case 4: return kernel_selector::argm_axis::X; + default: IE_THROW() << "Invalid arg_max_min axis " << axis; + } +} + struct arg_max_min_impl : typed_primitive_impl_ocl { using parent = typed_primitive_impl_ocl; using parent::parent; @@ -38,9 +60,8 @@ public: const auto& primitive = arg.get_primitive(); const auto& axis = primitive->axis; const auto& top_k = primitive->top_k; - const auto& out_type = primitive->output_type; + const auto& mode = primitive->mode; const auto& sort_type = primitive->sort; - const auto& with_axis = primitive->with_axis; const auto& values_first = primitive->values_first; const auto& outputs_num = primitive->input.size() == 3 ? 2 : 1; // second output passed as input for TOP_K layer @@ -50,34 +71,14 @@ public: argm_params.outputs_num = outputs_num; argm_params.topK = top_k; - if (with_axis) { - switch (axis) { - case arg_max_min::batch: - argm_params.argMaxMinAxis = kernel_selector::argm_axis::BATCH; - break; - case arg_max_min::feature: - argm_params.argMaxMinAxis = kernel_selector::argm_axis::FEATURE; - break; - case arg_max_min::x: - argm_params.argMaxMinAxis = kernel_selector::argm_axis::X; - break; - case arg_max_min::y: - argm_params.argMaxMinAxis = kernel_selector::argm_axis::Y; - break; - case arg_max_min::z: - argm_params.argMaxMinAxis = kernel_selector::argm_axis::Z; - break; - default: - break; - } - } + argm_params.argMaxMinAxis = GetArgMaxMinAxis(axis, arg.get_output_layout().get_rank()); - if (out_type == primitive->max) + if (mode == ov::op::TopKMode::MAX) argm_params.argMaxMinOut = kernel_selector::argm_output::MAX; else argm_params.argMaxMinOut = kernel_selector::argm_output::MIN; - if (sort_type == primitive->sort_by_values) + if (sort_type == ov::op::TopKSortType::SORT_VALUES) argm_params.argMaxMinSortType = kernel_selector::argm_sort::VALUE; else argm_params.argMaxMinSortType = kernel_selector::argm_sort::INDEX; diff --git a/src/plugins/intel_gpu/src/graph/include/kernel_selector_helper.h b/src/plugins/intel_gpu/src/graph/include/kernel_selector_helper.h index 65e5c6cc5a7..15cc5853ff3 100644 --- a/src/plugins/intel_gpu/src/graph/include/kernel_selector_helper.h +++ b/src/plugins/intel_gpu/src/graph/include/kernel_selector_helper.h @@ -54,7 +54,6 @@ using pool_remainder = kernel_selector::PoolRemainder; using argm_axis = kernel_selector::ArgMaxMinAxis; using argm_output = kernel_selector::ArgMaxMinOut; using argm_sort = kernel_selector::ArgMaxMinSortType; -using lookt_axis = kernel_selector::LookUpTableAxis; using lrn_mode = kernel_selector::LRNMode; using normalize_mode = kernel_selector::NormalizeMode; using mvn_mode = kernel_selector::MVNMode; diff --git a/src/plugins/intel_gpu/src/kernel_selector/common/common_types.h b/src/plugins/intel_gpu/src/kernel_selector/common/common_types.h index 3063788e08e..221933f67ee 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/common/common_types.h +++ b/src/plugins/intel_gpu/src/kernel_selector/common/common_types.h @@ -198,28 +198,6 @@ enum class LRNMode { WITHIN_CHANNEL }; -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LookUpTableAxis -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -enum class LookUpTableAxis { - BATCH, - FEATURE, - X, - Y, - XYF -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// EmbedAxis -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -enum class EmbedAxis { - BATCH, - FEATURE, - X, - Y, - XYF -}; - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ArgMaxMinDim //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -228,8 +206,7 @@ enum class ArgMaxMinAxis { FEATURE, X, Y, - Z, - XYF + Z }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_base.h b/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_base.h index 828b511f273..dd7d8159bab 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_base.h +++ b/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_base.h @@ -14,7 +14,7 @@ namespace kernel_selector { struct arg_max_min_params : public base_params { arg_max_min_params() : base_params(KernelType::ARG_MAX_MIN) {} - ArgMaxMinAxis argMaxMinAxis = ArgMaxMinAxis::XYF; + ArgMaxMinAxis argMaxMinAxis; ArgMaxMinOut argMaxMinOut = ArgMaxMinOut::MAX; ArgMaxMinSortType argMaxMinSortType = ArgMaxMinSortType::VALUE; uint32_t topK = 1; diff --git a/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_gpu_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_gpu_ref.cpp index 74228c0171e..65e777fbb6b 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_gpu_ref.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_gpu_ref.cpp @@ -15,7 +15,6 @@ ParamsKey ArgMaxMinKernelGPURef::GetSupportedKey() const { k.EnableInputLayout(DataLayout::yxfb); k.EnableOutputLayout(DataLayout::bfyx); k.EnableOutputLayout(DataLayout::yxfb); - k.EnableArgMaxMinAxis(ArgMaxMinAxis::XYF); k.EnableDifferentTypes(); k.EnableBatching(); return k; diff --git a/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_opt.cpp index 9cffc8f66db..d1105016b10 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_opt.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/core/actual_kernels/arg_max_min/arg_max_min_kernel_opt.cpp @@ -13,7 +13,6 @@ ParamsKey ArgMaxMinKernelOpt::GetSupportedKey() const { k.EnableOutputDataType(Datatype::F32); k.EnableInputLayout(DataLayout::bfyx); k.EnableOutputLayout(DataLayout::bfyx); - k.EnableArgMaxMinAxis(ArgMaxMinAxis::XYF); k.EnableDifferentTypes(); return k; } diff --git a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.cpp b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.cpp index 11b377a667c..0ac9e7e24a7 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.cpp @@ -227,18 +227,6 @@ std::string toString(ArgMaxMinAxis mode) { case ArgMaxMinAxis::X: return "X"; case ArgMaxMinAxis::Y: return "Y"; case ArgMaxMinAxis::Z: return "Z"; - case ArgMaxMinAxis::XYF: return "XYF"; - default: return ""; - } -} - -std::string toString(LookUpTableAxis mode) { - switch (mode) { - case LookUpTableAxis::BATCH: return "BATCH"; - case LookUpTableAxis::FEATURE: return "FEATURE"; - case LookUpTableAxis::X: return "X"; - case LookUpTableAxis::Y: return "Y"; - case LookUpTableAxis::XYF: return "XYF"; default: return ""; } } diff --git a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.h b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.h index c4d777626ae..6ce00e28861 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.h +++ b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_common.h @@ -137,7 +137,6 @@ std::string toString(ReorderMode mode); std::string toString(MeanSubtractMode mode); std::string toString(ArgMaxMinOut mode); std::string toString(ArgMaxMinAxis mode); -std::string toString(LookUpTableAxis mode); std::string toString(PoolType mode); std::string toString(LRNMode mode); std::string toString(KernelDividerMode mode); diff --git a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.cpp b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.cpp index 5d3c108279a..f4c59f6ed29 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.cpp @@ -148,28 +148,6 @@ void ParamsKey::EnableLRNMode(LRNMode m) { } } -void ParamsKey::EnableLookUpTableAxis(LookUpTableAxis m) { - switch (m) { - case kernel_selector::LookUpTableAxis::BATCH: - key.restrict.val.dedicated.lookt.axisBatch = 1; - break; - case kernel_selector::LookUpTableAxis::FEATURE: - key.restrict.val.dedicated.lookt.axisFeature = 1; - break; - case kernel_selector::LookUpTableAxis::X: - key.restrict.val.dedicated.lookt.axisX = 1; - break; - case kernel_selector::LookUpTableAxis::Y: - key.restrict.val.dedicated.lookt.axisY = 1; - break; - case kernel_selector::LookUpTableAxis::XYF: - key.restrict.val.dedicated.lookt.axisXYF = 1; - break; - default: - break; - } -} - void ParamsKey::EnableNormalizeMode(NormalizeMode m) { switch (m) { case NormalizeMode::ACROSS_SPATIAL: @@ -350,9 +328,6 @@ void ParamsKey::EnableArgMaxMinAxis(ArgMaxMinAxis a) { case ArgMaxMinAxis::BATCH: key.restrict.val.dedicated.argm.axisBatch = 1; break; - case ArgMaxMinAxis::XYF: - key.restrict.val.dedicated.argm.axisXYF = 1; - break; default: break; } @@ -377,13 +352,6 @@ void ParamsKey::EnableIndexSelectAxis(IndexSelectAxis a) { } } -void ParamsKey::EnableLookUpTableIndicesFormat(Datatype a) { - if (a == Datatype::F32) - key.restrict.val.dedicated.lookt.indicesF32 = 1; - else - key.restrict.val.dedicated.lookt.indicesOther = 1; -} - void ParamsKey::EnableQuantization(QuantizationType q) { switch (q) { case QuantizationType::NONE: diff --git a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.h b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.h index ade3458f65e..f5ac2de9570 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.h +++ b/src/plugins/intel_gpu/src/kernel_selector/core/kernel_selector_params.h @@ -78,22 +78,12 @@ public: uint32_t asym_d_quantization : 1; union dedicated_t { - struct lookt_t { - uint32_t axisX : 1; - uint32_t axisY : 1; - uint32_t axisFeature : 1; - uint32_t axisBatch : 1; - uint32_t axisXYF : 1; - uint32_t indicesF32 : 1; - uint32_t indicesOther : 1; - } lookt; struct argm_t { uint32_t axisX : 1; uint32_t axisY : 1; uint32_t axisZ : 1; uint32_t axisFeature : 1; uint32_t axisBatch : 1; - uint32_t axisXYF : 1; } argm; struct idxsel_t { uint32_t axisX : 1; @@ -277,7 +267,6 @@ public: void EnableActivationAdditionalParamsAsInput() { key.restrict.val.activationAdditionalParamsAsInput = 1; } void EnableMomentum() { key.restrict.val.momentum = 1; } void EnableLRNMode(LRNMode m); - void EnableLookUpTableAxis(LookUpTableAxis m); void EnableNormalizeMode(NormalizeMode m); void EnableMVNMode(MVNMode m); void EnableMVNNormalizeVariance(); @@ -317,7 +306,6 @@ public: void DisableTuning() { key.enableTuning = 0; } void EnableConcatOneKernel() { key.restrict.val.dedicated.concat.oneKernel = 1; } void EnableArgMaxMinAxis(ArgMaxMinAxis a); - void EnableLookUpTableIndicesFormat(Datatype a); void EnableIndexSelectAxis(IndexSelectAxis a); void EnableFusedConvEltwiseRWOutOpt(); bool Support(const ParamsKey& k) const; diff --git a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_topk_rois.cpp b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_topk_rois.cpp index d20b868aa8b..b5fe854a276 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_topk_rois.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_topk_rois.cpp @@ -25,8 +25,8 @@ void CreateExperimentalDetectronTopKROIsOp(Program &p, auto layer_name = layer_type_name_ID(op); auto argmax_layer_name = layer_name + "_topk"; auto top_k_indices = arg_max_min(argmax_layer_name, - {input_primitives[1]}, arg_max_min::max, max_rois, arg_max_min::batch, - arg_max_min::sort_by_values, false, "", cldnn::padding(), cldnn::data_types::i32); + {input_primitives[1]}, ov::op::TopKMode::MAX, max_rois, 0, + ov::op::TopKSortType::SORT_VALUES, false, "", cldnn::padding(), cldnn::data_types::i32); p.AddPrimitive(top_k_indices); diff --git a/src/plugins/intel_gpu/src/plugin/ops/topk.cpp b/src/plugins/intel_gpu/src/plugin/ops/topk.cpp index 4be07c20450..000bc0cae58 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/topk.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/topk.cpp @@ -14,54 +14,16 @@ namespace ov { namespace intel_gpu { -static cldnn::arg_max_min::axis_name GetAxis(int32_t axis, size_t in_rank) { - if (in_rank == 5) { - if (-5 <= axis && axis <= -1) - axis += 5; - - switch (axis) { - case 0: return cldnn::arg_max_min::axis_name::batch; - case 1: return cldnn::arg_max_min::axis_name::feature; - case 2: return cldnn::arg_max_min::axis_name::z; - case 3: return cldnn::arg_max_min::axis_name::y; - case 4: return cldnn::arg_max_min::axis_name::x; - } - } else { - if (-static_cast(in_rank) <= axis && axis <= -1) - axis += in_rank; - - switch (axis) { - case 0: return cldnn::arg_max_min::axis_name::batch; - case 1: return cldnn::arg_max_min::axis_name::feature; - case 2: return cldnn::arg_max_min::axis_name::y; - case 3: return cldnn::arg_max_min::axis_name::x; - } - } - - return cldnn::arg_max_min::axis_name::batch; -} - static void CreateTopKOp(Program& p, const std::shared_ptr& op) { p.ValidateInputs(op, {2}); auto inputPrimitives = p.GetInputPrimitiveIDs(op); std::string layerName = layer_type_name_ID(op); - cldnn::arg_max_min::out_type otype; - cldnn::arg_max_min::sort_type stype; - - if (op->get_mode() == ngraph::op::v1::TopK::Mode::MAX) - otype = cldnn::arg_max_min::out_type::max; - else - otype = cldnn::arg_max_min::out_type::min; - - if (op->get_sort_type() == ngraph::op::v1::TopK::SortType::SORT_VALUES) - stype = cldnn::arg_max_min::sort_type::sort_by_values; - else - stype = cldnn::arg_max_min::sort_type::sort_by_indices; + ov::op::TopKMode mode = op->get_mode(); + ov::op::TopKSortType stype = op->get_sort_type(); uint32_t top_k = op->get_k(); - cldnn::arg_max_min::axis_name chosen_axis = GetAxis(static_cast(op->get_axis()), - op->get_input_shape(0).size()); + uint64_t chosen_axis = op->get_axis(); if (op->get_output_size() == 2) { auto mutable_precision = op->get_output_element_type(1); @@ -90,7 +52,7 @@ static void CreateTopKOp(Program& p, const std::shared_ptr std::string ArgMaxLayerName = layerName + ".0"; auto argmaxPrim = cldnn::arg_max_min(ArgMaxLayerName, inputPrimitives, - otype, + mode, top_k, chosen_axis, stype, @@ -113,7 +75,7 @@ static void CreateTopKOp(Program& p, const std::shared_ptr } else if (op->get_output_size() == 1) { auto argmaxPrim = cldnn::arg_max_min(layerName, inputPrimitives, - otype, + mode, top_k, chosen_axis, stype, diff --git a/src/plugins/intel_gpu/tests/test_cases/arg_max_gpu_test.cpp b/src/plugins/intel_gpu/tests/test_cases/arg_max_gpu_test.cpp index 45d96bbe8f5..2c4410cf6ec 100644 --- a/src/plugins/intel_gpu/tests/test_cases/arg_max_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/test_cases/arg_max_gpu_test.cpp @@ -13,301 +13,15 @@ using namespace cldnn; using namespace ::tests; -template -void generic_arg_max_test_xyf(int input_b, int input_f, int input_y, int input_x, arg_max_min::out_type mode, bool expect_throw = false) { - auto axis = arg_max_min::axis_name::xyf; - auto sort_type = arg_max_min::sort_type::sort_by_values; - auto test_input_fmt = format::bfyx; - auto& engine = get_test_engine(); - - tensor input_tensor(input_b, input_f, input_x, input_y); - auto input = engine.allocate_memory({ type_to_data_type::value, test_input_fmt, input_tensor }); - topology topology; - topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, mode, 1U, axis, sort_type, false, "", padding(), type_to_data_type::value)); - - int min_random = -2, max_random = 2; - VVVVF input_rnd = generate_random_4d(input_b, input_f, input_y, input_x, min_random, max_random); - VF input_rnd_vec = flatten_4d(test_input_fmt, input_rnd); - - set_values(input, input_rnd_vec); - - if (expect_throw) { - std::string msg_to_find = "Current output data type is unable to hold maximum index of a tensor."; - EXPECT_ANY_THROW(check_exception_massage(engine, topology, msg_to_find)); - return; - } - network network(engine, topology); - network.set_input_data("input", input); - auto outputs = network.execute(); - - EXPECT_EQ(outputs.size(), size_t(1)); - EXPECT_EQ(outputs.begin()->first, "arg_max"); - - int out_size = input_x * input_y * input_f; - - auto output = outputs.at("arg_max").get_memory(); - cldnn::mem_lock output_ptr(output, get_test_stream()); - - Tout index; - Tin value; - for (auto i = 0; i < input_b; i++) { - index = get_value(output_ptr.data(), i); - EXPECT_GE(index, (Tout)0); - EXPECT_LT(index, (Tout)out_size); - value = input_rnd_vec[i*out_size + (int)index]; - for (auto j = 0; j < out_size; j++) { - if (mode == arg_max_min::out_type::max) { - EXPECT_LE(input_rnd_vec[i*out_size + j], value); - } - else { - EXPECT_GE(input_rnd_vec[i*out_size + j], value); - } - } - } -} - -TEST(arg_max_gpu_batch_one, base) { - // Input : 2x3x2x2 - static const int32_t x_size = 2, y_size = 2, feature_num = 5, batch_num = 1, top_k = 8; - auto& engine = get_test_engine(); - - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); - topology topology; - topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max, top_k)); - - std::vector input_vec = { - //y0x0 y0x1 y1x0 y1x1 - /*b0f0*/0.1f, -0.1f, 0.9f, 1.5f, - /*b0f1*/0.2f, 0.2f, -10.f, 5.2f, - /*b0f2*/0.2f, 0.2f, -10.f, 5.2f, - /*b0f3*/0.2f, 0.2f, -10.f, 4.2f, - /*b0f3*/0.1f, 0.3f, -11.f, 15.0f - }; - set_values(input, input_vec); - - network network(engine, topology); - - network.set_input_data("input", input); - auto outputs = network.execute(); - - EXPECT_EQ(outputs.size(), size_t(1)); - EXPECT_EQ(outputs.begin()->first, "arg_max"); - - auto output = outputs.at("arg_max").get_memory(); - cldnn::mem_lock output_ptr(output, get_test_stream()); - float out_buffer[batch_num * top_k]; - for (uint32_t i = 0; i < batch_num * top_k; i++) { - out_buffer[i] = get_value(output_ptr.data(), i); - } - int size = x_size * y_size * feature_num; - int index; - float value; - for (int i = 0; i < batch_num; i++) { - int count = 0; - int amount = 0; - int same_values = 1; - int j; - for (j = 0; j < top_k; j++) { - EXPECT_GE((int)out_buffer[i*top_k + j], 0); - EXPECT_LT((int)out_buffer[i*top_k + j], size); - if (top_k - 1 == j) { - if (input_vec[i*size + (int)out_buffer[i*top_k + j]] != input_vec[i*size + (int)out_buffer[i*top_k + j - 1]]) { - amount += j; - } - else - amount += same_values * (j - same_values + 1); - } else if (input_vec[i*size + (int)out_buffer[i*top_k + j]] != input_vec[i*size + (int)out_buffer[i*top_k + j + 1]]) { - if (same_values != j + 1) { - amount += same_values * (j - same_values + 1); - same_values = 1; - } - } - else - same_values++; - } - EXPECT_GE(out_buffer[i*top_k + top_k - 1], 0); - EXPECT_LT(out_buffer[i*top_k + top_k - 1], size); - for (int j = 0; j < top_k; j++) { - index = (int)out_buffer[i*top_k + j]; - value = input_vec[i*size + index]; - for (int k = 0; k < size; k++) { - if (input_vec[i*size + k] > value) - count++; - } - } - EXPECT_EQ(count, amount); - } -} - -TEST(arg_max_gpu_top_k, base) { - // Input : 2x3x2x2 - static const int32_t x_size = 2, y_size = 2, feature_num = 5, batch_num = 2; - auto& engine = get_test_engine(); - const int top_k = 8; - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); - topology topology; - topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max, top_k)); - - std::vector input_vec = { - //y0x0 y0x1 y1x0 y1x1 - /*b0f0*/0.1f, -0.1f, 0.9f, 1.5f, - /*b0f1*/0.2f, 0.2f, -10.f, 5.2f, - /*b0f2*/0.2f, 0.2f, -10.f, 5.2f, - /*b0f3*/0.2f, 0.2f, -10.f, 4.2f, - /*b0f3*/0.1f, 0.3f, -11.f, 15.0f, - - /*b1f0*/3.f, 0.5f, 7.f, 10.f, - /*b1f1*/4.f, 0.5f, 8.f, 8.2f, - /*b1f2*/0.2f, 0.2f, -10.f, 5.2f, - /*b1f3*/4.f, 0.5f, 8.f, 8.2f, - /*b0f3*/0.1f, 0.3f, -11.f, 15.0f, - }; - set_values(input, input_vec); - - network network(engine, topology); - - network.set_input_data("input", input); - auto outputs = network.execute(); - - EXPECT_EQ(outputs.size(), size_t(1)); - EXPECT_EQ(outputs.begin()->first, "arg_max"); - - auto output = outputs.at("arg_max").get_memory(); - cldnn::mem_lock output_ptr(output, get_test_stream()); - float out_buffer[batch_num * top_k]; - for (uint32_t i = 0; i < batch_num * top_k; i++) { - out_buffer[i] = get_value(output_ptr.data(), i); - } - int size = x_size * y_size * feature_num; - int index; - float value; - for (int i = 0; i < batch_num; i++) { - int count = 0; - int amount = 0; - int same_values = 1; - int j; - for (j = 0; j < top_k; j++) { - EXPECT_GE((int)out_buffer[i*top_k + j], 0); - EXPECT_LT((int)out_buffer[i*top_k + j], size); - if (top_k - 1 == j) { - if (input_vec[i*size + (int)(int)out_buffer[i*top_k + j]] != input_vec[i*size + (int)(int)out_buffer[i*top_k + j - 1]]) { - amount += j; - } - else - amount += same_values * (j - same_values + 1); - } else if (input_vec[i*size + (int)(int)out_buffer[i*top_k + j]] != input_vec[i*size + (int)(int)out_buffer[i*top_k + j + 1]]) { - if (same_values != j+1) { - amount += same_values * (j - same_values + 1); - same_values = 1; - } - } else { - same_values++; - } - } - EXPECT_GE(out_buffer[i*top_k + top_k - 1], 0); - EXPECT_LT(out_buffer[i*top_k + top_k - 1], size); - for (int j = 0; j < top_k; j++) { - index = (int)out_buffer[i*top_k + j]; - value = input_vec[i*size + index]; - for (int k = 0; k < size; k++) { - if (input_vec[i*size + k] > value) - count++; - } - } - EXPECT_EQ(count, amount); - } -} - -TEST(arg_max_gpu_min_top_k, base) { - // Input : 2x3x2x2 - static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; - auto& engine = get_test_engine(); - const int top_k = 3; - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); - topology topology; - topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::min, top_k)); - - std::vector input_vec = { - //f0b0 f0b1 f1b0 f1b1 - /*x0y0*/0.1f, -0.1f, 0.9f, 1.5f, - /*x0y1*/0.2f, 0.2f, -10.f, 5.2f, - /*x0y2*/0.2f, 0.2f, -10.f, 5.2f, - /*x0f3*/0.2f, 0.2f, -10.f, 4.2f, - - /*x1y0*/3.f, 0.5f, 7.f, 10.f, - /*x1y1*/4.f, 0.5f, 8.f, 8.2f, - /*x1y2*/0.2f, 0.2f, -10.f, 5.2f, - /*x1y3*/4.f, 0.5f, 8.f, 8.2f - }; - set_values(input, input_vec); - - network network(engine, topology); - - network.set_input_data("input", input); - auto outputs = network.execute(); - - EXPECT_EQ(outputs.size(), size_t(1)); - EXPECT_EQ(outputs.begin()->first, "arg_max"); - - auto output = outputs.at("arg_max").get_memory(); - cldnn::mem_lock output_ptr(output, get_test_stream()); - float out_buffer[batch_num * top_k]; - for (uint32_t i = 0; i < batch_num * top_k; i++) { - out_buffer[i] = get_value(output_ptr.data(), i); - } - int size = x_size * y_size * feature_num; - int index; - float value; - for (int i = 0; i < batch_num; i++) { - int count = 0; - int amount = 0; - int same_values = 1; - int j; - for (j = 0; j < top_k; j++) { - EXPECT_GE((int)out_buffer[i*top_k + j], 0); - EXPECT_LT((int)out_buffer[i*top_k + j], size); - if (top_k - 1 == j) { - if (input_vec[i*size + (int)out_buffer[i*top_k + j]] != input_vec[i*size + (int)out_buffer[i*top_k + j - 1]]) { - amount += j; - } - else - amount += same_values * (j - same_values + 1); - } else if (input_vec[i*size + (int)out_buffer[i*top_k + j]] != input_vec[i*size + (int)out_buffer[i*top_k + j + 1]]) { - if (same_values != j + 1) { - amount += same_values * (j - same_values + 1); - same_values = 1; - } - } else { - same_values++; - } - } - EXPECT_GE(out_buffer[i*top_k + top_k - 1], 0); - EXPECT_LT(out_buffer[i*top_k + top_k - 1], size); - for (int j = 0; j < top_k; j++) { - index = (int)out_buffer[i*top_k + j]; - value = input_vec[i*size + index]; - for (int k = 0; k < size; k++) { - if (input_vec[i*size + k] < value) - count++; - } - } - EXPECT_EQ(count, amount); - } -} - TEST(arg_max_gpu_min_axis_batch, base) { - // Input : 2x3x2x2 + // Input : 2x4x2x2 static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 2; - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::min, top_k, arg_max_min::batch)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MIN, top_k, 0)); std::vector input_vec = { //y0x0 y0x1 y1x0 y1x1 @@ -342,59 +56,15 @@ TEST(arg_max_gpu_min_axis_batch, base) { } } -TEST(arg_max_gpu, f32) { - generic_arg_max_test_xyf(50, 25, 25, 25, arg_max_min::out_type::max); -} - -TEST(arg_max_gpu_min, f32) { - generic_arg_max_test_xyf(50, 25, 25, 25, arg_max_min::out_type::min); -} - -TEST(arg_max_gpu, u8) { - generic_arg_max_test_xyf(4, 2, 2, 2, arg_max_min::out_type::max); -} - -TEST(arg_max_gpu_min, u8) { - generic_arg_max_test_xyf(4, 2, 2, 2, arg_max_min::out_type::min); -} - -TEST(arg_max_gpu, i8) { - generic_arg_max_test_xyf(4, 2, 2, 2, arg_max_min::out_type::max); -} - -TEST(arg_max_gpu_bad_sizes, i8) { - generic_arg_max_test_xyf(50, 25, 25, 25, arg_max_min::out_type::max, true); -} - -TEST(arg_max_gpu_min, i8) { - generic_arg_max_test_xyf(4, 2, 2, 2, arg_max_min::out_type::min); -} - -TEST(arg_max_gpu, i32) { - generic_arg_max_test_xyf(50, 25, 25, 25, arg_max_min::out_type::max); -} - -TEST(arg_max_gpu_min, i32) { - generic_arg_max_test_xyf(50, 25, 25, 25, arg_max_min::out_type::min); -} - -TEST(arg_max_gpu, i64) { - generic_arg_max_test_xyf(50, 25, 25, 25, arg_max_min::out_type::max); -} - -TEST(arg_max_gpu_min, i64) { - generic_arg_max_test_xyf(50, 25, 25, 25, arg_max_min::out_type::min); -} - TEST(arg_max_gpu_min_axis_batch, i32) { // Input : 2x3x2x2 static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 2; - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::min, top_k, arg_max_min::batch, arg_max_min::sort_by_values, false, "", padding(), data_types::i32)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MIN, top_k, 0, ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::i32)); std::vector input_vec = { //y0x0 y0x1 y1x0 y1x1 @@ -434,10 +104,10 @@ TEST(arg_max_gpu_min_axis_batch_bfzyx, i32) { static const int32_t x_size = 2, y_size = 2, z_size = 1, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 2; - auto input = engine.allocate_memory({ data_types::f32, format::bfzyx,{ batch_num, feature_num, x_size , y_size, z_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::bfzyx,{ batch_num, feature_num, x_size, y_size, z_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::min, top_k, arg_max_min::batch, arg_max_min::sort_by_values, false, "", padding(), data_types::i32)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MIN, top_k, 0, ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::i32)); std::vector input_vec = { //y0x0 y0x1 y1x0 y1x1 @@ -476,10 +146,10 @@ TEST(arg_max_gpu_min_axis_y_yxfb, f32) { static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 1; - auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max, top_k, arg_max_min::y, arg_max_min::sort_by_values, false, "", padding(), data_types::f32)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MAX, top_k, 2, ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::f32)); std::vector input_vec = { 0.1f, -0.1f, @@ -540,10 +210,10 @@ TEST(arg_max_gpu_min_axis_batch_yxfb, f32) { static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 1; - auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max, top_k, arg_max_min::batch, arg_max_min::sort_by_values, false, "", padding(), data_types::f32)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MAX, top_k, 0, ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::f32)); std::vector input_vec = { 0.1f, -0.1f, @@ -604,10 +274,10 @@ TEST(arg_max_gpu_min_axis_y_yxfb_topk_2, f32) { static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 2; - auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max, top_k, arg_max_min::y, arg_max_min::sort_by_values, false, "", padding(), data_types::f32)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MAX, top_k, 2, ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::f32)); std::vector input_vec = { 0.1f, -0.1f, @@ -678,14 +348,14 @@ TEST(top_k_layer_tests, second_output) { static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 2; - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); - auto top_k_input = engine.allocate_memory({ data_types::f32, format::bfyx,{ 1, 1, 1 , 1 } }); - auto second_output = engine.allocate_memory({ data_types::f32, format::bfyx, { top_k, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size, y_size } }); + auto top_k_input = engine.allocate_memory({ data_types::f32, format::bfyx,{ 1, 1, 1, 1 } }); + auto second_output = engine.allocate_memory({ data_types::f32, format::bfyx, { top_k, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); topology.add(cldnn::data("const", top_k_input)); topology.add(mutable_data("second_output", second_output)); - topology.add(arg_max_min("arg_max", { "input", "const", "second_output" }, arg_max_min::min, top_k, arg_max_min::batch)); + topology.add(arg_max_min("arg_max", { "input", "const", "second_output" }, ov::op::TopKMode::MIN, top_k, 0)); std::vector input_vec = { //y0x0 y0x1 y1x0 y1x1 @@ -729,14 +399,14 @@ TEST(top_k_layer_tests, second_output2) { static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 1; - auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size , y_size } }); - auto top_k_input = engine.allocate_memory({ data_types::f32, format::bfyx,{ 1, 1, 1 , 1 } }); - auto second_output = engine.allocate_memory({ data_types::f32, format::yxfb, { top_k, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size, y_size } }); + auto top_k_input = engine.allocate_memory({ data_types::f32, format::bfyx,{ 1, 1, 1, 1 } }); + auto second_output = engine.allocate_memory({ data_types::f32, format::yxfb, { top_k, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); topology.add(cldnn::data("const", top_k_input)); topology.add(mutable_data("second_output", second_output)); - topology.add(arg_max_min("arg_max", { "input", "const", "second_output" }, arg_max_min::max, top_k, arg_max_min::batch, arg_max_min::sort_by_values, false, "", padding(), data_types::f32)); + topology.add(arg_max_min("arg_max", { "input", "const", "second_output" }, ov::op::TopKMode::MAX, top_k, 0, ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::f32)); std::vector input_vec = { 0.1f, -0.1f, @@ -823,10 +493,10 @@ TEST(arg_max_gpu_min_axis_y_yxfb_topk_2, sort_by_values) { static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 2; - auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max, top_k, arg_max_min::y, arg_max_min::sort_by_values, false, "", padding(), data_types::f32)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MAX, top_k, 2, ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::f32)); std::vector input_vec = { 0.1f, -0.1f, @@ -897,10 +567,10 @@ TEST(arg_max_gpu_min_axis_y_yxfb_topk_2, sort_by_indices) { static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; auto& engine = get_test_engine(); const int top_k = 2; - auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::yxfb,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max, top_k, arg_max_min::y, arg_max_min::sort_by_indices, false, "", padding(), data_types::f32)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MAX, top_k, 2, ov::op::TopKSortType::SORT_INDICES, false, "", padding(), data_types::f32)); std::vector input_vec = { 0.1f, -0.1f, @@ -972,11 +642,11 @@ TEST(top_k_layer_tests, sort_probabilities_by_indices) { static const int32_t x_size = 10, y_size = 1, feature_num = 1, batch_num = 1; auto& engine = get_test_engine(); const int top_k = 5; - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); + auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input"}, arg_max_min::max, top_k, arg_max_min::x, - arg_max_min::sort_by_values, false, "", padding(), data_types::i32)); + topology.add(arg_max_min("arg_max", { "input"}, ov::op::TopKMode::MAX, top_k, 3, + ov::op::TopKSortType::SORT_VALUES, false, "", padding(), data_types::i32)); std::vector input_vec = { 0.9f, @@ -2040,7 +1710,7 @@ TEST(top_k_layer_tests, md_sync) { topology.add(mutable_data("arg_max_md_write", shared_memory)); topology.add(data("const", top_k_input)); topology.add(arg_max_min("arg_max.0", { "input1", "const", "arg_max_md_write" }, - arg_max_min::max, top_k, arg_max_min::feature, arg_max_min::sort_by_indices, true)); + ov::op::TopKMode::MAX, top_k, 1, ov::op::TopKSortType::SORT_INDICES, true)); topology.add(mutable_data("arg_max.1", { "arg_max.0" }, shared_memory)); network network(engine, topology); diff --git a/src/plugins/intel_gpu/tests/test_cases/command_queue_test.cpp b/src/plugins/intel_gpu/tests/test_cases/command_queue_test.cpp index b5f4664168f..210f913b7b7 100644 --- a/src/plugins/intel_gpu/tests/test_cases/command_queue_test.cpp +++ b/src/plugins/intel_gpu/tests/test_cases/command_queue_test.cpp @@ -15,52 +15,44 @@ using namespace std; // Run some topology too see if command queue does work correctly // Coppied from arg_max_gpu.base test. void exexute_network(cldnn::engine& engine) { - // Input : 2x3x2x2 - static const int32_t x_size = 2, y_size = 2, feature_num = 3, batch_num = 2; - - auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } }); + // Input : 2x4x2x2 + static const int32_t x_size = 2, y_size = 2, feature_num = 4, batch_num = 2; + const int top_k = 2; + auto input = engine.allocate_memory({ data_types::f32, format::bfyx,{ batch_num, feature_num, x_size, y_size } }); topology topology; topology.add(input_layout("input", input->get_layout())); - topology.add(arg_max_min("arg_max", { "input" }, arg_max_min::max)); + topology.add(arg_max_min("arg_max", { "input" }, ov::op::TopKMode::MIN, top_k, 0)); - vector input_vec = { + std::vector input_vec = { //y0x0 y0x1 y1x0 y1x1 /*b0f0*/0.1f, -0.1f, 0.9f, 1.5f, /*b0f1*/0.2f, 0.2f, -10.f, 5.2f, /*b0f2*/0.2f, 0.2f, -10.f, 5.2f, + /*b0f3*/0.2f, 0.2f, -10.f, 4.2f, /*b1f0*/3.f, 0.5f, 7.f, 10.f, /*b1f1*/4.f, 0.5f, 8.f, 8.2f, - /*b1f2*/0.2f, 0.2f, -10.f, 5.2f + /*b1f2*/0.2f, 0.2f, -10.f, 5.2f, + /*b1f3*/4.f, 0.5f, 8.f, 8.2f }; set_values(input, input_vec); network network(engine, topology); network.set_input_data("input", input); - auto outputs = network.execute(); EXPECT_EQ(outputs.size(), size_t(1)); EXPECT_EQ(outputs.begin()->first, "arg_max"); - + const int out_size = y_size * feature_num * x_size * top_k; auto output = outputs.at("arg_max").get_memory(); cldnn::mem_lock output_ptr(output, get_test_stream()); - float out_buffer[batch_num]; - for (uint32_t i = 0; i < batch_num; i++) { + float out_buffer[out_size]; + for (uint32_t i = 0; i < out_size; i++) { out_buffer[i] = get_value(output_ptr.data(), i); } - int size = x_size * y_size * feature_num; - int index; - float value; - for (int i = 0; i < batch_num; i++) { - EXPECT_GE(out_buffer[i], 0); - EXPECT_LT(out_buffer[i], size); - index = (int)out_buffer[i]; - value = input_vec[i*size + (int)index]; - for (int j = 0; j < size; j++) { - EXPECT_LE(input_vec[i*size + j], value); - } + for (int i = 0; i < out_size; i++) { + EXPECT_EQ(out_buffer[i], i < (out_size / 2) ? 0 : 1); } } diff --git a/src/plugins/intel_gpu/tests/test_cases/set_output_memory_gpu_test.cpp b/src/plugins/intel_gpu/tests/test_cases/set_output_memory_gpu_test.cpp index 555bbd069bc..db855a2ca2c 100644 --- a/src/plugins/intel_gpu/tests/test_cases/set_output_memory_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/test_cases/set_output_memory_gpu_test.cpp @@ -176,7 +176,7 @@ TEST(set_output_memory_gpu, top_k1) { topology topology; topology.add(input_layout("input", input->get_layout())); topology.add(cldnn::data("const", top_k_input)); - topology.add(arg_max_min("arg_max", { "input", "const" }, arg_max_min::min, top_k, arg_max_min::batch)); + topology.add(arg_max_min("arg_max", { "input", "const" }, ov::op::TopKMode::MIN, top_k, 0)); topology.add(reorder("reorder", "arg_max", output_mem->get_layout())); std::vector input_vec = { @@ -222,7 +222,7 @@ TEST(set_output_memory_gpu, top_k2) { topology.add(input_layout("input", input->get_layout())); topology.add(cldnn::data("const", top_k_input)); topology.add(mutable_data("second_output", second_output)); - topology.add(arg_max_min("arg_max", { "input", "const", "second_output" }, arg_max_min::min, top_k, arg_max_min::batch)); + topology.add(arg_max_min("arg_max", { "input", "const", "second_output" }, ov::op::TopKMode::MIN, top_k, 0)); topology.add(reorder("reorder", "arg_max", second_output->get_layout())); std::vector input_vec = { @@ -355,7 +355,7 @@ TEST(set_output_memory_gpu, mutable_output_data) { topology.add(input_layout("Add_1396", input->get_layout())); topology.add(cldnn::mutable_data("second_input", second_input)); topology.add(cldnn::mutable_data("12220_md_write", final_output)); - topology.add(arg_max_min("arg_max", { "Add_1396", "second_input", "12220_md_write" }, arg_max_min::min, top_k, arg_max_min::batch)); + topology.add(arg_max_min("arg_max", { "Add_1396", "second_input", "12220_md_write" }, ov::op::TopKMode::MIN, top_k, 0)); topology.add(cldnn::mutable_data("pred/sink_port_0", {"arg_max"},final_output) ); std::vector input_vec = {