| 52 | } |
| 53 | |
| 54 | uint64_t session_bytes(const ModelGeometry& g, int64_t max_cells, int64_t k, int64_t layer_lo, int64_t layer_hi) { |
| 55 | if (layer_hi < 0 || layer_hi > g.n_layers) layer_hi = g.n_layers; |
| 56 | if (layer_lo < 0) layer_lo = 0; |
| 57 | // QSA layers are `l % interval == interval-1`, so exactly `bound / interval` of them live below `bound` |
| 58 | const int64_t I = std::max<int64_t>(g.qsa_interval, 1); |
| 59 | const int64_t q_lo = layer_lo / I, q_hi = layer_hi / I; |
| 60 | #ifdef STRATA_WITH_LOOP |
| 61 | const int64_t extra_q = strata::kernels::loop_extra_qsa_slots(layer_lo, layer_hi, I); |
| 62 | const int64_t extra_g = strata::kernels::loop_extra_gdn_slots(layer_lo, layer_hi, I); |
| 63 | const int64_t q_n = std::max<int64_t>(q_hi - q_lo, g.n_qsa_layers() > 0 ? 1 : 0) + extra_q; |
| 64 | const int64_t gdn_n = std::max<int64_t>((layer_hi - layer_lo) - std::max<int64_t>(q_hi - q_lo, 0), 0) + extra_g; |
| 65 | #else |
| 66 | const int64_t q_n = std::max<int64_t>(q_hi - q_lo, g.n_qsa_layers() > 0 ? 1 : 0); |
| 67 | const int64_t gdn_n = std::max<int64_t>((layer_hi - layer_lo) - std::max<int64_t>(q_hi - q_lo, 0), 0); |
| 68 | #endif |
| 69 | uint64_t n = 0; |
| 70 | n += gdn_buffers_bytes(g); |
| 71 | n += (uint64_t) gdn_n * gdn_state_floats(g) * 4; |
| 72 | // One QSA state carries the RoPE table; the others borrow it (P7: 64 MiB per layer at 262K). |
| 73 | if (g.n_qsa_layers() > 0) |
| 74 | n += qsa_state_bytes(g, max_cells, true) + (uint64_t) (q_n - 1) * qsa_state_bytes(g, max_cells, false); |
| 75 | n += qsa_buffers_bytes(g, max_cells); |
| 76 | n += moe_buffers_bytes(g, k); |
| 77 | n += block_buffers_bytes(g); |
| 78 | n += ple_hist_bytes(); // the PLE's NG_HIST normalized history rows |
| 79 | return align_up(n, SESSION_STATE_ALIGN) + 4096; |
| 80 | } |
| 81 | |
| 82 | uint64_t session_init(const ModelGeometry& g, int64_t max_cells, int64_t k, void* base, SessionState& s, |
| 83 | int64_t layer_lo, int64_t layer_hi) { |
no test coverage detected