| 169 | #endif |
| 170 | |
| 171 | void session_zero(SessionState& s, const ModelGeometry& g, const float* R_init, void* stream) { |
| 172 | #if defined(STRATA_GPU_METAL) |
| 173 | // the running state lives in the Metal decode window; the session's own device buffers are not read there |
| 174 | (void) g; (void) R_init; (void) stream; |
| 175 | strata::metal_engine::window_reset(&s); |
| 176 | s.ple_prev[0] = -1; |
| 177 | s.ple_prev[1] = -1; |
| 178 | s.ple_token = -1; |
| 179 | return; |
| 180 | #endif |
| 181 | cudaStream_t cs = (cudaStream_t) stream; |
| 182 | // the residual: `hc` copies of the one vector a caller hands in. A real sequence's first token is the |
| 183 | // embedding broadcast to every stream, which is the reference's own initial condition. |
| 184 | if (R_init != nullptr) { |
| 185 | for (int64_t c = 0; c < g.hc; ++c) |
| 186 | cudaMemcpyAsync(s.block.R + (size_t) c * g.n_embd, R_init, (size_t) g.n_embd * 4, |
| 187 | cudaMemcpyDeviceToDevice, cs); |
| 188 | } else { |
| 189 | cudaMemsetAsync(s.block.R, 0, (size_t) g.hc * g.n_embd * 4, cs); |
| 190 | } |
| 191 | // every owned GDN layer's recurrence and conv history |
| 192 | cudaMemsetAsync(s.gdn_state, 0, (size_t) s.gdn_alloc * gdn_state_floats(g) * 4, cs); |
| 193 | // and every owned QSA layer's cache and indexer |
| 194 | for (int64_t j = 0; j < s.qsa_alloc; ++j) qsa_state_zero(s.qsa_states[s.qsa_ord0 + j], g, stream); |
| 195 | // **AND THE PLE'S CONV HISTORY AND TOKEN WINDOW.** A sequence that started with a warm history would |
| 196 | // convolve over rows belonging to a different sequence - the conv reads NG_HIST previous NORMALIZED rows, |
| 197 | // so a stale one is a real contribution and not a zero. The token window resets to `NG_HIST`-many nulls |
| 198 | // for the same reason: `ngram_rows` treats a missing predecessor as the EOS cut, which is what a sequence |
| 199 | // boundary IS. |
| 200 | cudaMemsetAsync(s.ple_hist, 0, (size_t) ple_hist_bytes(), cs); |
| 201 | s.ple_prev[0] = -1; |
| 202 | s.ple_prev[1] = -1; |
| 203 | s.ple_token = -1; |
| 204 | } |
| 205 | |
| 206 | /// Sets `s.gdn.state`/`conv_state` for `layer`, which is what makes one layer's GDN state its own. Shared by |
| 207 | /// the direct and captured paths so the two cannot disagree about which slice a layer owns. |
nothing calls this directly
no test coverage detected