From bcf47ac603add4b951ad3a51423f3761f78d1c07 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 15 Nov 2026 04:25:21 -0400 Subject: [PATCH 1/3] tests: guard #393's loader hunk and the imported type's device (engine #2500 follow-up) test-hrx-loader-mapped loads a model on HRX and reads the loader's "model buffer size" lines: at least one HRX0_Mapped, none HRX0_Imported or nameless. Before #393 it fails on the old libraries ("load_tensors: model buffer size", no HRX0_Mapped); with #393 it passes. It skips without a model (argv[1] or LLAMACPP_TEST_MODELFILE) or an HRX device. hrx-buffer-test loader_mmap_proc also requires the imported buffer type to carry its device (the zeroed context was half of #2500). Both were asked for on #393. Co-Authored-By: Claude Opus 5.5 --- tests/CMakeLists.txt | 2 + tests/hrx-buffer-test.cpp | 4 ++ tests/test-hrx-loader-mapped.cpp | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 tests/test-hrx-loader-mapped.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7b6b074361e2..7a87b6a3a4ce 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -517,6 +517,8 @@ if (TARGET ggml-hrx) target_include_directories(hrx-buffer-test PRIVATE ../ggml/include ../ggml/src ../ggml/src/ggml-hrx) add_test(NAME hrx-buffer-test COMMAND hrx-buffer-test --hrx-buffer-test-jobs 1 --hrx-buffer-test-output all --hrx-buffer-test-filter ".*") + # engine #2500: the loader's mapping becomes HRX0_Mapped weight buffers (skips without LLAMACPP_TEST_MODELFILE) + llama_build_and_test(test-hrx-loader-mapped.cpp LABEL "hrx") add_executable(hrx-backend-test hrx-backend-test.cpp) target_link_libraries(hrx-backend-test PRIVATE ggml-hrx ggml hrx::hrx loomc::loomc) diff --git a/tests/hrx-buffer-test.cpp b/tests/hrx-buffer-test.cpp index 8e4a19bff66d..26fb43518fdb 100644 --- a/tests/hrx-buffer-test.cpp +++ b/tests/hrx-buffer-test.cpp @@ -797,6 +797,10 @@ static void run_loader_mmap_proc_checks(ggml_backend_t backend) { REQUIRE(!ggml_backend_buffer_is_host(imported)); const std::string imported_name = ggml_backend_buft_name(ggml_backend_buffer_get_type(imported)); REQUIRE(!imported_name.empty()); + // the device-less type was the other half of #2500: a zeroed imported_buft_context + const auto * imported_type = static_cast( + ggml_backend_buffer_get_type(imported)->context); + REQUIRE(imported_type != nullptr && imported_type->device != nullptr); REQUIRE(imported_name != ggml_backend_buft_name(ggml_backend_buffer_get_type(mapped))); ggml_backend_buffer_free(imported); ggml_backend_buffer_free(mapped); diff --git a/tests/test-hrx-loader-mapped.cpp b/tests/test-hrx-loader-mapped.cpp new file mode 100644 index 000000000000..570457a25eea --- /dev/null +++ b/tests/test-hrx-loader-mapped.cpp @@ -0,0 +1,83 @@ +// engine #2500: on HRX the loader's file mapping must become MAPPED weight buffers (HRX0_Mapped, host), never imported +// ones. llama.cpp#371 routed every mmap-backed weight through the import path (non-host), and zaya1-8b then aborted at +// load because a weight view HRX declines had no backend; llama.cpp#393 restored the mapped path. This loads a model on +// HRX and reads the loader's own "model buffer size" lines, so a revert of the loader hunk fails here, not only in the +// hw-gate. Model: argv[1] or LLAMACPP_TEST_MODELFILE; skipped (exit 0) without a model or an HRX device. +#include "llama.h" + +#include +#include +#include +#include +#include + +static std::vector g_buffer_lines; + +static void collect(ggml_log_level level, const char * text, void * user_data) { + (void) level; + (void) user_data; + if (text != nullptr && std::strstr(text, "model buffer size") != nullptr) { + g_buffer_lines.emplace_back(text); + } +} + +int main(int argc, char ** argv) { + const char * path = argc > 1 ? argv[1] : std::getenv("LLAMACPP_TEST_MODELFILE"); + if (path == nullptr || path[0] == '\0') { + std::printf("skipped: no model (argv[1] or LLAMACPP_TEST_MODELFILE)\n"); + return EXIT_SUCCESS; + } + llama_backend_init(); + ggml_backend_dev_t hrx = nullptr; + for (size_t i = 0; i < ggml_backend_dev_count(); ++i) { + ggml_backend_dev_t d = ggml_backend_dev_get(i); + if (std::strcmp(ggml_backend_reg_name(ggml_backend_dev_backend_reg(d)), "HRX") == 0) { + hrx = d; + break; + } + } + if (hrx == nullptr) { + std::printf("skipped: no HRX device\n"); + llama_backend_free(); + return EXIT_SUCCESS; + } + llama_log_set(collect, nullptr); + llama_model_params params = llama_model_default_params(); + params.n_gpu_layers = 99; + ggml_backend_dev_t devs[] = { hrx, nullptr }; + params.devices = devs; + llama_model * model = llama_model_load_from_file(path, params); + llama_log_set(nullptr, nullptr); + int fails = 0; + if (model == nullptr) { + std::fprintf(stderr, "FAIL: the model did not load\n"); + fails++; + } + size_t mapped = 0; + for (const std::string & line : g_buffer_lines) { + if (line.find("HRX0_Mapped") != std::string::npos) { + mapped++; + } + // an imported weight buffer, or a nameless buffer type: nothing but spaces between "load_tensors:" and + // "model buffer size" (the empty "()" of the #2500 abort) + bool nameless = false; + if (const size_t at = line.find("load_tensors:"); at != std::string::npos) { + const size_t name = line.find_first_not_of(' ', at + std::strlen("load_tensors:")); + nameless = name != std::string::npos && line.compare(name, std::strlen("model buffer size"), "model buffer size") == 0; + } + if (line.find("_Imported") != std::string::npos || nameless) { + std::fprintf(stderr, "FAIL: a weight buffer is not a mapped one: %s", line.c_str()); + fails++; + } + } + if (mapped == 0) { + std::fprintf(stderr, "FAIL: no HRX0_Mapped weight buffer among %zu buffer lines\n", g_buffer_lines.size()); + fails++; + } + std::printf("%zu weight buffer lines, %zu HRX0_Mapped, %d failure(s)\n", g_buffer_lines.size(), mapped, fails); + if (model != nullptr) { + llama_model_free(model); + } + llama_backend_free(); + return fails == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} From 83b5f975873a375642960536951bf992019e4cc5 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 15 Nov 2026 04:36:14 -0400 Subject: [PATCH 2/3] tests: test-hrx-loader-mapped skips with 77 (SKIP_RETURN_CODE), not 0 (#394 review) Co-Authored-By: Claude Opus 5.5 --- tests/CMakeLists.txt | 1 + tests/test-hrx-loader-mapped.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7a87b6a3a4ce..488be1fee2f3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -519,6 +519,7 @@ if (TARGET ggml-hrx) --hrx-buffer-test-jobs 1 --hrx-buffer-test-output all --hrx-buffer-test-filter ".*") # engine #2500: the loader's mapping becomes HRX0_Mapped weight buffers (skips without LLAMACPP_TEST_MODELFILE) llama_build_and_test(test-hrx-loader-mapped.cpp LABEL "hrx") + set_tests_properties(test-hrx-loader-mapped PROPERTIES SKIP_RETURN_CODE 77) add_executable(hrx-backend-test hrx-backend-test.cpp) target_link_libraries(hrx-backend-test PRIVATE ggml-hrx ggml hrx::hrx loomc::loomc) diff --git a/tests/test-hrx-loader-mapped.cpp b/tests/test-hrx-loader-mapped.cpp index 570457a25eea..3d7f9ad72ba3 100644 --- a/tests/test-hrx-loader-mapped.cpp +++ b/tests/test-hrx-loader-mapped.cpp @@ -2,7 +2,7 @@ // ones. llama.cpp#371 routed every mmap-backed weight through the import path (non-host), and zaya1-8b then aborted at // load because a weight view HRX declines had no backend; llama.cpp#393 restored the mapped path. This loads a model on // HRX and reads the loader's own "model buffer size" lines, so a revert of the loader hunk fails here, not only in the -// hw-gate. Model: argv[1] or LLAMACPP_TEST_MODELFILE; skipped (exit 0) without a model or an HRX device. +// hw-gate. Model: argv[1] or LLAMACPP_TEST_MODELFILE; skipped (exit 77, ctest SKIP_RETURN_CODE) without a model or an HRX device. #include "llama.h" #include @@ -25,7 +25,7 @@ int main(int argc, char ** argv) { const char * path = argc > 1 ? argv[1] : std::getenv("LLAMACPP_TEST_MODELFILE"); if (path == nullptr || path[0] == '\0') { std::printf("skipped: no model (argv[1] or LLAMACPP_TEST_MODELFILE)\n"); - return EXIT_SUCCESS; + return 77; // ctest SKIP_RETURN_CODE, as test-hrx-external-window-view } llama_backend_init(); ggml_backend_dev_t hrx = nullptr; @@ -39,7 +39,7 @@ int main(int argc, char ** argv) { if (hrx == nullptr) { std::printf("skipped: no HRX device\n"); llama_backend_free(); - return EXIT_SUCCESS; + return 77; } llama_log_set(collect, nullptr); llama_model_params params = llama_model_default_params(); From f897e4ca1852b05cb8d8bca761abc612f92c9952 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 15 Nov 2026 05:06:14 -0400 Subject: [PATCH 3/3] hrx: the placement report says which off-HRX nodes are BY DESIGN (engine#2450) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `off_by_design` is computed on every graph (a weight in the loader's file mapping, or an unaligned matmul with no HRX dense schedule) and it decides the GGML_HRX_STRICT abort -- but it was never printed. The `level >= 1` placement line carried only the op counts: placement: 989 nodes, 2 off HRX (GET_ROWS x 2), 2 graph splits so a reader of the log -- and the hardware gate's `placement` row, which parses this line -- could only compare the raw off-HRX count. That row is the only red row in the gate on every model at main, always on the same two nodes: 2 of 989 nodes off HRX (GET_ROWS x 2) qwen3-0.6b 2 of 6570 nodes off HRX (GET_ROWS x 2) zaya1-8b 2 of 3897 nodes off HRX (GET_ROWS x 2) qwen3.8-27b and the strict-mode comment names that exact case as by design: "the token-embedding GET_ROWS over a weight in the loader's file mapping". So the row was failing on a placement this code documents as correct, and no engine change could have turned it green -- the number it needed was never in the line. Two counts, beside the total: placement: 989 nodes, 2 off HRX (GET_ROWS x 2), 2 by design, 0 unexplained, 2 graph splits The gate half is engine#2511, and it is backwards compatible on purpose: the two fields are optional in its regex, so it keeps today's behaviour until a binary prints them, then decides on `unexplained` alone. Verified end to end without a device, by composing the exact line this format prints and running the gate's parser over it: 2 off-HRX node(s) BY DESIGN and none unexplained, in 1 graphs (largest 989 nodes) rc 0 2 of 989 nodes off HRX (GET_ROWS x 2), 2 graph splits, 0 by design, 2 unexplained … rc 1 and the file compiles: `-fsyntax-only` with the hw-gate build's own compile command, re-mapped to this tree (proved by injecting an error first -- "expected expression" at the new line -- and getting a clean rc 0 after restoring). Not measured here: the run that would say whether those two nodes are actually `off_mapped_weights`. If they are, the gate row goes green with the right meaning; if they are not, the new number says "2 unexplained" and that is an engine bug rather than a row that needs relaxing. Either way the next gate run answers engine#2450. --- ggml/src/ggml-hrx/ggml-hrx.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ggml/src/ggml-hrx/ggml-hrx.cpp b/ggml/src/ggml-hrx/ggml-hrx.cpp index 5835d7787872..8494593f7b06 100644 --- a/ggml/src/ggml-hrx/ggml-hrx.cpp +++ b/ggml/src/ggml-hrx/ggml-hrx.cpp @@ -740,8 +740,15 @@ static void placement_observer(ggml_backend_sched_t sched, ggml_cgraph * graph, if (level >= 1) { reported.store(true); - GGML_LOG_INFO("%s: placement: %d nodes, %" PRId64 " off HRX (%s), %d graph splits\n", __func__, graph->n_nodes, - off_nodes, off_detail.c_str(), ggml_backend_sched_get_n_splits(sched)); + // engine#2450: say WHICH off-HRX nodes are intended. `off_by_design` (a weight in the loader's file mapping, or an + // unaligned matmul with no HRX dense schedule) is incremented above and feeds the strict decision, but it was never + // printed -- so the hardware gate's placement row could only compare the raw off-HRX count and failed on a placement + // this code documents as correct. With the two counts beside the total, the row decides on `unexplained` and a reader + // of the log can see why: e.g. "2 off HRX (GET_ROWS x 2), 2 by design, 0 unexplained, 2 graph splits". + GGML_LOG_INFO("%s: placement: %d nodes, %" PRId64 " off HRX (%s), %" PRId64 " by design, %" PRId64 + " unexplained, %d graph splits\n", __func__, graph->n_nodes, + off_nodes, off_detail.c_str(), off_by_design, off_nodes - off_by_design, + ggml_backend_sched_get_n_splits(sched)); } else if (off_nodes > 0 && !placement_fallback_quiet() && !fallback_reported.exchange(true)) { // engine #991: a model whose hidden size is not a multiple of 256 loses its dense matmuls to the CPU by design, and // until this line existed the only way to know was GGML_HRX_STRICT=1. Say it once, at load, with the reason.