From 9cf0a857dcc24a6cd8bd365a2176bd9c1afe0ad5 Mon Sep 17 00:00:00 2001 From: hrx-compat lane Date: Sun, 15 Nov 2026 05:35:15 -0400 Subject: [PATCH] hrx-buffer-test: a buffer type must have an identity (engine#2500) The user-visible symptom of #2500's second half was a runtime message with empty parentheses -- 'pre-allocated tensor (...) in a buffer () that cannot run the operation' -- from a buffer type whose context was never initialised: get_name() returned "" and context.device was null. imported_buft_context was the only uninitialised one of the three in backend-context.h, and it stayed unset through two rounds of this file's own arms (#371, #2393), because they asked 'is it host' and 'is it tagged', never 'does it have a name'. Two assertions, and the invariant is not HRX's -- a buffer type reporting an empty name is malformed in any backend, so the generic half lives here rather than in HRX code: * buffer_type_identity: over every device, assert ggml_backend_dev_buffer_type() and host_buffer_type() have a non-null, non-empty name and a positive alignment; * in run_imported_buffer_checks, where the buffer exists: the imported type is an EXTRA buft that no public accessor enumerates (ggml_backend_dev_get_extra_bufts is a typedef, not a function), so its identity has to be asserted at the buffer. Measured on both sides, which is the whole argument for the arm: pre-#393 (imported_buft_context = {}): [FAIL] 4/11 imported_buffer, "hrx-buffer-test.cpp:241: requirement failed: ggml_backend_buft_name(ggml_backend_buffer_get_type(imported))[0] != '\0'" post-#393 (the assignment lands): 11 passed, 0 failed, rc=0 It fails on the real defect, as a REQUIRE with the requirement printed, and clears once the fix is in. Every other case (host_buffer, loader_mmap_proc, host_transfer, host_staging, host_weight_cache, weight_layout_warnings, packed_weight_identity) passes on both. --- tests/hrx-buffer-test.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/hrx-buffer-test.cpp b/tests/hrx-buffer-test.cpp index 8e4a19bff66d..00f1e1e29fa1 100644 --- a/tests/hrx-buffer-test.cpp +++ b/tests/hrx-buffer-test.cpp @@ -233,7 +233,13 @@ static void run_imported_buffer_checks(ggml_backend_t backend) { } ggml_backend_buffer_t imported = ggml_backend_dev_buffer_from_host_ptr(device, source.data(), sizeof(source), sizeof(source) / 2); + + // engine#2500: the imported type had no context (name "", device null) since #371, so every imported weight + // buffer was nameless and device-less -- announced only as "pre-allocated tensor (...) in a buffer () that + // cannot run the operation". Assert the identity here, where the buffer exists, because the type is an extra + // buft and no public accessor enumerates it. REQUIRE(imported != nullptr); + REQUIRE(ggml_backend_buft_name(ggml_backend_buffer_get_type(imported))[0] != '\0'); REQUIRE(imported != nullptr); REQUIRE(ggml_backend_buffer_get_base(imported) == source.data()); // engine #2393: an import is NOT host-typed, and that is the property that broke. #370 relaxed this assertion // on the reading that `imported` and `is_host` are independent flags (backend-buffer-binding.cpp:85 keeps them @@ -802,7 +808,34 @@ static void run_loader_mmap_proc_checks(ggml_backend_t backend) { ggml_backend_buffer_free(mapped); } +// engine#2500: every buffer type must have an IDENTITY. A context initialised to `{}` gives a type whose name is "" +// and whose context.device is null, and the only place that shows up is a runtime message with empty parentheses: +// pre-allocated tensor (...) in a buffer () that cannot run the operation +// That is exactly how `imported_buft_context` stayed unset through two rounds of this file's own tests (#371, #2393): +// the arms asked "is it host" and "is it tagged", never "does it have a name". The invariant is not HRX's -- a buffer +// type reporting an empty name is malformed in any backend -- so it is asserted over every device's every type here. +static void run_buffer_type_identity_checks() { + const size_t n_dev = ggml_backend_dev_count(); + REQUIRE(n_dev > 0); + for (size_t d = 0; d < n_dev; ++d) { + ggml_backend_dev_t dev = ggml_backend_dev_get(d); + REQUIRE(dev != nullptr); + for (size_t b = 0; b < 2; ++b) { + ggml_backend_buffer_type_t buft = b == 0 ? ggml_backend_dev_buffer_type(dev) + : ggml_backend_dev_host_buffer_type(dev); + if (buft == nullptr) { + continue; + } + const char * name = ggml_backend_buft_name(buft); + REQUIRE(name != nullptr); + REQUIRE(name[0] != '\0'); // the "(...in a buffer ())" defect + REQUIRE(ggml_backend_buft_get_alignment(buft) > 0); + } + } +} + static void register_hrx_buffer_cases(test_runner::Suite & suite) { + suite.device_case("buffer_type_identity", [] { run_buffer_type_identity_checks(); }); suite.device_case("backend_buffer", [] { run_with_hrx_backend([](ggml_backend_t backend, ggml_backend_hrx_context *) { run_backend_buffer_checks(backend);