From cba7b2ed2dfe2f11b83ebb61b84d4e548a1a6a14 Mon Sep 17 00:00:00 2001 From: Peilin Wang Date: Mon, 12 Jul 2021 16:05:14 -0400 Subject: [PATCH] initial commit: fix topk index --- .../backend/kernel_compiler/gpu/cuda_impl/in_top_k_impl.cu | 2 +- tests/st/ops/gpu/test_in_top_k.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/in_top_k_impl.cu b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/in_top_k_impl.cu index e5da715acb1..d56307e9472 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/in_top_k_impl.cu +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/in_top_k_impl.cu @@ -26,7 +26,7 @@ __global__ void InTopK(const T *predictions, const int32_t *targets, bool *outpu for (; gt_id < batch_size; gt_id += blockDim.x * gridDim.x) { int32_t target_index = targets[gt_id]; T predicted_value = predictions[gt_id * class_id_count + target_index]; - T top_k_smallest_value = top_k_output[k - 1]; + T top_k_smallest_value = top_k_output[gt_id * k + k - 1]; output[gt_id] = predicted_value >= top_k_smallest_value; } diff --git a/tests/st/ops/gpu/test_in_top_k.py b/tests/st/ops/gpu/test_in_top_k.py index fe4df4170cb..3ec6f4f4d8d 100644 --- a/tests/st/ops/gpu/test_in_top_k.py +++ b/tests/st/ops/gpu/test_in_top_k.py @@ -32,9 +32,9 @@ class InTopKNet(nn.Cell): def in_top_k(nptype): context.set_context(mode=context.GRAPH_MODE, device_target="GPU") - predictions = Tensor(np.array([[9, 3, 8, 0, 0, 0, 0, 0, 0], + predictions = Tensor(np.array([[4, 1, 2, 0, 0, 0, 0, 0, 0], [7, 9, 9, 0, 0, 0, 0, 0, 0], - [9, 9, 9, 0, 0, 0, 0, 0, 0]]).astype(nptype)) + [3, 3, 3, 0, 0, 0, 0, 0, 0]]).astype(nptype)) k = 1 in_top_k_net = InTopKNet(k)