From 660996051e965dd8db71df188cdf6de021b6bbf2 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 28 Sep 2026 12:49:25 +0200 Subject: [PATCH] engine: load every CUDA kernel at start (CUDA_MODULE_LOADING=EAGER) With lazy loading, a kernel first used mid-prompt found no VRAM left for its code once the expert cache and the prompt path had taken it: IQ3_XXS at 64K and 128K on a 12 GB card ended with 'out of memory: cudaFuncSetAttribute' in the MMQ launch. Loaded at start the kernels cost ~30 MB, accounted before the cache is sized (~23 fewer slots). A user's own CUDA_MODULE_LOADING is kept. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN --- src/program/generate.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index b699ee1931..4b060741ab 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -759,6 +759,16 @@ int main(int argc, char** argv) { // pipe or a file is block-buffered, so a program that dies loses every line it had already printed - which // turns "it crashed at step 7" into "it crashed somewhere", and the difference is a debugging session. std::setvbuf(stdout, nullptr, _IONBF, 0); + // Load every CUDA kernel when the context is created, before the expert cache takes the free VRAM. With the + // default lazy loading, a kernel first used mid-prompt (MMQ for IQ3_XXS at 64K+ on a 12 GB card) found no VRAM + // left for its code and the engine ended ("out of memory: cudaFuncSetAttribute"). Costs ~30 MB of VRAM. + if (std::getenv("CUDA_MODULE_LOADING") == nullptr) { +#if defined(_WIN32) + _putenv_s("CUDA_MODULE_LOADING", "EAGER"); +#else + setenv("CUDA_MODULE_LOADING", "EAGER", 0); +#endif + } Options o; bool have_tokens = false; bool have_logits_stride = false;