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

Method batch_poll

engine/src/core/verify.cpp:6482–6550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6480}
6481
6482int Verifier::batch_poll(PoolMultiFn pool, void* user, std::string& err) {
6483 if (!b_running_) return 1;
6484 // set_external_serve: another thread serves the doorbells (batch_serve) and this one only checks for a window that
6485 // will not finish, as below: its graph ended (or failed) with a layer still to ring, or no layer rang for 20 s.
6486 // The stream query can wait for the driver's lock while a read's call holds it; the doorbells go on meanwhile.
6487 // The served count is read before the query and the ring count after it: a layer served in between rang first.
6488 if (ext_serve_.load(std::memory_order_acquire) && !ar_on()) {
6489 const int64_t k = b_k_.load(std::memory_order_acquire);
6490 if (k < b_steps_) {
6491 const auto now = Clock::now();
6492 if (now - last_ring() <= std::chrono::milliseconds(2) || now - ext_checked_ < std::chrono::milliseconds(1))
6493 return 0;
6494 ext_checked_ = now; // (at most one query a millisecond: pump calls this in a loop)
6495 const OnDevice on_device(device_);
6496 const cudaError_t q = cudaStreamQuery(cs_);
6497 if (q != cudaErrorNotReady && *(volatile uint32_t*) h_seq_ < (uint32_t) (k + 1)) {
6498 err = "verify batch: layer " + std::to_string(lb_ + k) + " never rang (" +
6499 (q == cudaSuccess ? std::string("graph finished") : std::string(cudaGetErrorString(q))) + ")";
6500 b_running_ = false;
6501 return -1;
6502 }
6503 if (now - last_ring() > std::chrono::seconds(20)) {
6504 err = "verify batch: timed out at layer " + std::to_string(lb_ + k) +
6505 released_note(release_gpu_waits(5000));
6506 b_running_ = false;
6507 return -1;
6508 }
6509 return 0;
6510 }
6511 }
6512 const OnDevice on_device(device_);
6513 const int S = last_t_;
6514 // the layers that have rung so far (batch_serve); with one still to ring: did the graph finish without it, or
6515 // has it waited too long?
6516 if (!batch_serve(pool, user)) {
6517 const auto now = Clock::now();
6518 if (now - last_ring() > std::chrono::milliseconds(2)) {
6519 const cudaError_t q = cudaStreamQuery(cs_);
6520 if (q != cudaErrorNotReady && *(volatile uint32_t*) h_seq_ < (uint32_t) (b_k_ + 1)) {
6521 err = "verify batch: layer " + std::to_string(lb_ + b_k_) + " never rang (" +
6522 (q == cudaSuccess ? std::string("graph finished") : std::string(cudaGetErrorString(q))) + ")";
6523 b_running_ = false;
6524 return -1;
6525 }
6526 if (now - last_ring() > std::chrono::seconds(20)) {
6527 err = "verify batch: timed out at layer " + std::to_string(lb_ + b_k_) +
6528 released_note(release_gpu_waits(5000));
6529 b_running_ = false;
6530 return -1;
6531 }
6532 }
6533 return 0;
6534 }
6535 const cudaError_t q = cudaStreamQuery(cs_);
6536 if (q == cudaErrorNotReady) return 0;
6537 if (q != cudaSuccess) { err = std::string("verify batch: ") + cudaGetErrorString(q); b_running_ = false; return -1; }
6538 const cudaError_t qc = cudaStreamQuery(copy_); // no host function of this window may raise flag B in the next
6539 if (qc == cudaErrorNotReady) return 0;

Callers

nothing calls this directly

Calls 10

cudaStreamQueryFunction · 0.85
secondsFunction · 0.85
release_gpu_waitsFunction · 0.85
progress_beatFunction · 0.85
released_noteFunction · 0.70
nowFunction · 0.50
to_stringFunction · 0.50
stringFunction · 0.50
cudaGetErrorStringFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected