Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion npu/target/xdna/xdna_target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,21 @@ int64_t XdnaTarget::m16_check_gemm_rows(I8Ctx& ref, I8Ctx& fast, const float* A,

void XdnaTarget::prof_add(ProfAcc* acc, int design, double pack, double quant,
double wait, double rb) {
if (q4nx_lh::phprof_on() && acc == prof_dec_ && !q4nx_lh::g_in_head) {
// g_ph is what the [bs] (batch) and [ph] (decode step) lines print, and both read it. Only the DECODE
// accumulator used to be counted, so a 219-row prefill -- which launches through prof_pre_ -- reported
// "n=0 launches, host=93113 ms" for 224 launches and 93 s of device wait: the wait fell into the line's
// host= residual and the launch count stayed zero, which reads exactly like a host fallback and sent one
// lane (engine #1582) looking for a fallback that does not exist. The batched body sets g_in_batch for
// its whole duration, so accepting prof_pre_ there counts those launches and keeps a decode-only
// measurement decode-only.
// The head is NEVER counted here, and that is the second half of this gate. `g_in_batch` stays set for the whole of
// step_batch, and the batched head (run_lm_head_rows -> note_head -> prof_add(&prof_head_, ...)) runs inside that
// window without setting g_in_head -- which only the single-row head does. So accepting "any accumulator while in a
// batch" put the head's device time into g_ph as well, where [bs] computes host = layers - gsum: the same time was
// then reported twice, once in gsum and once on the epilogue line's own h_* slices, and host was understated by it
// (it can go negative) on exactly the multi-row passes this line exists for. The head keeps its own accounting.
if (q4nx_lh::phprof_on() && acc != &prof_head_ &&
(acc == prof_dec_ || (q4nx_lh::g_in_batch && acc == prof_pre_)) && !q4nx_lh::g_in_head) {
q4nx_lh::g_ph.g_pack += pack; q4nx_lh::g_ph.g_ql += quant;
q4nx_lh::g_ph.g_wait += wait; q4nx_lh::g_ph.g_rb += rb;
q4nx_lh::g_ph.launches++;
Expand Down
Loading