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

Method wait_ms

engine/src/core/graph.cpp:84–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84bool CapturedGraph::wait_ms(int timeout_ms) const {
85 if (!done_) return false;
86 // A BOUNDED wait, and the bound is the point: an unbounded spin turns a protocol bug into a hung run, and
87 // a hung run says nothing about which side is stuck. `cudaEventQuery` is a QUERY - it does not block and
88 // it does not synchronise - so this satisfies P2.X3 while still giving the driver the call it needs to
89 // flush the submission. See NOTE 1 in the header: without a driver call here the work never starts.
90 //
91 // The deadline is a REAL CLOCK, not a count of pause instructions: `_mm_pause` is a few cycles, so
92 // counting pauses as microseconds would make the timeout tens of times longer than the caller asked for -
93 // a timeout that does not time out is worse than none, because it reports a hang as a pass.
94 const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeout_ms);
95 for (;;) {
96 const cudaError_t q = cudaEventQuery(done_);
97 if (q == cudaSuccess) return true;
98 if (q != cudaErrorNotReady) return false; // a real error, not "not finished"
99 if (std::chrono::steady_clock::now() >= deadline) return false;
100 for (int i = 0; i < 64; ++i) strata_cpu_pause();
101 }
102}
103
104bool GraphRegistry::record(LayerType type, int n_tokens, const std::function<void()>& body, std::string& err) {
105 const Key k{(int) type, n_tokens};

Callers 1

launchMethod · 0.45

Calls 3

strata_cpu_pauseFunction · 0.85
nowFunction · 0.50
cudaEventQueryFunction · 0.50

Tested by

no test coverage detected