Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Support BF16 for Topk (#39655)

Min, Byungil41854db66946
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 002d1ce635b..73305c6a0e8 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
@@ -135,7 +135,7 @@ public:
namespace detail {
attach_arg_max_min_impl::attach_arg_max_min_impl() {
- auto types = {data_types::f16, data_types::f32, data_types::i8, data_types::i32, data_types::u8};
+ auto types = {data_types::f16, data_types::bf16, data_types::f32, data_types::i8, data_types::i32, data_types::u8};
auto formats = {
format::bfyx,
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/arg_max_min_axis.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/arg_max_min_axis.cl
index 3715ed67e99..7ff4329379a 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/arg_max_min_axis.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/arg_max_min_axis.cl
@@ -25,6 +25,9 @@
#define AXIS 4
#endif
+#define GET_INPUT_VALUE() DECODE_INPUT0_COMPUTE_TYPE( \
+ input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])])
+
// Value order shared with arg_max_min_topk_radix: NaN ranks above +inf as in PyTorch, and -0.0
// equals +0.0. Plain float comparisons are false for NaN, so with them a NaN ranks first and races
// with the true maximum for the same output position.
@@ -181,7 +184,7 @@ KERNEL(arg_max_min_modified)(
indices[AXIS] = sort_idx;
iav_type result;
- result.value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result.value = GET_INPUT_VALUE();
result.index = sort_idx;
// Values before sort_idx rank ahead when they rank at or above this one, later values when
@@ -196,13 +199,13 @@ KERNEL(arg_max_min_modified)(
#ifdef MAX_OUT
for (uint i = 0; i < sort_idx && sort_position < TOP_K; i++) {
indices[AXIS] = i;
- sort_position += isnan(input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])]) ? 1 : 0;
+ sort_position += isnan(GET_INPUT_VALUE()) ? 1 : 0;
}
#else
sort_position = sort_idx;
for (uint i = sort_idx + 1; i < VALUES_NUM && sort_position < TOP_K; i++) {
indices[AXIS] = i;
- sort_position += isnan(input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])]) ? 0 : 1;
+ sort_position += isnan(GET_INPUT_VALUE()) ? 0 : 1;
}
#endif
head_end = 0;
@@ -213,35 +216,35 @@ KERNEL(arg_max_min_modified)(
for (uint i = 0; i < head_end / 8; i++) {
uint index_offset = i * 8;
indices[AXIS] = index_offset;
- INPUT0_TYPE test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ INPUT0_COMPUTE_TYPE test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 1;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 2;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 3;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 4;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 5;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 6;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 7;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
if (sort_position + PARALLEL_RANK(counted, index_offset + 8) >= TOP_K)
@@ -250,7 +253,7 @@ KERNEL(arg_max_min_modified)(
for (uint i = (head_end / 8) * 8; i < head_end; i++) {
indices[AXIS] = i;
- INPUT0_TYPE test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ INPUT0_COMPUTE_TYPE test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_1(result.value, test_value))
counted++;
}
@@ -265,42 +268,42 @@ KERNEL(arg_max_min_modified)(
const uint tail_aligned = min((tail_begin + 7) / 8 * 8, (uint)VALUES_NUM);
for (uint i = tail_begin; i < tail_aligned; i++) {
indices[AXIS] = i;
- INPUT0_TYPE test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ INPUT0_COMPUTE_TYPE test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
}
for (uint i = tail_aligned / 8; i < VALUES_NUM / 8; i++) {
uint index_offset = i * 8;
indices[AXIS] = index_offset;
- INPUT0_TYPE test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ INPUT0_COMPUTE_TYPE test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 1;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 2;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 3;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 4;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 5;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 6;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
indices[AXIS] = index_offset + 7;
- test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
if (sort_position + PARALLEL_RANK(counted, index_offset + 8 - tail_begin) >= TOP_K)
@@ -309,7 +312,7 @@ KERNEL(arg_max_min_modified)(
for (uint i = max(tail_aligned, (uint)(VALUES_NUM / 8) * 8); i < VALUES_NUM; i++) {
indices[AXIS] = i;
- INPUT0_TYPE test_value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ INPUT0_COMPUTE_TYPE test_value = GET_INPUT_VALUE();
if (COMPARE_PARALLEL_SIGN_2(result.value, test_value))
counted++;
}
@@ -320,7 +323,7 @@ KERNEL(arg_max_min_modified)(
// Using simple sorting for sorting by indices and when TOP_K == 1
#elif TOP_K == 1
- INPUT0_TYPE val = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ INPUT0_COMPUTE_TYPE val = GET_INPUT_VALUE();
result[0].index = 0;
result[0].value = val;
bool already_exist = false;
@@ -339,7 +342,7 @@ KERNEL(arg_max_min_modified)(
}
indices[AXIS] = i;
- INPUT0_TYPE in_data = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ INPUT0_COMPUTE_TYPE in_data = GET_INPUT_VALUE();
if (COMPARE_SIGN(val, in_data)) {
result[top_k].index = i;
result[top_k].value = in_data;
@@ -355,26 +358,26 @@ KERNEL(arg_max_min_modified)(
for (uint i = 0; i < VALUES_NUM / 8; i++) {
uint index_offset = i * 8;
indices[AXIS] = result[index_offset].index = index_offset;
- result[index_offset].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset].value = GET_INPUT_VALUE();
indices[AXIS] = result[index_offset + 1].index = index_offset + 1;
- result[index_offset + 1].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset + 1].value = GET_INPUT_VALUE();
indices[AXIS] = result[index_offset + 2].index = index_offset + 2;
- result[index_offset + 2].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset + 2].value = GET_INPUT_VALUE();
indices[AXIS] = result[index_offset + 3].index = index_offset + 3;
- result[index_offset + 3].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset + 3].value = GET_INPUT_VALUE();
indices[AXIS] = result[index_offset + 4].index = index_offset + 4;
- result[index_offset + 4].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset + 4].value = GET_INPUT_VALUE();
indices[AXIS] = result[index_offset + 5].index = index_offset + 5;
- result[index_offset + 5].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset + 5].value = GET_INPUT_VALUE();
indices[AXIS] = result[index_offset + 6].index = index_offset + 6;
- result[index_offset + 6].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset + 6].value = GET_INPUT_VALUE();
indices[AXIS] = result[index_offset + 7].index = index_offset + 7;
- result[index_offset + 7].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[index_offset + 7].value = GET_INPUT_VALUE();
}
for (uint i = (VALUES_NUM / 8) * 8; i < VALUES_NUM; i++) {
indices[AXIS] = result[i].index = i;
- result[i].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ result[i].value = GET_INPUT_VALUE();
}
for (uint k = 1; k < VALUES_NUM; k *= 2) {
@@ -404,26 +407,26 @@ KERNEL(arg_max_min_modified)(
for (uint i = 0; i < VALUES_NUM / 8; i++) {
uint index_offset = i * 8;
indices[AXIS] = temp_buf[index_offset].index = index_offset;
- temp_buf[index_offset].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset].value = GET_INPUT_VALUE();
indices[AXIS] = temp_buf[index_offset + 1].index = index_offset + 1;
- temp_buf[index_offset + 1].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset + 1].value = GET_INPUT_VALUE();
indices[AXIS] = temp_buf[index_offset + 2].index = index_offset + 2;
- temp_buf[index_offset + 2].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset + 2].value = GET_INPUT_VALUE();
indices[AXIS] = temp_buf[index_offset + 3].index = index_offset + 3;
- temp_buf[index_offset + 3].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset + 3].value = GET_INPUT_VALUE();
indices[AXIS] = temp_buf[index_offset + 4].index = index_offset + 4;
- temp_buf[index_offset + 4].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset + 4].value = GET_INPUT_VALUE();
indices[AXIS] = temp_buf[index_offset + 5].index = index_offset + 5;
- temp_buf[index_offset + 5].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset + 5].value = GET_INPUT_VALUE();
indices[AXIS] = temp_buf[index_offset + 6].index = index_offset + 6;
- temp_buf[index_offset + 6].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset + 6].value = GET_INPUT_VALUE();
indices[AXIS] = temp_buf[index_offset + 7].index = index_offset + 7;
- temp_buf[index_offset + 7].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[index_offset + 7].value = GET_INPUT_VALUE();
}
for (uint i = (VALUES_NUM / 8) * 8; i < VALUES_NUM; i++) {
indices[AXIS] = temp_buf[i].index = i;
- temp_buf[i].value = input[FUNC_CALL(get_input_index)(OPTIONAL_SHAPE_INFO_TENSOR indices[0], indices[1], 0, indices[2], indices[3], indices[4])];
+ temp_buf[i].value = GET_INPUT_VALUE();
}
for (uint group = 0; group < group_num - 1; group++) {
@@ -583,6 +586,7 @@ KERNEL(arg_max_min_modified)(
#undef ORDER_GT
#undef ORDER_GE
#undef INPUT0_FILL_VAL
+#undef GET_INPUT_VALUE
#undef AXIS
#undef VALUES_NUM
#undef MINIMUM_NUMBER_FOR_PARTIAL_SORTING
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/arg_max_min_common.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/arg_max_min_common.cl
index da7b0ae2caa..2792faf7547 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/arg_max_min_common.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/arg_max_min_common.cl
@@ -8,7 +8,7 @@
typedef struct
{
uint index;
- INPUT0_TYPE value;
+ INPUT0_COMPUTE_TYPE value;
} iav_type;
#define IAV_STRUCT_DEFINED
#endif
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/arg_max_min/arg_max_min_kernel_axis.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/arg_max_min/arg_max_min_kernel_axis.cpp
index 68884c69625..9999e8786ae 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/arg_max_min/arg_max_min_kernel_axis.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/arg_max_min/arg_max_min_kernel_axis.cpp
@@ -45,11 +45,18 @@ size_t getSortSize(const arg_max_min_params& params) {
throw std::invalid_argument("Unsupported axis");
}
}
+
+bool useParallelValueSort(const arg_max_min_params& params) {
+ // A single BF16 result needs no value ordering, and the linear scan avoids per-candidate ranking.
+ return params.argMaxMinSortType == ArgMaxMinSortType::VALUE &&
+ (params.inputs[0].GetDType() != Datatype::BF16 || params.topK != 1);
+}
} // namespace
ParamsKey ArgMaxMinKernelAxis::GetSupportedKey() const {
ParamsKey k;
k.EnableInputDataType(Datatype::F16);
+ k.EnableInputDataType(Datatype::BF16);
k.EnableInputDataType(Datatype::F32);
k.EnableInputDataType(Datatype::INT8);
k.EnableInputDataType(Datatype::UINT8);
@@ -92,7 +99,6 @@ bool ArgMaxMinKernelAxis::Validate(const Params& p) const {
}
const arg_max_min_params& params = static_cast<const arg_max_min_params&>(p);
-
if (params.inputs.size() > 1) {
if (params.inputs[1].PitchesDifferFromLogicalDims() || params.outputs[0].PitchesDifferFromLogicalDims()) {
DO_NOT_USE_THIS_KERNEL(p.layerID);
@@ -108,7 +114,7 @@ ArgMaxMinKernelBase::DispatchData ArgMaxMinKernelAxis::SetDefault(const arg_max_
if (!params.has_dynamic_tensors()) {
size_t ops_size = getOperationNumber(params);
ops_size = ops_size > 1 ? Align(ops_size, 32) : 1;
- size_t sort_size = params.argMaxMinSortType == ArgMaxMinSortType::VALUE ? getSortSize(params) : 1;
+ size_t sort_size = useParallelValueSort(params) ? getSortSize(params) : 1;
dispatchData.gws = { ops_size, sort_size, 1 };
dispatchData.lws = GetOptimalLocalWorkGroupSizes(dispatchData.gws, params.engineInfo);
@@ -120,7 +126,8 @@ ArgMaxMinKernelBase::DispatchData ArgMaxMinKernelAxis::SetDefault(const arg_max_
namespace {
std::vector<InternalBuffer> get_internal_buffer_sizes(const arg_max_min_params& params) {
const size_t elem_size = params.inputs[0].ElementSize();
- const size_t iav_type_size = Align(elem_size + 4, 4);
+ const size_t value_size = params.inputs[0].GetDType() == Datatype::BF16 ? sizeof(float) : elem_size;
+ const size_t iav_type_size = Align(value_size + sizeof(uint32_t), sizeof(uint32_t));
const size_t sort_size = getSortSize(params);
const size_t ops_size = getOperationNumber(params);
const size_t group_size = params.topK >= 8 ? params.topK : 8;
@@ -208,7 +215,7 @@ JitConstants ArgMaxMinKernelAxis::GetJitConstants(const arg_max_min_params& para
const size_t operation_num = getOperationNumber(params);
jit.AddConstant(MakeJitConstant("OPERATION_NUM", operation_num));
}
- if (params.argMaxMinSortType == ArgMaxMinSortType::VALUE) {
+ if (useParallelValueSort(params)) {
jit.AddConstant(MakeJitConstant("SORT_BY_VALUE", 1));
} else {
jit.AddConstant(MakeJitConstant("SORT_BY_INDEX", 1));
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp
index cf9098f9d14..d420e7e8439 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp
@@ -4,10 +4,41 @@
#include "single_op_tests/topk.hpp"
+#include <algorithm>
+
+#include "openvino/runtime/properties.hpp"
+
namespace {
using ov::test::TopK11LayerTest;
using ov::test::TopKLayerTest;
+class TopK11LayerTestBF16GPU : public TopK11LayerTest {
+protected:
+ void SetUp() override {
+ TopK11LayerTest::SetUp();
+ const auto capabilities = core->get_property(targetDevice, ov::device::capabilities);
+ if (std::find(capabilities.begin(), capabilities.end(), ov::device::capability::BF16) == capabilities.end()) {
+ GTEST_SKIP() << "Device does not support BF16";
+ }
+ configuration.insert(ov::hint::inference_precision(ov::element::bf16));
+ }
+
+ void validate() override {
+ TopK11LayerTest::validate();
+ const auto runtime_model = compiledModel.get_runtime_model();
+ const auto& ops = runtime_model->get_ordered_ops();
+ const auto topk = std::find_if(ops.begin(), ops.end(), [](const std::shared_ptr<ov::Node>& op) {
+ return op->get_rt_info().at("layerType").as<std::string>() == "ArgMax";
+ });
+ ASSERT_NE(topk, ops.end());
+ EXPECT_EQ((*topk)->get_rt_info().at("runtimePrecision").as<std::string>(), "bf16");
+ }
+};
+
+TEST_P(TopK11LayerTestBF16GPU, Inference) {
+ run();
+}
+
std::vector<ov::Shape> shapes = {{10, 10, 10}};
const std::vector<ov::element::Type> netPrecisions = {
@@ -54,4 +85,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_TopK11,
::testing::Values(ov::test::utils::DEVICE_GPU)),
TopK11LayerTest::getTestCaseName);
+INSTANTIATE_TEST_SUITE_P(smoke_TopK11_BF16,
+ TopK11LayerTestBF16GPU,
+ ::testing::Combine(::testing::ValuesIn(keep),
+ ::testing::ValuesIn(axes),
+ ::testing::ValuesIn(modes),
+ ::testing::ValuesIn(sortTypes),
+ ::testing::Values(ov::element::bf16),
+ ::testing::Values(ov::test::static_shapes_to_test_representation(shapes)),
+ ::testing::ValuesIn(stable),
+ ::testing::Values(ov::test::utils::DEVICE_GPU)),
+ TopK11LayerTest::getTestCaseName);
+
} // namespace
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/top_k.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/top_k.cpp
index 18c58ebbaa1..1d657e9dfad 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/top_k.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/top_k.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include <algorithm>
#include <random>
#include "common_test_utils/ov_tensor_utils.hpp"
@@ -12,6 +13,7 @@
#include "openvino/op/constant.hpp"
#include "openvino/op/result.hpp"
#include "openvino/op/topk.hpp"
+#include "openvino/runtime/properties.hpp"
namespace {
using ov::test::InputShape;
@@ -66,6 +68,14 @@ protected:
targetDevice = _targetDevice;
input_type = _input_type;
+ if (model_type == ov::element::bf16) {
+ const auto capabilities = core->get_property(targetDevice, ov::device::capabilities);
+ if (std::find(capabilities.begin(), capabilities.end(), ov::device::capability::BF16) == capabilities.end()) {
+ GTEST_SKIP() << "Device does not support BF16";
+ }
+ configuration.insert(ov::hint::inference_precision(ov::element::bf16));
+ }
+
if (input_type == ov::test::utils::InputLayerType::CONSTANT) {
init_input_shapes({input_shape});
} else {
@@ -128,6 +138,18 @@ protected:
for (size_t i = 0; i < size; ++i) {
rawBlobDataPtr[i] = static_cast<ov::float16>(data[i]);
}
+ } else if (model_type == ov::element::bf16) {
+ std::vector<int> data(size);
+
+ int start = -static_cast<int>(size / 2);
+ std::iota(data.begin(), data.end(), start);
+ std::mt19937 gen(0);
+ std::shuffle(data.begin(), data.end(), gen);
+
+ auto* rawBlobDataPtr = static_cast<ov::bfloat16*>(tensor.data());
+ for (size_t i = 0; i < size; ++i) {
+ rawBlobDataPtr[i] = static_cast<ov::bfloat16>(data[i]);
+ }
} else {
FAIL() << "generate_inputs for " << model_type << " precision isn't supported";
}
@@ -147,6 +169,21 @@ protected:
}
}
+ void validate() override {
+ ov::test::SubgraphBaseTest::validate();
+ if (model_type != ov::element::bf16) {
+ return;
+ }
+
+ const auto runtime_model = compiledModel.get_runtime_model();
+ const auto& ops = runtime_model->get_ordered_ops();
+ const auto topk = std::find_if(ops.begin(), ops.end(), [](const std::shared_ptr<ov::Node>& op) {
+ return op->get_rt_info().at("layerType").as<std::string>() == "ArgMax";
+ });
+ ASSERT_NE(topk, ops.end());
+ EXPECT_EQ((*topk)->get_rt_info().at("runtimePrecision").as<std::string>(), "bf16");
+ }
+
private:
int64_t axis;
size_t inferRequestNum = 0;
@@ -161,6 +198,7 @@ TEST_P(TopKLayerGPUTest, Inference) {
const std::vector<ov::element::Type> model_types = {
ov::element::f32,
ov::element::f16,
+ ov::element::bf16,
};
const std::vector<int64_t> axes = {0, 3};
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/arg_max_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/arg_max_gpu_test.cpp
index e227d99efd6..7b83e1444ac 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/arg_max_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/arg_max_gpu_test.cpp
@@ -1916,6 +1916,42 @@ std::vector<float> topk_radix_special_values(size_t rows, size_t row_size, ov::o
}
} // namespace
+TEST(arg_max_gpu_topk_axis_bf16, k1_sort_values) {
+ ASSERT_NO_FATAL_FAILURE(run_topk_radix_case<ov::bfloat16>(
+ ov::PartialShape{2, 64, 1, 1},
+ {{2, 64, 1, 1}},
+ 1,
+ ov::op::TopKMode::MAX,
+ 1,
+ [](size_t rows, size_t row_size) { return topk_radix_random_values(rows, row_size, 31); },
+ ov::op::TopKSortType::SORT_VALUES,
+ "arg_max_min_axis"));
+}
+
+TEST(arg_max_gpu_topk_axis_bf16, k_greater_than_one_sort_values) {
+ ASSERT_NO_FATAL_FAILURE(run_topk_radix_case<ov::bfloat16>(
+ ov::PartialShape{2, 64, 1, 1},
+ {{2, 64, 1, 1}},
+ 1,
+ ov::op::TopKMode::MIN,
+ 5,
+ [](size_t rows, size_t row_size) { return topk_radix_random_values(rows, row_size, 37); },
+ ov::op::TopKSortType::SORT_VALUES,
+ "arg_max_min_axis"));
+}
+
+TEST(arg_max_gpu_topk_axis_bf16, internal_buffer_sort_indices) {
+ ASSERT_NO_FATAL_FAILURE(run_topk_radix_case<ov::bfloat16>(
+ ov::PartialShape{2, 2049, 1, 1},
+ {{2, 2049, 1, 1}},
+ 1,
+ ov::op::TopKMode::MAX,
+ 5,
+ [](size_t rows, size_t row_size) { return topk_radix_random_values(rows, row_size, 41); },
+ ov::op::TopKSortType::SORT_INDICES,
+ "arg_max_min_axis"));
+}
+
// Chunked mode with dynamic rows: the maximum level repeats in every chunk, so the first
// top-K indices come from equal values spread over several chunks.
TYPED_TEST(arg_max_gpu_topk_radix, chunked_dynamic_rows_tied_indices) {