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++
gemm (#240 follow-up): setup calls that failed before without a word are logged and survived as before (not fatal - hipBLAS can return not-supported), init_external names its failures too, the MiB stays in the scratch message; no unused resource_failure flag
Niko122164dcc59fae91
diff --git a/include/strata/prefill/gemm.hpp b/include/strata/prefill/gemm.hppindex f5fc71723..c9ddc6f4d 100644--- a/include/strata/prefill/gemm.hpp+++ b/include/strata/prefill/gemm.hpp@@ -20,10 +20,7 @@ public:Gemm& operator=(const Gemm&) = delete;/// `scratch_elems`: BF16 elements of the dequantization scratch (the largest weight dequantized at once).- /// `resource_failure`, when given, is set to true only for a failure that means the machine ran out of room- /// (a cuBLAS allocation or a `cudaMalloc`), so a caller can retry with a smaller cache instead of treating- /// every init failure as fatal. It is always set (false on success or a non-resource error).- bool init(void* stream, int64_t scratch_elems, std::string& err, bool* resource_failure = nullptr);+ bool init(void* stream, int64_t scratch_elems, std::string& err);/// The same with caller-owned device buffers (the prompt path borrowing expert-cache slots).bool init_external(void* stream, uint16_t* scratch, int64_t scratch_elems, void* workspace, size_t ws_bytes,std::string& err);diff --git a/src/prefill/gemm.cu b/src/prefill/gemm.cuindex a0fa8b843..328c8ae45 100644--- a/src/prefill/gemm.cu+++ b/src/prefill/gemm.cu@@ -42,6 +42,11 @@ void ck(cublasStatus_t s, const char* what) {}}+// A setup call whose failure the engine survives (the handle keeps its defaults), as before #240 - but said.+void note(cublasStatus_t s, const char* what) {+ if (s != CUBLAS_STATUS_SUCCESS) std::fprintf(stderr, "prefill gemm: %s: cuBLAS status %d (continuing)\n", what, (int) s);+}+#if defined(__HIPCC__) && defined(STRATA_HIPBLASLT_AVAILABLE)struct HipLtCallKey {strata::prefill::hipblaslt::InputType type;@@ -285,14 +290,17 @@ Gemm::~Gemm() {bool Gemm::init_external(void* stream, uint16_t* scratch, int64_t scratch_elems, void* workspace, size_t ws_bytes,std::string& err) {cublasHandle_t h = nullptr;- if (cublasCreate(&h) != CUBLAS_STATUS_SUCCESS) { err = "prefill gemm: cublasCreate failed"; return false; }+ if (const cublasStatus_t s = cublasCreate(&h); s != CUBLAS_STATUS_SUCCESS) {+ err = "prefill gemm: cublasCreate: cuBLAS status " + std::to_string((int) s);+ return false;+ }handle_ = h;stream_ = stream;external_ = true;- cublasSetStream(h, (cudaStream_t) stream);+ note(cublasSetStream(h, (cudaStream_t) stream), "cublasSetStream");workspace_ = workspace;- cublasSetWorkspace(h, workspace_, ws_bytes);- cublasSetMathMode(h, CUBLAS_DEFAULT_MATH);+ note(cublasSetWorkspace(h, workspace_, ws_bytes), "cublasSetWorkspace");+ note(cublasSetMathMode(h, CUBLAS_DEFAULT_MATH), "cublasSetMathMode");scratch_ = scratch;scratch_elems_ = scratch_elems;#if defined(__HIPCC__) && defined(STRATA_HIPBLASLT_AVAILABLE)@@ -315,39 +323,34 @@ void Gemm::rebind(uint16_t* scratch, int64_t scratch_elems, void* workspace, siz#endif}-bool Gemm::init(void* stream, int64_t scratch_elems, std::string& err, bool* resource_failure) {- if (resource_failure) *resource_failure = false;- // Every failure below is reported with the call that produced it and, for the two that mean "the machine is- // out of room", with `resource_failure` set so a caller can tell "no VRAM" from "a broken install" without- // parsing the message. The distinction matters on a low-RAM box: a shortage is worth retrying with a smaller- // cache or prompt, while an unsupported math mode never is.- auto blas = [&](cublasStatus_t s, const char* op) {- if (s == CUBLAS_STATUS_SUCCESS) return true;- if (resource_failure) *resource_failure = s == CUBLAS_STATUS_ALLOC_FAILED;- err = std::string("prefill gemm: ") + op + ": cuBLAS status " + std::to_string((int) s);- return false;- };- auto alloc = [&](cudaError_t s, const char* op) {- if (s == cudaSuccess) return true;- if (resource_failure) *resource_failure = s == cudaErrorMemoryAllocation;- err = std::string("prefill gemm: ") + op + ": " + cudaGetErrorString(s);- return false;- };+bool Gemm::init(void* stream, int64_t scratch_elems, std::string& err) {+ // #240: every failure names the call and the real status, so "no VRAM" can be told from a broken installcublasHandle_t h = nullptr;- if (!blas(cublasCreate(&h), "create")) return false;+ if (const cublasStatus_t s = cublasCreate(&h); s != CUBLAS_STATUS_SUCCESS) {+ err = "prefill gemm: cublasCreate: cuBLAS status " + std::to_string((int) s);+ return false;+ }handle_ = h;stream_ = stream;- if (!blas(cublasSetStream(h, (cudaStream_t) stream), "stream")) return false;+ note(cublasSetStream(h, (cudaStream_t) stream), "cublasSetStream");// A fixed workspace so the handle never allocates on the way (and graphs could capture it later).const size_t ws = 32u << 20;- if (!alloc(cudaMalloc(&workspace_, ws), "workspace")) return false;- if (!blas(cublasSetWorkspace(h, workspace_, ws), "workspace config") ||- !blas(cublasSetMathMode(h, CUBLAS_DEFAULT_MATH), "math mode")) return false;+ if (const cudaError_t e = cudaMalloc(&workspace_, ws); e != cudaSuccess) {+ err = std::string("prefill gemm: workspace of 32 MiB: ") + cudaGetErrorString(e);+ return false;+ }+ note(cublasSetWorkspace(h, workspace_, ws), "cublasSetWorkspace");+ note(cublasSetMathMode(h, CUBLAS_DEFAULT_MATH), "cublasSetMathMode");#if defined(__HIPCC__) && defined(STRATA_HIPBLASLT_AVAILABLE)hipblaslt_state_ = create_hipblaslt_state(workspace_, ws).release();#endif- if (scratch_elems > 0 && !alloc(cudaMalloc((void**) &scratch_, (size_t) scratch_elems * 2),- "dequant scratch")) return false;+ if (scratch_elems > 0) {+ if (const cudaError_t e = cudaMalloc((void**) &scratch_, (size_t) scratch_elems * 2); e != cudaSuccess) {+ err = "prefill gemm: dequant scratch of " + std::to_string(scratch_elems * 2 >> 20) + " MiB: " ++ cudaGetErrorString(e);+ return false;+ }+ }scratch_elems_ = scratch_elems;return true;}