| 4334 | } |
| 4335 | |
| 4336 | bool Verifier::prelaunch(int T, const int32_t* tokens, int64_t pos0, std::string& err) { |
| 4337 | const OnDevice on_device(device_); |
| 4338 | prelaunched_ = 0; |
| 4339 | sel_long_ = select_long_on() && pos0 + T >= select_long_at() ? 1 : 0; // the variant the previous stage captured |
| 4340 | cudaGraphExec_t exec_t = ar_off_ ? exec_nr_[sel_long_][T] : exec_[sel_long_][T]; // #871: the variant the previous stage refreshed |
| 4341 | if (T < 1 || T > max_t_ || exec_t == nullptr) { err = "verify: prelaunch before the window was captured"; return false; } |
| 4342 | if (released_.load()) { err = "verify: an earlier window never finished on the GPU (#267); restart the engine"; return false; } |
| 4343 | if (pos0 + T > ss_->qsa_states[ss_->qsa_primary()].max_cells) { err = "verify: the window runs past the context"; return false; } |
| 4344 | const Clock::time_point t0 = Clock::now(); |
| 4345 | stage_inputs(T, tokens, pos0); |
| 4346 | if (trace_h_ != nullptr) std::memset(trace_h_, 0, trace_n_ * 8); |
| 4347 | std::atomic_thread_fence(std::memory_order_seq_cst); |
| 4348 | trace_ev("WINDOW-PRE", -1, -1, pos0 * 16 + T); |
| 4349 | ms_host += ms_since(t0); |
| 4350 | if (h_bal_ != nullptr) std::memset(h_bal_, 0, (size_t) bal_p_.size() * 4 * 8); // this window's stamps only |
| 4351 | if (ar_on() && h_plan_err_ != nullptr) *(volatile uint32_t*) h_plan_err_ = 0; |
| 4352 | // 0.1.43: the same gate run() applies before it launches (the adaptive tier's copies land first) |
| 4353 | if (adapt_gate_ != nullptr && adapt_gate_->active.load(std::memory_order_acquire) && ar_on() && |
| 4354 | !adapt_gate_wait((int32_t) g_->n_layers, err)) return false; |
| 4355 | strata::dispatch::Stats::get().graph_launch(T, ar_on() ? 0 : 1); |
| 4356 | const cudaError_t le = cudaGraphLaunch(exec_t, cs_); |
| 4357 | trace_ev("LAUNCHED", -1, -1, (int64_t) le); |
| 4358 | if (le != cudaSuccess) { err = std::string("verify: launch: ") + cudaGetErrorString(le); return false; } |
| 4359 | (void) cudaStreamQuery(cs_); |
| 4360 | prelaunched_ = T; |
| 4361 | return true; |
| 4362 | } |
| 4363 | |
| 4364 | #if defined(STRATA_GPU_METAL) |
| 4365 | // #879's device row check on the Metal port: CUDA scans every head window's logits rows in the graph |
no test coverage detected