char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

cwritersycl: rfc: Use radix select for top_k (#28670)21f6b0d22

char/aliceai-t5-moe
1.1 KiB24 linesraw
1#pragma once
2
3#include "common.hpp"
4
5// The legacy implementation uses SLM to implement sorting and top_k selection.
6// SLM is limited to 128KB on Xe, which limits how much can be sorted to k<32.
7// After a k=8, the radix selection becomes beneficial for most cases, because
8// scan-merge has (block + 1) * k pairs of (value, index). Given normal sorting of nlog(n),
9// radix-select becomes beneficial quite early. This sets it to 8 - however, the other parameters
10// (columns and rows) may also be a driving factor.
11// We select the legacy implementation for k below this constant because the overhead of radix select
12// exceeds the benefit for very small problems
13constexpr int SYCL_TOP_K_SCAN_MERGE_MAX_K = 8;
14
15// Top-k of every row of src, k indices per row into dst_indices, in no particular order.
16// Picks between the one-group-per-row and the split-row kernel from the shape and the device.
17void ggml_sycl_top_k_radix(
18    ggml_backend_sycl_context & ctx,
19    const float *   src,
20    int32_t *       dst_indices,
21    const int64_t   ncols,
22    const int64_t   nrows,
23    const int       k,
24    dpct::queue_ptr main_stream);