gfx12 decode: the split HC norm from registers (-1.8 us a read), the host-flag waits folded into the copies that follow them (-2 nodes a layer); STRATA_VERIFY_NODES lists the window graph on HIP; the stage profile splits the FFN-side HC read; STRATA_DUMMY_NODES=k measures what an empty graph node costs

This commit is contained in:
Niko1221 committed 2026-10-11 04:04:07 +02:00
1 parent bb519f5bca
commit 7fc02cb5c2
6 files changed
+218 -8

No files matched your search

+82 -3
View File
@@ -1,5 +1,6 @@
// src/core/verify.cpp - see include/strata/core/verify.hpp.
#include "strata/core/batch_rows.hpp"
#include "strata/kernels/gfx_arch.hpp"
#include "strata/core/verify.hpp"
#include "strata/core/remote_expert_opt.hpp"
#include "strata/core/dma_batch.hpp"
@@ -205,6 +206,30 @@ bool head_mix_multi_enabled() {
#endif
}
// 143-amdk: the wait for a host flag folded into the copy that follows it (wait_copy_i32_from_mapped,
// copy_rows_from_mapped_after): same reads, same values, one kernel node fewer each. A dependent kernel costs ~2.4 us in a
// gfx1201 graph whatever it does; measured on gfx12 only, so it is on there by default. STRATA_FUSE_WAIT=0 / 1 forces it
// off / on (HIP builds; a CUDA build never fuses).
bool fuse_wait_on() {
#if defined(STRATA_USE_HIP)
static const int env = [] {
const char* v = std::getenv("STRATA_FUSE_WAIT");
return v != nullptr ? (std::atoi(v) != 0 ? 1 : 0) : -1;
}();
if (env >= 0) return env != 0;
static int per_dev[64]; // 0 unknown, 1 no, 2 yes
int dev = 0;
if (cudaGetDevice(&dev) != cudaSuccess || dev < 0 || dev >= 64) return false;
if (!per_dev[dev]) {
cudaDeviceProp p;
per_dev[dev] = cudaGetDeviceProperties(&p, dev) == cudaSuccess && strata::kernels::gfx_arch_is_gfx12(p.gcnArchName) ? 2 : 1;
}
return per_dev[dev] == 2;
#else
return false;
#endif
}
bool one_token_self_commit() {
#if defined(STRATA_USE_HIP)
static const bool on = [] {
@@ -1001,6 +1026,10 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
(int) (l * kProfPer + (half == 0 ? 27 : 30)));
};
const bool q8_attn = gr_read_group(0, pending, inj2_, inj_); // true: xq_ holds mixed's q8_1 (STRATA_QFUSE)
{ // measurement only: STRATA_DUMMY_NODES=k adds k empty kernel nodes per layer (what one node costs in a window)
static const int dummy = [] { const char* e = std::getenv("STRATA_DUMMY_NODES"); return e != nullptr ? std::atoi(e) : 0; }();
for (int d = 0; d < dummy; ++d) gpu_noop(cs);
}
if (inputs_pending) { // the window's steps and positions, before the first mixer reads them
join(1);
inputs_pending = false;
@@ -1331,6 +1360,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
}
stamp(l, 16, grp);
const bool q8_ffn = gr_read_group(1, true, inj_, inj2_); // true: nat_xq_ holds the MoE input's q8_1 (STRATA_QFUSE)
stamp(l, 32, grp); // the profile only: the FFN-side read ends here, the router starts
// with CPU experts in the window the shared expert forks off once the doorbell is published (it no longer
// competes with it for the GPU's first microseconds); STRATA_SH_FORK_LATE=0 forks at the top as before
static const bool sh_fork_late_env = [] {
@@ -1511,8 +1541,12 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
wait_flag_ge_or(m_flagA_, ring, skip_ + grp, cs);
copy_i32_from_mapped_unless(pl, m_plan_ + (size_t) grp * (size_t) plan_i32_, plan_i32_, skip_ + grp, ring, cs);
} else {
if (fuse_wait_on() && !prof_on_) { // 143-amdk: one launch for the wait and the copy
wait_copy_i32_from_mapped(m_flagA_, ring, pl, m_plan_ + (size_t) grp * (size_t) plan_i32_, plan_i32_, cs);
} else {
wait_flag_ge(m_flagA_, ring, cs); // the pool published this group's GPU plan
copy_i32_from_mapped(pl, m_plan_ + (size_t) grp * (size_t) plan_i32_, plan_i32_, cs);
}
}
stamp(l, 19, grp);
grouped(p_ptr, p_start, p_counts, 0, hit_out);
@@ -1535,10 +1569,14 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
copy_or_zero_from_mapped(parts_out, m_ymiss_ + (size_t) tb * K * N, (long long) n * K * N,
skip_ + grp, ring, cs);
} else {
wait_flag_ge(m_flag_, ring, cs); // the CPU's share is in the mapped rows
const bool fuse_rows = fuse_wait_on() && !prof_on_ && !remote_opt_ && dec_batch; // 143-amdk
if (!fuse_rows) wait_flag_ge(m_flag_, ring, cs); // the CPU's share is in the mapped rows
stamp(l, 23, grp);
if (remote_opt_) // #578: the helper's rows come back reduced; skip them as well
remote_opt_->copy_rows(parts_out, m_ymiss_ + (size_t) tb * K * N, tb, n, p_dst, p_counts + 1, cs);
else if (fuse_rows) // the wait folded into the copy's blocks
copy_rows_from_mapped_after(m_flag_, ring, parts_out, m_ymiss_ + (size_t) tb * K * N, (int64_t) n * K, N,
p_dst, p_counts + 1, cs);
else if (dec_batch) // only the CPU rows cross PCIe (p_dst[0, counts[1]) = the GPU's own rows)
copy_rows_from_mapped(parts_out, m_ymiss_ + (size_t) tb * K * N, (int64_t) n * K, N,
p_dst, p_counts + 1, cs);
@@ -1697,9 +1735,9 @@ std::string Verifier::profile_report() {
if (!prof_on_ || prof_windows_ == 0) return std::string();
static const char* names[kProfPer] = {"-", "hc-read0", "q8+qkv/q-idx gemv", "conv", "ab", "z", "rec", "q8+kv-idx",
"k/v+norm-rope", "kv+idx append", "q+q-idx", "scores+topk", "kv-resolve",
"attention", "gate", "", "out-proj", "hc-read1+router", "shared+quant",
"attention", "gate", "", "out-proj", "router+plan+bell", "shared+quant",
"waitA", "VRAM hits", "waitB", "PCIe grp", "waitCPU", "copy+combine",
"(gap)", "head", " hc0 norm", " hc0 down", " hc0 up", "", "", ""};
"(gap)", "head", " hc0 norm", " hc0 down", " hc0 up", " hc1 norm", " hc1 down", " hc1 up"};
std::string out;
char b[80];
double total = 0;
@@ -1765,6 +1803,38 @@ bool Verifier::capture(int T, std::string& err) {
err = std::string("verify: end capture: ") + cudaGetErrorString(ce);
return false;
}
#if defined(STRATA_USE_HIP) // 143-amdk: the same listing on HIP (kernel names by hipKernelNameRefByPtr); STRATA_VERIFY_NODES=2 also lists the first nodes in graph order
if (std::getenv("STRATA_VERIFY_NODES") != nullptr) {
size_t nn = 0;
hipGraphGetNodes(graph, nullptr, &nn);
std::vector<hipGraphNode_t> nodes(nn);
hipGraphGetNodes(graph, nodes.data(), &nn);
std::map<std::string, int> kinds;
std::string seq;
size_t shown = 0;
for (hipGraphNode_t nd : nodes) {
hipGraphNodeType ty;
hipGraphNodeGetType(nd, &ty);
std::string name = "type" + std::to_string((int) ty);
if (ty == hipGraphNodeTypeKernel) {
hipKernelNodeParams kp{};
if (hipGraphKernelNodeGetParams(nd, &kp) == hipSuccess && kp.func != nullptr) {
const char* fn = hipKernelNameRefByPtr(kp.func, nullptr);
if (fn != nullptr) name = fn;
}
} else if (ty == hipGraphNodeTypeMemcpy) name = "memcpy";
else if (ty == hipGraphNodeTypeMemset) name = "memset";
++kinds[name];
if (std::atoi(std::getenv("STRATA_VERIFY_NODES")) >= 2 && shown++ < 400) seq += "\n " + name.substr(0, 110);
}
std::vector<std::pair<int, std::string>> v;
for (auto& [k2, c] : kinds) v.push_back({c, k2});
std::sort(v.rbegin(), v.rend());
std::fprintf(stderr, "strata verify: the %d-token window graph has %zu nodes:", T, nn);
for (size_t i = 0; i < v.size() && i < 80; ++i) std::fprintf(stderr, "\n %4d x %.110s", v[i].first, v[i].second.c_str());
std::fprintf(stderr, "\n%s\n", seq.c_str());
}
#endif
#if !defined(STRATA_USE_HIP) // a CUDA debug listing (node types, kernel names)
if (std::getenv("STRATA_VERIFY_NODES") != nullptr) { // what the window graph holds
size_t nn = 0;
@@ -1956,6 +2026,15 @@ void Verifier::accumulate_profile(const unsigned long long* stamps) {
prof_sum_[kind][i] += (double) (x - prev);
prev = x;
}
{ // the FFN-side read split like hc-read0: norm 30, down 31, up 32; what is left of 17 is the router, plan, doorbell
const double n1 = gap(at(l, 30), at(l, 16)), d1 = gap(at(l, 31), at(l, 30)), u1 = gap(at(l, 32), at(l, 31));
if (n1 > 0 && d1 > 0 && u1 > 0) {
prof_sum_[kind][30] += n1;
prof_sum_[kind][31] += d1;
prof_sum_[kind][32] += u1;
prof_sum_[kind][17] -= gap(at(l, 32), at(l, 16));
}
}
if (l + 1 < le_) prof_sum_[kind][25] += gap(at(l + 1, 0), at(l, 24));
const double dn = gap(at(l, 27), at(l, 0)), dd = gap(at(l, 28), at(l, 27)), du = gap(at(l, 1), at(l, 28));
if (dn > 0 && dd > 0 && du > 0) { // the split exists: show it split, not twice