Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
CUDA: service CPU doorbells while instrumented graph launches block
Davidd8684360b82e
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 49a45ee18..3b78cc269 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -483,6 +483,13 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)src/core/arch_defaults.cpp src/core/vmm.cpp src/core/conversation_file.cpp)target_include_directories(strata_engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)target_link_libraries(strata_engine PUBLIC strata_core strata_kernels strata_kernels_cpu ${_strata_gpu_runtime_target})+ if(STRATA_BUILD_TESTS AND STRATA_ENABLE_CUDA AND NOT STRATA_HIP_GFX906)+ add_executable(host_graph_launch_test tests/core/host_graph_launch_test.cu)+ target_include_directories(host_graph_launch_test PRIVATE include)+ target_link_libraries(host_graph_launch_test PRIVATE CUDA::cudart Threads::Threads)+ add_test(NAME host_graph_launch_test COMMAND host_graph_launch_test)+ set_tests_properties(host_graph_launch_test PROPERTIES TIMEOUT 30)+ endif()if(STRATA_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/exchange_storage_test.cpp")add_executable(exchange_storage_test tests/core/exchange_storage_test.cpp)target_include_directories(exchange_storage_test PRIVATE include)diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex d703d9c06..12f70e17f 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -2011,3 +2011,20 @@ The prompt path's half-output buffer `bo` reuses the embedding buffer `emb`, whi**Fused int8 prompt experts on gfx12 (RDNA4, R9700): on by default for IQ3_S and IQ3_XXS packs.** `STRATA_PF_FUSED=0` turns them off (back to the MMQ prompt kernels, the previous bits). R9700, 1 card: prompt 4K +15.7%, 16K +13..+17%, 32K +19..+20%, a 96K prompt +16% (answers identical text); first-token KL against the FP16 prompt path over 96 prompts is equal to MMQ within noise (IQ3_XXS 0.00613 against 0.00683, IQ3_S 0.00416 against 0.00372). Other quants and other GPUs are unchanged; `STRATA_PF_FUSED=1` still opts in every covered format.**gfx12 (Linux): a bare `--prefill auto` may take 16384-token chunks.** Explicit `--prefill N`, `auto:N` and `STRATA_PREFILL_AUTO_MAX` are untouched; `STRATA_GFX12_CHUNK=0` or `STRATA_GFX12_DEFAULTS=0` keeps 8192.++### CUDA diagnostics: a host thread for the verify-window launch++`STRATA_VERIFY_ASYNC_LAUNCH=1` runs `Verifier::run`'s CUDA graph launch on a separate+host thread. This lets its caller serve the CPU expert doorbells while an+instrumented `cudaGraphLaunch` blocks waiting for the graph. The caller joins the+launch and checks its real error before returning a frontier; an early service+failure releases the mapped GPU waits before joining. The switch is off by+default and applies to this single-request verifier entry point. Direct batch+and pipelined graph launches and the HIP/SYCL paths retain their existing scheduling.++For Compute Sanitizer, set this variable before running the usual model command+under `compute-sanitizer --tool memcheck --error-exitcode 86`. Build with+`STRATA_BUILD_TESTS=ON` and run `host_graph_launch_test` for the CUDA graph/CPU+signal, early cleanup and `--errors` error-propagation checks. Its `--synchronous`+mode is the negative control under memcheck: an eight-second watchdog releases+the original launch/service deadlock and the test fails.diff --git a/include/strata/core/host_graph_launch.hpp b/include/strata/core/host_graph_launch.hppnew file mode 100644index 000000000..2993997a6--- /dev/null+++ b/include/strata/core/host_graph_launch.hpp@@ -0,0 +1,64 @@+#pragma once++#include <cuda_runtime.h>+#include <atomic>+#include <functional>+#include <thread>+#include <utility>++namespace strata::core {++// Instrumented cudaGraphLaunch may block until device work completes. A graph+// which waits for CPU doorbells must therefore launch outside its service thread.+// The caller still services exactly the same graph and observes the real launch+// error before synchronizing or publishing its output.+class HostGraphLaunch {+public:+ HostGraphLaunch(cudaGraphExec_t graph, cudaStream_t stream, int device,+ bool threaded, std::function<void()> release_waits)+ : stream_(stream), release_waits_(std::move(release_waits)) {+ if (threaded) {+ pending_.store(true);+ worker_ = std::thread([this, graph, device] {+ auto error = cudaSetDevice(device);+ if (error == cudaSuccess) error = cudaGraphLaunch(graph, stream_);+ error_ = error;+ pending_.store(false, std::memory_order_release);+ });+ } else {+ error_ = cudaGraphLaunch(graph, stream_);+ }+ }+ HostGraphLaunch(const HostGraphLaunch&) = delete;+ HostGraphLaunch& operator=(const HostGraphLaunch&) = delete;++ ~HostGraphLaunch() {+ // On an early service failure, release the GPU's mapped waits before+ // joining a launcher that may be blocked behind those waits.+ if (worker_.joinable() && !finished_) release_waits_();+ if (worker_.joinable()) worker_.join();+ }++ bool pending() const { return pending_.load(std::memory_order_acquire); }+ cudaError_t status() const { return pending() ? cudaSuccess : error_; }+ cudaError_t query() const {+ if (pending()) return cudaErrorNotReady;+ if (error_ != cudaSuccess) return error_;+ return cudaStreamQuery(stream_);+ }+ cudaError_t finish() {+ if (worker_.joinable()) worker_.join();+ finished_ = true;+ return error_;+ }++private:+ cudaStream_t stream_;+ std::function<void()> release_waits_;+ std::atomic<bool> pending_{false};+ cudaError_t error_ = cudaSuccess;+ std::thread worker_;+ bool finished_ = false;+};++} // namespace strata::corediff --git a/src/core/verify.cpp b/src/core/verify.cppindex 0513a8240..66de8cc84 100644--- a/src/core/verify.cpp+++ b/src/core/verify.cpp@@ -2,6 +2,9 @@#include "strata/core/batch_rows.hpp"#include "strata/kernels/gfx_arch.hpp"#include "strata/core/verify.hpp"+#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)+#include "strata/core/host_graph_launch.hpp"+#endif#include "strata/core/remote_expert_opt.hpp"#include "strata/core/dma_batch.hpp"#include "strata/core/spec_prob.hpp"@@ -2172,10 +2175,25 @@ bool Verifier::run(int T, const int32_t* tokens, int64_t pos0, PoolMultiFn pool,// 0.1.43: with the all-resident graph the host serves no layer, so nothing can hold a layer back: every copy firstif (adapt_gate_ != nullptr && adapt_gate_->active.load(std::memory_order_acquire) && ar_on() &&!adapt_gate_wait((int32_t) g.n_layers, err)) return false;+#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)+ // A blocking instrumented launch cannot also serve the graph's CPU doorbells.+ static const bool threaded_launch = [] {+ const char* value = std::getenv("STRATA_VERIFY_ASYNC_LAUNCH");+ return value != nullptr && value[0] == '1';+ }();+ HostGraphLaunch launch(ar_off_ ? exec_nr_[T] : exec_[T], cs_, device_, threaded_launch,+ [this] { (void) release_gpu_waits(5000); });+ const cudaError_t le = launch.status();+#elseconst cudaError_t le = cudaGraphLaunch(ar_off_ ? exec_nr_[T] : exec_[T], cs_);+#endiftrace_ev("LAUNCHED", -1, -1, (int64_t) le);if (le != cudaSuccess) { err = std::string("verify: launch: ") + cudaGetErrorString(le); return false; }+#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)+ (void) launch.query();+#else(void) cudaStreamQuery(cs_);+#endifVDBG("launched\n");volatile uint32_t* const seq = h_seq_;volatile uint32_t* const flag = h_flag_;@@ -2209,7 +2227,11 @@ bool Verifier::run(int T, const int32_t* tokens, int64_t pos0, PoolMultiFn pool,const auto now = Clock::now();if (now - last_flush > std::chrono::microseconds(2000)) {last_flush = now;+#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)+ const cudaError_t q = launch.query();+#elseconst cudaError_t q = cudaStreamQuery(cs_);+#endifif (q != cudaErrorNotReady && *seq < want) {trace_ev("NEVER-RANG", k, l, (int64_t) q);trace_dump(stderr);@@ -2220,7 +2242,11 @@ bool Verifier::run(int T, const int32_t* tokens, int64_t pos0, PoolMultiFn pool,}if (now - a > std::chrono::seconds(20)) {// #267: the caller ends the engine; no spin kernel may outlive it+#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)+ trace_ev("TIMEOUT", k, l, (int64_t) launch.query());+#elsetrace_ev("TIMEOUT", k, l, (int64_t) cudaStreamQuery(cs_));+#endifif (g_trace) {diag(stderr); // the words and the breadcrumbs before the release ...const bool drained = release_gpu_waits(5000);@@ -2285,6 +2311,13 @@ bool Verifier::run(int T, const int32_t* tokens, int64_t pos0, PoolMultiFn pool,// spin kernel outlives the process - the case that left Windows GPUs "lost" until a power cycle. The wait// itself stays a blocking sync: a cudaStreamQuery poll here cost IQ3_S ~3% decode (a core calling the driver// beside the expert workers).+#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)+ const cudaError_t launch_result = launch.finish();+ if (launch_result != cudaSuccess) {+ err = std::string("verify: launch: ") + cudaGetErrorString(launch_result);+ return false;+ }+#endiftrace_ev("SYNC", -1, -1, 0);const cudaError_t se = cudaStreamSynchronize(cs_);trace_ev("SYNCED", -1, -1, (int64_t) se);diff --git a/tests/core/host_graph_launch_test.cu b/tests/core/host_graph_launch_test.cunew file mode 100644index 000000000..39a79e8f6--- /dev/null+++ b/tests/core/host_graph_launch_test.cu@@ -0,0 +1,82 @@+#include "strata/core/host_graph_launch.hpp"+#include <chrono>+#include <cstdio>+#include <cstdlib>+#include <cstring>+#include <atomic>+#include <thread>++static void check(bool ok, const char* what) {+ if (!ok) { std::fprintf(stderr, "FAIL: %s\n", what); std::exit(1); }+}+static void gpu(cudaError_t e) { check(e == cudaSuccess, cudaGetErrorString(e)); }+__global__ void wait_for_cpu(volatile unsigned* flag) {+ while (*flag == 0) { }+}+__global__ void tick(unsigned* value) { ++*value; }++int main(int argc, char** argv) {+ const bool threaded = !(argc > 1 && std::strcmp(argv[1], "--synchronous") == 0);+ cudaStream_t stream;+ gpu(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));+ unsigned *host, *flag, *value;+ gpu(cudaHostAlloc(&host, sizeof(unsigned), cudaHostAllocMapped));+ gpu(cudaHostGetDevicePointer(&flag, host, 0));+ gpu(cudaMalloc(&value, sizeof(unsigned)));+ gpu(cudaMemset(value, 0, sizeof(unsigned)));+ *host = 0;+ cudaGraph_t graph;+ cudaGraphExec_t exec;+ gpu(cudaStreamBeginCapture(stream, cudaStreamCaptureModeGlobal));+ wait_for_cpu<<<1, 1, 0, stream>>>(flag);+ // Enough nodes to exercise launch backpressure under Compute Sanitizer.+ for (int i = 0; i < 4096; ++i) tick<<<1, 1, 0, stream>>>(value);+ gpu(cudaStreamEndCapture(stream, &graph));+ gpu(cudaGraphInstantiate(&exec, graph, nullptr, nullptr, 0));+ std::atomic<bool> done{false}, timed_out{false};+ std::thread watchdog([&] {+ const auto start = std::chrono::steady_clock::now();+ while (!done && std::chrono::steady_clock::now() - start < std::chrono::seconds(8))+ std::this_thread::sleep_for(std::chrono::milliseconds(10));+ if (!done) { timed_out = true; *(volatile unsigned*)host = 1; }+ });+ {+ strata::core::HostGraphLaunch launch(exec, stream, 0, threaded,+ [&] { *(volatile unsigned*)host = 1; });+ gpu(launch.status());+ check(launch.query() == cudaErrorNotReady, "graph waits for CPU service");+ *(volatile unsigned*)host = 1;+ gpu(launch.finish());+ gpu(cudaStreamSynchronize(stream));+ }+ done = true;+ watchdog.join();+ check(!timed_out, "CPU service proceeds without launch deadlock");+ unsigned count = 0;+ gpu(cudaMemcpy(&count, value, sizeof(unsigned), cudaMemcpyDeviceToHost));+ check(count == 4096, "all graph nodes executed");+ if (threaded) {+ // An early service failure must release the graph before joining.+ *host = 0;+ std::atomic<bool> released{false};+ {+ strata::core::HostGraphLaunch launch(exec, stream, 0, true,+ [&] { released = true; *(volatile unsigned*)host = 1; });+ }+ check(released, "early return releases device waits");+ gpu(cudaStreamSynchronize(stream));+ gpu(cudaMemcpy(&count, value, sizeof(unsigned), cudaMemcpyDeviceToHost));+ check(count == 8192, "early return drains the actual graph");+ if (argc > 1 && std::strcmp(argv[1], "--errors") == 0) {+ strata::core::HostGraphLaunch invalid(exec, stream, -1, true, [] {});+ check(invalid.finish() == cudaErrorInvalidDevice, "launch-thread device error propagated");+ (void)cudaGetLastError();+ }+ }+ gpu(cudaGraphExecDestroy(exec));+ gpu(cudaGraphDestroy(graph));+ gpu(cudaFree(value));+ gpu(cudaFreeHost(host));+ gpu(cudaStreamDestroy(stream));+ std::puts("PASS: graph launch, CPU doorbell service and cleanup");+}