mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
After f-p4-smf68943534, pick_ww takes (n, n_expert, staged, wide); the Qwen3.6 copy's call in src/prefill/moe_fused_iq_q36.cu becomes, as lane P4-Q36 compiled it on sm_120 in its scratch merge (7bc09fadf+f68943534+ e14d4e370; one-layer parity passed on the RTX PRO 5000; the line is byte-equal in its scratch trees src-g1m.tgz and src-g2.tgz): const int ww = pick_ww(n, n_expert, sw_on(g.gu_type, true), g.gu_type == T_Q6_K || g.gu_type == T_Q8_0); The merge itself had no conflict; this one line is the only change beyond the two branches.
This commit is contained in:
commit
9f81b8b67c
6 files changed
+82
-5
No files matched your search
@@ -29,6 +29,11 @@ void quantize_act_native(const float* x, int64_t rows, int64_t cols, void* xa, v
|
||||
/// One layer's experts [b.e0, b.e1): see moe_fused_iq.hpp's experts_native.
|
||||
void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n, const void* scratch, const void* xa,
|
||||
const int32_t* src, void* ha, float* dm, void* stream);
|
||||
/// native_supported / experts_native plus the K-quant downs of UD-Q4_K_XL (a Q4_K or Q5_K gate/up with a Q5_K or Q6_K down: K = 512 is two 256-value
|
||||
/// super-blocks), which the copy of moe_fused_iq.cu has instances for but whose dispatch is not part of it. Every other pair goes to the two above.
|
||||
bool native_supported_ext(int gu_type, int d_type);
|
||||
void experts_native_ext(const Batch& b, const NativeGeom& g, int n_expert, int64_t n, const void* scratch, const void* xa,
|
||||
const int32_t* src, void* ha, float* dm, void* stream);
|
||||
#endif
|
||||
|
||||
} // namespace strata::prefill::fused_q36
|
||||
@@ -897,7 +897,7 @@ native_kernel(const BatchOf<NT> b, const NativeGeom geo, const Tables tb, const
|
||||
: blob + geo.down_off + (size_t) (rbase + ur) * geo.d_row;
|
||||
// gate/up in Q2_0 (64-value blocks): a block per stage, as the down rows read theirs; in Q8_0 (32-value blocks, CUDA
|
||||
// STRATA_PF_FUSED_Q8GU=1): two blocks a stage, as the Q8_0 down rows read theirs
|
||||
constexpr bool GU256 = GU && WT != T_Q2_0 && WT != T_Q8_0 && !is_tq(WT);
|
||||
constexpr bool GU256 = (GU || ((WT == T_Q4_K || WT == T_Q5_K || WT == T_Q6_K) && D_ROWS_K % 256 == 0)) && WT != T_Q2_0 && WT != T_Q8_0 && !is_tq(WT); // (a K-quant DOWN walks its 256-value super-blocks too, when n_ff is a multiple of 256: Qwen3.6's 512)
|
||||
constexpr bool B128 = is_tq(WT); // (CUDA, STRATA_PF_FUSED_TQ=1) 128-value blocks, gate/up and down: a block per two stages, sub-blocks 0-3
|
||||
auto unit = [&](int s) -> const uint8_t* { // the block of stage s's sub-block
|
||||
if (B128) return wrow + (s >> 1) * BS;
|
||||
|
||||
@@ -57,6 +57,73 @@ bool requested();
|
||||
namespace strata::prefill::fused_q36 {
|
||||
// the one function of moe_fused.cu (outside the renamed copy) the kernels' rules call: the same answer for both copies
|
||||
bool requested() { return strata::prefill::fused::requested(); }
|
||||
|
||||
// ---- the K-quant downs of UD-Q4_K_XL (Q5_K on 38 layers, Q6_K on 3), item C --------------------------------------------------------------------------
|
||||
// native_kernel<T, false, ...> walks a K-quant down row's 256-value super-blocks (GU256's `D_ROWS_K % 256 == 0` arm: K = 512 here, two blocks a row) and reads
|
||||
// the minimum's code sums the Q4_K / Q5_K gate/up epilogue writes into H's spare bytes (has_min); the dispatch is not in the copy's native_supported /
|
||||
// experts_native (and moe_fused_iq.cu is not edited for it), so it is here: the pair rule of the K-quant gate/up (native_supported(gu, T_Q5_1): the same
|
||||
// prerequisites - STRATA_PF_FUSED, the K-quant instances set up, no NT = 256 / warp-specialized kernels) plus this file's own set-up of the two down instances,
|
||||
// then the K-quant launch of experts_native with the new down. (After lane SMALL-SM's pick_ww(n, n_expert, staged, wide) lands this call takes its arguments.)
|
||||
namespace {
|
||||
struct KqDown {
|
||||
bool ok = false;
|
||||
int occ5 = 1, occ6 = 1; // blocks per multiprocessor of the Q5_K / Q6_K down instances
|
||||
};
|
||||
const KqDown& kqdown_info() {
|
||||
static std::mutex mu;
|
||||
static KqDown per[32];
|
||||
static bool done[32] = {};
|
||||
int dev = 0;
|
||||
cudaGetDevice(&dev);
|
||||
std::lock_guard<std::mutex> lk(mu);
|
||||
KqDown& k = per[dev & 31];
|
||||
if (done[dev & 31]) return k;
|
||||
done[dev & 31] = true;
|
||||
const DevInfo& d = dev_info();
|
||||
int o5 = 1 << 20, o6 = 1 << 20;
|
||||
if (d.ok && d.kq && setup_one<T_Q5_K, false>(o5) && setup_one<T_Q6_K, false>(o6)) {
|
||||
k.ok = true;
|
||||
k.occ5 = o5;
|
||||
k.occ6 = o6;
|
||||
}
|
||||
cudaGetLastError();
|
||||
return k;
|
||||
}
|
||||
bool is_kq_down_pair(int gu_type, int d_type) {
|
||||
return (gu_type == T_Q4_K || gu_type == T_Q5_K) && (d_type == T_Q5_K || d_type == T_Q6_K);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool native_supported_ext(int gu_type, int d_type) {
|
||||
if (is_kq_down_pair(gu_type, d_type)) return native_supported(gu_type, T_Q5_1) && kqdown_info().ok;
|
||||
return native_supported(gu_type, d_type);
|
||||
}
|
||||
|
||||
void experts_native_ext(const Batch& b, const NativeGeom& g, int n_expert, int64_t n, const void* scratch, const void* xa, const int32_t* src, void* ha,
|
||||
float* dm, void* stream) {
|
||||
if (!is_kq_down_pair(g.gu_type, g.d_type)) {
|
||||
experts_native(b, g, n_expert, n, scratch, xa, src, ha, dm, stream);
|
||||
return;
|
||||
}
|
||||
if (b.e1 <= b.e0 || n <= 0) return;
|
||||
const DevInfo& d = dev_info();
|
||||
const KqDown& kd = kqdown_info();
|
||||
if (!d.ok || !d.kq || !kd.ok) {
|
||||
std::fprintf(stderr, "prefill fused experts (Qwen3.6): types %d / %d are not covered here\n", g.gu_type, g.d_type);
|
||||
std::exit(1);
|
||||
}
|
||||
const cudaStream_t s = (cudaStream_t) stream;
|
||||
const Tables tb = tables(const_cast<void*>(scratch), n_expert);
|
||||
const int ww = pick_ww(n, n_expert, sw_on(g.gu_type, true), g.gu_type == T_Q6_K || g.gu_type == T_Q8_0);
|
||||
const int64_t tiles = (n + kTileRows - 1) / kTileRows + (b.e1 - b.e0);
|
||||
const unsigned k_gu = (unsigned) std::min<int64_t>(tiles * (GU_ROWS_N / weight_rows(ww)), (int64_t) d.sms * d.occ_kq);
|
||||
const unsigned k_d = (unsigned) std::min<int64_t>(tiles * (D_ROWS_N / weight_rows(ww)), (int64_t) d.sms * (g.d_type == T_Q5_K ? kd.occ5 : kd.occ6));
|
||||
if (g.gu_type == T_Q4_K) launch<T_Q4_K, true>(ww, k_gu, b, g, tb, xa, src, ha, nullptr, s);
|
||||
else launch<T_Q5_K, true>(ww, k_gu, b, g, tb, xa, src, ha, nullptr, s);
|
||||
if (g.d_type == T_Q5_K) launch<T_Q5_K, false>(ww, k_d, b, g, tb, ha, src, nullptr, dm, s);
|
||||
else launch<T_Q6_K, false>(ww, k_d, b, g, tb, ha, src, nullptr, dm, s);
|
||||
ck(cudaGetLastError(), "experts_native_ext");
|
||||
}
|
||||
} // namespace strata::prefill::fused_q36
|
||||
|
||||
#endif // !__HIPCC__
|
||||
@@ -1399,7 +1399,7 @@ struct Engine {
|
||||
g.n_ff == FQ::kQ36FF)
|
||||
for (size_t i = 0; i < n_state; ++i) {
|
||||
const Layer& L = layer_at((int) i);
|
||||
fused_on[i] = FQ::native_supported(L.L.gu_type, L.L.d_type) ? 1 : 0;
|
||||
fused_on[i] = FQ::native_supported_ext(L.L.gu_type, L.L.d_type) ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
use_pf = true;
|
||||
@@ -2140,7 +2140,7 @@ struct Engine {
|
||||
b.e0 = e;
|
||||
b.e1 = std::min(ne, e + FQ::kQ36MaxBatch);
|
||||
for (int x = b.e0; x < b.e1; ++x) b.blob[x - b.e0] = wbase + (size_t) x * L.stride;
|
||||
FQ::experts_native(b, ng, ne, n_ent, f_scr, f_xq, f_src, f_ha, eparts, st);
|
||||
FQ::experts_native_ext(b, ng, ne, n_ent, f_scr, f_xq, f_src, f_ha, eparts, st);
|
||||
}
|
||||
prow = f_slot;
|
||||
#endif
|
||||
|
||||
@@ -245,7 +245,7 @@ void run_fused(const Pair& p, const Geo& geo, FusedBufs& b, const float* x_dev,
|
||||
bt.e0 = e0;
|
||||
bt.e1 = std::min(cuts[c + 1], e0 + fq::kQ36MaxBatch);
|
||||
for (int e = bt.e0; e < bt.e1; ++e) bt.blob[e - bt.e0] = blob[(size_t) e];
|
||||
fq::experts_native(bt, ng, E, rows, b.scratch.p, b.xa.p, b.src.as<int32_t>(), b.ha.p, b.dm.as<float>(), s);
|
||||
fq::experts_native_ext(bt, ng, E, rows, b.scratch.p, b.xa.p, b.src.as<int32_t>(), b.ha.p, b.dm.as<float>(), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -614,7 +614,7 @@ int main(int argc, char** argv) {
|
||||
ck(cudaStreamCreateWithFlags(&s, cudaStreamNonBlocking), "stream");
|
||||
for (const Pair& p : pairs) {
|
||||
if (only && std::string(p.name).find(only) == std::string::npos) continue;
|
||||
if (!fq::native_supported((int) p.gu, (int) p.d)) {
|
||||
if (!fq::native_supported_ext((int) p.gu, (int) p.d)) {
|
||||
if (p.optional) { std::printf("%s: not covered by this build of the Qwen3.6 kernels (skipped)\n", p.name); continue; }
|
||||
throw std::runtime_error(std::string(p.name) + ": not covered by the Qwen3.6 copy of the kernels");
|
||||
}
|
||||
|
||||
@@ -161,6 +161,11 @@ ALLOWED = {
|
||||
# spill 36 / 52 (sm_86), 32 / 32 (sm_120) at the 128-register cap of __launch_bounds__(THREADS = 512, 1); its q[8]
|
||||
# / raw[5] / bq[4] / a[4] / d[4] stay in registers
|
||||
"strata::prefill::fused::{anonymous}::native_kernel": {"sm_120": (32, 0), "sm_86": (32, 0)},
|
||||
# the Qwen3.6 copy of the same kernels (moe_fused_iq_q36.cu includes moe_fused_iq.cu with the shape override and its namespace renamed): same source and
|
||||
# instance parameters, so the same spill under the same register cap, no per-thread array found (an instance has the same STACK as its fused:: twin in 24 of 25 cases on
|
||||
# sm_86 and 7 of 10 on sm_120, never more than 8 B apart). Measured on f-p4-q36 7bc09fadf, CUDA 13.2 sm_120 (l620) and CUDA 12.9
|
||||
# cuobjdump on CUDA 13.0 objects for sm_86 (z440): the maximum over 62 instances, which include the K-quant down instances <13 / 14, false, 2 / 4, 512>
|
||||
"strata::prefill::fused_q36::{anonymous}::native_kernel": {"sm_120": (16, 0), "sm_86": (80, 0)},
|
||||
# float x[GRW_PER] (GRW_PER = 10): the thread's rows for the norm (no spill)
|
||||
"strata::prefill::{anonymous}::gr_write_cvec_norm_rs_kernel": {"sm_86": (40, 0)},
|
||||
# float v[GRW_PER] (GRW_PER = 10): the thread's rows for the norm (no spill)
|
||||
|
||||
Reference in new issue
Block a user