MCPcopy Create free account
hub / github.com/Niko1221/Strata / commit

Method commit

engine/src/core/verify.cpp:5249–5314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5247void Verifier::set_commit_async(bool on) { g_commit_async = on && std::getenv("STRATA_COMMIT_SYNC") == nullptr; }
5248
5249bool Verifier::commit(int n_keep, std::string& err) {
5250#if defined(STRATA_GPU_METAL)
5251 return strata::metal_engine::window_commit(metal_, n_keep, err);
5252#endif
5253 const OnDevice on_device(device_);
5254 if (n_keep < 1 || n_keep > last_t_) { err = "verify: commit count out of range"; return false; }
5255 const Clock::time_point t0 = Clock::now();
5256 h_commit_[0] = n_keep;
5257 h_commit_[1] = n_keep - 1;
5258 for (int t = 0; t < max_t_; ++t) h_commit_[2 + t] = t < n_keep ? (int32_t) (last_pos0_ + t) : -1;
5259 if (last_t_ == 1 && !always_publish_ && one_token_self_commit() && !STRATA_QFUSE_BLOCKS_SELF_COMMIT()) {
5260 // a one-token window has advanced the state itself (record_window): no commit graph. (Not with STRATA_QFUSE: its windows
5261 // do not self-commit, see `self_commit` there - skipping the commit here left the GDN state and the indexer tail one token behind.)
5262 } else {
5263 std::atomic_thread_fence(std::memory_order_seq_cst);
5264 // STRATA_COMMIT_TIMING=1 (measurement only): the commit graph's GPU time, from an event pair around it (read at the
5265 // next commit, when the pair has long completed); printed every 300 commits
5266 static struct CommitTiming {
5267 bool on = false, pending = false;
5268 cudaEvent_t b = nullptr, e = nullptr;
5269 double ms = 0;
5270 int64_t n = 0;
5271 CommitTiming() { const char* v = std::getenv("STRATA_COMMIT_TIMING"); on = v != nullptr && v[0] == '1'; }
5272 } ct;
5273 if (ct.on && ct.b == nullptr &&
5274 (cudaEventCreate(&ct.b) != cudaSuccess || cudaEventCreate(&ct.e) != cudaSuccess)) { ct.on = false; (void) cudaGetLastError(); }
5275 if (ct.on && ct.pending) {
5276 float ms = 0;
5277 if (cudaEventSynchronize(ct.e) == cudaSuccess && cudaEventElapsedTime(&ms, ct.b, ct.e) == cudaSuccess) { ct.ms += ms; ++ct.n; }
5278 ct.pending = false;
5279 if (ct.n > 0 && ct.n % 300 == 0)
5280 std::fprintf(stderr, "strata verify: commit graph %.3f ms GPU on average over %lld commits\n", ct.ms / (double) ct.n,
5281 (long long) ct.n);
5282 }
5283 if (ct.on) cudaEventRecord(ct.b, cs_);
5284 const cudaError_t le = cudaGraphLaunch(commit_exec_, cs_);
5285 if (ct.on) { cudaEventRecord(ct.e, cs_); ct.pending = true; }
5286 if (le != cudaSuccess) { err = std::string("verify: commit launch: ") + cudaGetErrorString(le); return false; }
5287 // set_commit_async: no wait here - the next window runs on the same stream after it, and the drafter (its own
5288 // stream) reads only this window's final rows and its own K/V. h_commit_ is next written after the next window's
5289 // results are read, i.e. after this graph has run. Everything else waits on commit_done_ (wait_commit).
5290 if (!g_commit_async || next_ != nullptr) {
5291 const cudaError_t se = cudaStreamSynchronize(cs_);
5292 if (se != cudaSuccess) { err = std::string("verify: commit: ") + cudaGetErrorString(se); return false; }
5293 } else {
5294 const cudaError_t re = cudaEventRecord(commit_done_, cs_);
5295 if (re != cudaSuccess) { err = std::string("verify: commit event: ") + cudaGetErrorString(re); return false; }
5296 (void) cudaStreamQuery(cs_);
5297 commit_pending_ = true;
5298 }
5299 }
5300 if (ple_stage()) // stages that share one session must advance it once
5301 for (int t = 0; t < n_keep; ++t) {
5302 ss_->ple_prev[0] = ss_->ple_prev[1];
5303 ss_->ple_prev[1] = last_tokens_[t];
5304 }
5305#ifdef STRATA_WITH_LOOP
5306 if (h_cd_omega_ != nullptr) {

Callers 7

commit_exchangesMethod · 0.45
commit_flipMethod · 0.45
lab_checkFunction · 0.45
fnx_run_cmdFunction · 0.45
generateMethod · 0.45
exerciseFunction · 0.45
exercise_sizedFunction · 0.45

Calls 15

window_commitFunction · 0.85
cudaStreamQueryFunction · 0.85
loop_think_state_afterFunction · 0.85
one_token_self_commitFunction · 0.70
ms_sinceFunction · 0.70
nowFunction · 0.50
cudaEventCreateFunction · 0.50
cudaGetLastErrorFunction · 0.50
cudaEventSynchronizeFunction · 0.50
cudaEventElapsedTimeFunction · 0.50
cudaEventRecordFunction · 0.50
cudaGraphLaunchFunction · 0.50

Tested by 2

exerciseFunction · 0.36
exercise_sizedFunction · 0.36