From 97a45e6ca2cba2b3bbb4a17237d52be86b59624d Mon Sep 17 00:00:00 2001 From: bcloud Date: Sat, 14 Nov 2026 10:25:24 -0400 Subject: [PATCH] tests: restore the imported-buffer is_host guard, and the rationale that argues for it #370 removed REQUIRE(!ggml_backend_buffer_is_host(imported)) with a comment explaining that `imported` and `is_host` are independent flags and a zero-copy import of host memory is legitimately host-typed. #371 settled the question the other way: the defect was a from-pointer buffer reaching that point as a CPU buffer with its `buft` retagged, which is exactly what made is_host true for something that was not a host allocation. The comment was never updated, so the merged tree still teaches the reading that produced the bug, in the file that regressed from it, and the assertion is gone. This restores both: - the rationale now cites backend-context.h's `imported_buft`, "a direct binding whose buffer must not claim to be a host allocation"; - REQUIRE(!ggml_backend_buffer_is_host(imported)) is back, naming what it catches: if an import ever becomes host-typed again, it went back through the retagging path that cost an afternoon. Verified at 7e91e98a7 before rebasing, one gpu-hold ticket, dmesg amdgpu resets 0 before / 0 after: hrx-buffer-test: 9 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 9 total so this restores a guard rather than surfacing a new failure. --- tests/hrx-buffer-test.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/hrx-buffer-test.cpp b/tests/hrx-buffer-test.cpp index 68a0b64d9dfb..9bf67ee09ab4 100644 --- a/tests/hrx-buffer-test.cpp +++ b/tests/hrx-buffer-test.cpp @@ -234,12 +234,14 @@ static void run_imported_buffer_checks(ggml_backend_t backend) { sizeof(source) / 2); REQUIRE(imported != nullptr); REQUIRE(ggml_backend_buffer_get_base(imported) == source.data()); - // engine #2393: `imported` and `is_host` are INDEPENDENT flags in this backend, not exclusive ones -- - // backend-buffer-binding.cpp:85 keeps them as separate booleans (ordinary_device_buffer = !imported && !is_host) - // and :111 accepts either as "retained", so a zero-copy import of host memory is legitimately host-typed. The - // contract the case can enforce is the one asserted immediately below: the buffer is an IMPORTED handle with no - // private storage, and its base is the caller's pointer (asserted above). A buffer-type label adds nothing to - // that, and asserting the negative here would pin an implementation detail the rest of the code does not rely on. + // 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 + // separate, :111 accepts either as "retained"). #371 settled it the other way: the bug was that a from-pointer + // buffer reached here as a CPU buffer with its `buft` retagged, so `is_host` was true for something that was not + // a host allocation at all. An import now has its own buft (backend-context.h: `imported_buft`, "a direct + // binding whose buffer must not claim to be a host allocation"), so this negative is the invariant to hold: + // if an import ever becomes host-typed again, it went back through the retagging path that cost an afternoon. + REQUIRE(!ggml_backend_buffer_is_host(imported)); auto * context = ggml_backend_hrx_buffer_context_from_buffer(imported); REQUIRE(context->imported); REQUIRE(context->buffer == nullptr);