Skip to content

Commit 07ac3ce

Browse files
authored
Merge pull request #25 from chimpera/fix-argmax-topk-64
fix(cuda): increase argmax topk kernel limit from 32 to 64
2 parents c6dfa39 + 91357dd commit 07ac3ce

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

ggml/src/ggml-cuda/argmax.cu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ static __global__ void topk_f32(
237237

238238
// Per-thread top-K heap (min-heap: smallest score at index 0)
239239
// Max K=32, stored in registers
240-
float heap_val[32];
241-
int32_t heap_idx[32];
240+
float heap_val[64];
241+
int32_t heap_idx[64];
242242
for (int i = 0; i < K; i++) {
243243
heap_val[i] = -FLT_MAX;
244244
heap_idx[i] = -1;
@@ -527,7 +527,7 @@ void ggml_cuda_argmax(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
527527
const int cub_mode = ggml_cuda_dflash_cub_topk_mode();
528528
const bool use_cub_topk =
529529
K > 1 && !output_logprob && seed == 0 &&
530-
(K > 32 || cub_mode == 1 || (cub_mode < 0 && nrows > 32));
530+
(K > 64 || cub_mode == 1 || (cub_mode < 0 && nrows > 32));
531531
if (ggml_cuda_dflash_argmax_profile_enabled() && K > 1) {
532532
GGML_LOG_INFO("%s: dflash argmax profile path=%s K=%d nrows=%" PRId64
533533
" vocab=%" PRId64 " temp=%.3f seed=%" PRIu64 " output_logprob=%d cub_mode=%d\n",
@@ -554,7 +554,7 @@ void ggml_cuda_argmax(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
554554
if (K == 1) {
555555
argmax_f32<<<blocks_num, blocks_dim, 0, stream>>>(src0_d, dst_d, ne00, nrows, inv_temp, seed, output_logprob);
556556
} else {
557-
GGML_ASSERT(K <= 32);
557+
GGML_ASSERT(K <= 64);
558558
// Shared memory: K * n_warps floats + K * n_warps ints + 2 * n_warps floats (softmax)
559559
const int n_warps = (int)(num_threads / WARP_SIZE);
560560
const size_t smem_size = K * n_warps * (sizeof(float) + sizeof(int32_t)) + 2 * n_warps * sizeof(float);

0 commit comments

Comments
 (0)