Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ggml/src/ggml-hrx/ggml-hrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ 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")
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)
Expand Down
4 changes: 4 additions & 0 deletions tests/hrx-buffer-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const ggml_backend_hrx_buffer_type_context *>(
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);
Expand Down
83 changes: 83 additions & 0 deletions tests/test-hrx-loader-mapped.cpp
Original file line number Diff line number Diff line change
@@ -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 77, ctest SKIP_RETURN_CODE) without a model or an HRX device.
#include "llama.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>

static std::vector<std::string> 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 77; // ctest SKIP_RETURN_CODE, as test-hrx-external-window-view
}
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 77;
}
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;
}