mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
prefill: size the dense MMQ row-id table with the margin llama.cpp's kernels read past it (STRATA_DENSE_MMQ=1)
Gemm::native_mmq (HIP builds, opt-in STRATA_DENSE_MMQ=1) passes MMQ an identity row-id table of exactly kRows = 1024 ints (4096 bytes), followed by 256 bytes of bounds and then the end of the allocation. llama.cpp's mul_mat_q copies ids_dst[col_low + jt * J + j] for a whole J-column tile before it compares the tile with the expert's rows, and mul_mat_q_stream_k_fixup reads up to roundup(max_rows, J) ids from the expert's first row; J goes up to 128. A full chunk (1024 rows) with a tile width that does not divide it (J = 112: the last tile starts at row 1008 and reads to index 1119) reads 384 bytes past the table, 128 past the allocation. The table now has kRows + roundup(kRows, 128) + 128 entries (mmq_ids_table_rows, the margin the Flash-Next prompt path uses, include/strata/prefill/mmq_ids_margin.hpp; max_rows <= kRows) and the identity is written over all of it; bounds follow the larger table. Not run: this code is compiled only for HIP (STRATA_PREFILL_MMQ with __HIPCC__) and only with the opt-in switch, so it has not been built or run for this commit. The change adds 4,608 bytes to one scratch allocation and writes more identity entries; the products' inputs are the same.
This commit is contained in:
1 parent
d7f7d9677b
commit
14dd746f6a
1 file changed
+7
-2
+7
-2
@@ -2,6 +2,7 @@
|
||||
#include "strata/prefill/gemm.hpp"
|
||||
#include "strata/kernels/dequant_bf16.hpp"
|
||||
#if defined(STRATA_PREFILL_MMQ) && defined(__HIPCC__)
|
||||
#include "strata/prefill/mmq_ids_margin.hpp"
|
||||
#include "strata/prefill/moe_mmq.hpp"
|
||||
#endif
|
||||
|
||||
@@ -1294,8 +1295,12 @@ bool Gemm::native_mmq(const uint16_t* X, int type, const void* W, float* Y, int6
|
||||
if (ldy <= 0) ldy = N;
|
||||
|
||||
const auto up = [](size_t v) { return (v + 255) & ~(size_t) 255; };
|
||||
// The row table is read past its end by llama.cpp's MMQ (mul_mat_q: a whole J-column tile from the start of each tile, J up to 128; the stream-k fixup:
|
||||
// up to roundup(max_rows, J) from the expert's first row): kRows + the margin of mmq_ids_margin.hpp (max_rows <= kRows), the identity written over all of it.
|
||||
// Exact, with only the 256 bytes of the bounds after it, a tile of 112 columns on a full chunk read 384 bytes past the table, 128 past the allocation.
|
||||
const size_t ids_rows = (size_t) mmq::mmq_ids_table_rows((uint64_t) kRows, (uint64_t) kRows);
|
||||
const size_t ident_off = up(mmq::q8_bytes(kRows, kMaxK));
|
||||
const size_t bounds_off = ident_off + up((size_t) kRows * 4);
|
||||
const size_t bounds_off = ident_off + up(ids_rows * 4);
|
||||
if (!mmq_buf_) {
|
||||
if (cudaMalloc(&mmq_buf_, bounds_off + 256) != cudaSuccess) {
|
||||
cudaGetLastError();
|
||||
@@ -1303,7 +1308,7 @@ bool Gemm::native_mmq(const uint16_t* X, int type, const void* W, float* Y, int6
|
||||
return false;
|
||||
}
|
||||
mmq_ctx_ = new mmq::Context();
|
||||
mmq::iota((int32_t*) ((uint8_t*) mmq_buf_ + ident_off), kRows, stream_);
|
||||
mmq::iota((int32_t*) ((uint8_t*) mmq_buf_ + ident_off), (int64_t) ids_rows, stream_);
|
||||
std::fprintf(stderr, "prefill gemm: dense MMQ on (STRATA_DENSE_MMQ=1)\n");
|
||||
}
|
||||
void* xq = mmq_buf_;
|
||||
|
||||
Reference in new issue
Block a user