diff --git a/src/prefill/gemm.cu b/src/prefill/gemm.cu index 6198170c..a52af750 100644 --- a/src/prefill/gemm.cu +++ b/src/prefill/gemm.cu @@ -36,6 +36,17 @@ #if defined(__HIPCC__) && defined(STRATA_HIPBLASLT_AVAILABLE) #include "hipblaslt_tuning.hpp" +#if defined(_WIN32) +#ifndef NOMINMAX +#define NOMINMAX +#endif +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#else +#include +#endif #include #include #include @@ -238,9 +249,34 @@ struct HipLtDescriptors { } }; +// The engine package's own tuning folder (/tuning), for a start that did not come through the launcher (a hand-made +// config, a CLI run): without a table the prompt GEMMs fall back to plain hipBLAS and a Strix Halo reads prompts at half speed +// (340 against 690 tok/s, IQ3_S 4K). The launcher sets STRATA_HIPBLASLT_TUNING itself; this is the same table found by the engine. +std::string own_tuning_dir() { +#if defined(_WIN32) + char p[4096] = {}; + const DWORD n = GetModuleFileNameA(nullptr, p, (DWORD) sizeof(p)); + std::string s(p, n); + const size_t k = s.find_last_of("\\/"); + return k == std::string::npos ? std::string() : s.substr(0, k + 1) + "tuning/"; +#else + char p[4096] = {}; + const ssize_t n = readlink("/proc/self/exe", p, sizeof(p) - 1); + std::string s(p, n > 0 ? (size_t) n : 0); + const size_t k = s.find_last_of('/'); + return k == std::string::npos ? std::string() : s.substr(0, k + 1) + "tuning/"; +#endif +} + std::unique_ptr create_hipblaslt_state(void* workspace, size_t workspace_bytes) { + std::string path_own; const char* path = std::getenv("STRATA_HIPBLASLT_TUNING"); - if (!path || !*path) return nullptr; + bool from_package = false; + if (!path || !*path) { + const char* sw = std::getenv("STRATA_HIPBLASLT_TABLE"); // the launcher's switch: off / 0 / false = never the packaged table + if (sw != nullptr && (std::strcmp(sw, "off") == 0 || std::strcmp(sw, "0") == 0 || std::strcmp(sw, "false") == 0)) return nullptr; + from_package = true; // the file is found below, once the card and the version are known + } auto state = std::make_unique(); state->workspace = workspace; @@ -265,6 +301,15 @@ std::unique_ptr create_hipblaslt_state(void* workspace, size_t works const auto suffix = arch.find(':'); if (suffix != std::string::npos) arch.resize(suffix); + if (from_package) { + const std::string dir = own_tuning_dir(); + if (dir.empty()) return nullptr; + path_own = dir + arch + "-hipblaslt-" + std::to_string(version) + ".txt"; + std::FILE* f = std::fopen(path_own.c_str(), "rb"); + if (f == nullptr) return nullptr; // no table for this card and hipBLASLt version beside the engine: plain hipBLAS as before + std::fclose(f); + path = path_own.c_str(); + } std::string error; if (!state->table.load(path, arch, version, error)) { std::fprintf(stderr, "prefill gemm: %s; using hipBLASEx\n", error.c_str()); diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 3b7ad411..f3635de1 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -2821,6 +2821,17 @@ int main(int argc, char** argv) { // So its expert arena stays unregistered. STRATA_UMA_REGISTER=1 (or STRATA_ARENA_PIN_GIB=0) registers it as before. if (strata::core::igpu_uma_arena_default(ad.gcnArchName, all_igpu, win_host)) strata::core::arena_uma_no_register_flag().store(true); + // gfx1151 on Windows (#1630 capped a bare `--prefill auto` at 6144 for a 7900 XTX's commit charge): the Strix Halo has its + // 8192 chunk back. IQ3_S, 8K prompt: 691 -> 787 tok/s (one chunk streams 1,785 experts instead of 2,782), 64K 713 -> 748; + // 4K is one chunk already. STRATA_GFX1151_CHUNK=0 (or STRATA_GFX1151_DEFAULTS=0) keeps 6144. + if (win_host && all_igpu && o.prefill_auto_bare && o.prefill_auto_cap > 0 && std::strncmp(ad.gcnArchName, "gfx1151", 7) == 0) { + const char* c1 = std::getenv("STRATA_GFX1151_CHUNK"); + const char* d1 = std::getenv("STRATA_GFX1151_DEFAULTS"); + if (!(c1 != nullptr && c1[0] == '0') && !(d1 != nullptr && d1[0] == '0')) { + o.prefill_auto_cap = 0; + o.prefill_chunk = std::max(o.prefill_chunk, 8192); + } + } } else (void) cudaGetLastError(); } #endif