Repository navigation
feat(bench): live Tensor G6 GPU<->EdgeTPU multi-layer token loop with r_iif fence chain - #59
Merged
Merged
Conversation
…aged/sync_file/r_iif fence arms - tools/volcanic_tpu_token_loop_bench.cpp: L-layer x T-token decode loop (Volcanic GEMV -> EdgeTPU W8A16 INT8 FFN -> Volcanic residual+RMSNorm) over pre-pinned fs_iova_pool CACHED DMA-BUFs in hot-loop mode, 3 sync arms, per-token /proc/self/status ctx-switch deltas, ODPM energy_value sampler, FP64 parity (cos >= 0.9999), mock CPU + live Vulkan/libopenbuenos executors. - tools/volcanic_token_loop_util.h: clean-room IIF candidate ABI with runtime probe + software emulator, ODPM parser, ctx-switch sampler, stats. - shaders/volcanic/residual_rmsnorm_f32.comp + generated SPIR-V header and scripts/gen_volcanic_token_loop_spirv.sh. - 5 new CTest cases incl. tests/test_token_loop_riif.cpp.
…for the token loop IIF (tools/volcanic_token_loop_util.h): - Replace the candidate ABI with the google,iif UAPI: FS_IIF_CREATE_FENCE (0xc0086900, u8 signaler_ip / u16 total_signalers / s32 fence_fd), FS_IIF_FENCE_SUBMIT_SIGNALER (0x6981), FS_IIF_FENCE_SIGNAL (0xc0086982, s32 error / u16 remaining_signalers), FS_IIF_FENCE_BRIDGE_DMA (0x80046985), FS_IIF_FENCE_SIGNALER_DONE (0x6986), FS_IIF_IP_AP = 3; _IOC encodings static_asserted on Linux. Fence fds are sync_file-compatible (poll waits). - Probe runs create(AP,1) -> submit_signaler -> signal -> poll -> close. - Documented lifetime rule: an IIF fd imported into a GPU queue is closed only after it is signaled and the queue drained. EdgeTPU backend auto-selection (tools/volcanic_tpu_token_loop_bench.cpp): - --tpu-backend auto (default): libopenbuenos when a Tensor G5 node opens, else the NNAPI ACCELERATOR (google-edgetpu first) with one TENSOR_QUANT8_ASYMM NHWC 1x1 CONV_2D per layer (tools/volcanic_nnapi_edgetpu.h, runtime dlopen only). - GPU and EdgeTPU share the same zero-copy uint8 tensors (AHardwareBuffer BLOB GPU_DATA_BUFFER, falling back to the pinned DMA-BUF fd) via new FP32<->QUANT8 bridge compute shaders; per-layer scales calibrated from the FP64 reference. - Arms: host_staged (2L host copies/token), sync_file_poll (waiter-thread poll + wakeup per hop), r_iif (one kernel fence chain per token: Vulkan SYNC_FD -> ANeuralNetworksEvent_createFromSyncFenceFd -> startComputeWithDependencies -> getSyncFenceFd -> vkImportSemaphoreFdKHR, gated by an AP-signaled dma_iif_fence imported into the GPU queue, zero userspace poll between layers). 'sync_file' stays an alias. - New per-arm counters: userspace fence polls / wakeups, NNAPI start blocking time and unfenced hops. - --mock --tpu-backend nnapi emulates the QUANT8 path bit-for-bit; QUANT8 parity gate defaults to cos >= 0.995. Tests: IIF UAPI constant/layout checks, SW submit_signaler semantics, QUANT8 helper references, mock QUANT8 d512/d2048 ctest entries.
…n-silicon proof Three runtime issues surfaced on a Pixel 11 Pro XL (Tensor G6, PowerVR C-Series CXTP-48-1536 + Google EdgeTPU via NNAPI) and are fixed here: - Zero-copy tensors are now device-only. A CPU AHardwareBuffer_lock + read/write of a shared GPU<->EdgeTPU tensor in host_staged corrupted every later zero-copy handoff (sync_file_poll cos 0.16-0.48, r_iif 0.57-0.88). host_staged now copies through its own CPU-visible AHB bridge tensors and command buffers (nnapi.host_staged_mem in JSON). - IIF fence fds (anon_inode:iif_file) are pollable but not sync_files, so Vulkan SYNC_FD import rejected the r_iif gate. New IifFences::bridge_sync_file() uses FS_IIF_FENCE_BRIDGE_DMA to get a real sync_file (validated with SYNC_IOC_FILE_INFO); r_iif imports it. The probe reports fence_is_sync_file / bridge_sync_file_ok / bridge_signaled. - libneuralnetworks.so is no longer dlclose()d: NNAPI runtime worker threads outlive every freed object and crashed at process exit. Tests: sync_file bridge checks in test_token_loop_riif; the regular-file probe check accepts EACCES (Android SELinux ioctl allowlisting). Proof: proof/tensor-g6-gpu-edgetpu-riif-token-loop (L=12, T=64, d=512/1024/2048, all arms cos >= 0.9992, r_iif 1.24-1.80x host_staged tok/s, 16-40% lower VSYS J/tok, 0 hot-loop maps, 0 faults).
- Budget the Vulkan descriptor pool for all 6 sets / 24 storage-buffer
descriptors per layer (GEMV, RMSNorm, QUANT8 bridge, isolated
host_staged bridge).
- Record explicit queue-family ownership release/acquire buffer barriers
for every GPU<->EdgeTPU tensor (VK_QUEUE_FAMILY_FOREIGN_EXT when
VK_EXT_queue_family_foreign is available, else VK_QUEUE_FAMILY_EXTERNAL).
- --require-iif now requires r_iif to have measurably created IIF fences,
from the kernel /dev/iif backend on live runs; --iif-sw-fallback no
longer satisfies it. Unit + CTest coverage added.
- host_staged fails closed (reported unavailable) when its isolated
staging tensors cannot be set up, instead of CPU-accessing the
zero-copy tensors.
- Check ANeuralNetworksEvent_wait status for every fenced EdgeTPU hop
(sync_file_poll after poll(), r_iif at the token boundary) before
freeing the event.
- W8A16 sync_file_poll exports the TPU fence with
DMA_BUF_IOCTL_EXPORT_SYNC_FILE and poll()s it before the next GPU
submit; a failed export fails the hop.
Proof packet regenerated on this tree: live L=12, T=64,
d in {512, 1024, 2048} sweep, all 9 cells pass, plus a negative
--iif-sw-fallback --require-iif run and a live W8A16 run.
…ove on Tensor G6
- run_tpu marks its counter parameter used so builds with Vulkan headers
and without FREESCHED_HAVE_LIBOPENBUENOS stay -Wextra -Werror clean.
- Every vkQueueSubmit wait semaphore uses VK_PIPELINE_STAGE_ALL_COMMANDS_BIT:
each command buffer starts with a foreign -> compute queue-family
ownership acquire of EdgeTPU-written tensors, and legacy acquires run
outside the defined pipeline stages.
- Remove the VK_QUEUE_FAMILY_EXTERNAL fallback. Without
VK_EXT_queue_family_foreign the openbuenos/nnapi accelerator backends
report the GPU<->EdgeTPU zero-copy path unavailable. --tpu-backend cpu
only touches the DMA-BUFs from the host, keeps tensors owned by the
compute queue family and records no transfer (queue_family =
none_host_only).
- --live --tpu-backend cpu fenced arms count the stage_in_/stage_out_
host copies (2L per token) in inter_ip_host_copies.
Proof packet regenerated on this tree: live Pixel 11 Pro XL L=12, T=64,
d in {512, 1024, 2048}, all 9 cells pass; negative --iif-sw-fallback
--require-iif run fails as expected; W8A16 CPU run now reports 24 host
copies/token on every arm. Compile matrix: arm64-v8a with/without
libopenbuenos, non-Android Linux syntax with/without, macOS host.
…ove on Tensor G6
- IifProbe records bridge_dma_ok (FS_IIF_FENCE_BRIDGE_DMA returned a
sync_file AND it signaled) separately from raw /dev/iif usability.
Raw kernel IIF stays available for CPU-proxy handoffs; the NNAPI arm
enables its Vulkan IIF gate only with a working bridge and otherwise
runs the ungated sync-fence chain with 0 IIF fences, so --require-iif
still rejects it. New --iif-ioctl-bridge override for live negatives.
- userspace_wakeups counts only cross-thread wakeups (NNAPI waiter
thread). Inline polls on the submitting thread (CPU-proxy IIF, mock
fence round trip, --tpu-backend cpu) count only as fence polls.
- PROOF.md states that cos is measured against an unquantized FP64
float-activation baseline (includes INT8 activation quantization
error); arms_max_abs_diff checks cross-arm quantized agreement.
- Token-loop CTests no longer use PASS_REGULAR_EXPRESSION (it masks the
exit code); content checks go through tests/ctest_run_expect.cmake,
plus a d2048 --require-iif negative test.
- Unit-test fixtures use $TMPDIR, then /data/local/tmp, then /tmp.
- Every floating JSON field emits null when non-finite
(json_finite_or_null), with a strict python3 JSON CTest.
Proof packet regenerated from one binary in one exclusive-adb session on
Pixel 11 Pro XL: L=12 T=64 d in {512,1024,2048} all 9 cells pass; W8A16
run reports 0 cross-thread wakeups; new no-bridge runs pass ungated and
fail with --require-iif; test_token_loop_riif passes as uid shell (with
and without TMPDIR) and as root.
…ove on Tensor G6
- IOVA proof tracks the buffers each device actually touches: GPU writes
of FP32 mid(l)/out(l) and, in dmabuf_fd mode, the EdgeTPU's QUANT8
qmid/qout pool slots (also in the r_iif chain). AHB mode no longer
records synthetic EdgeTPU submissions on FP32 slots; the JSON reports
iova_observation_scope (vulkan_pool_only_nnapi_ahb_external |
full_pool_dmabuf | full_pool_mock), ahb_hot_loop_allocs and
nnapi_ahb_memories_registered_before_hot_loop. A failed NNAPI hop
retires its QUANT8 slots once drained.
- --tpu-backend cpu: the synchronous CPU W8A16 output write is no longer
exported/polled (sync_file_poll) or proxied through an IIF (r_iif); it
counts as synchronous_cpu_hops instead of a fenced handoff
(fence_handoffs_per_tok = L = 12, synchronous_cpu_hops_per_tok = 12).
- sync_us_per_tok is replaced by host_wait_us_per_tok and
dispatch_submit_us_per_tok with identical interval definitions in every
arm; the r_iif whole-chain duration moves to pipelined_chain_us_per_tok.
- Every JSON string value goes through fs_tokloop::json_escape(),
including --iif-dev in the new iif_probe_json(); unit test plus strict
python3 JSON CTests with a path containing a quote, backslashes and
control characters.
Proof packet regenerated from one binary (sha256 5e71eae8...) in one
exclusive-adb session on Pixel 11 Pro XL: L=12 T=64 d in {512,1024,2048}
all 9 cells pass; W8A16 reports 12 fenced + 12 synchronous hops per
token; --iif-probe-only receipts (incl. a hostile --iif-dev) are strict
JSON. Host ctest 56/56, ASan/UBSan token-loop 14/14, 6-config -Werror
matrix, clean-room audit 0 errors.
…ove on Tensor G6
- [P2] EdgeTPU x dmabuf_fd x fenced execution is refused before dispatch.
nnapi_fenced_dmabuf_block_reason() gates NnEdgeTpu::start() before any
NNAPI call and skips sync_file_poll / r_iif with
nnapi_fenced_dmabuf_unavailable_on_edgetpu. Both --nnapi-mem dmabuf and
the automatic AHB -> dmabuf_fd fallback import the pool DMA-BUFs for the
GPU only (never into NNAPI). --allow-edgetpu-dmabuf-fenced-probe is the
debug-only opt-in. Host mock test (NnEdgeTpu test seam) proves no
exec_start_deps_ / event_from_fd_ call.
- [P3] poll_sync_fd() and FdWaiter call sync_fd_wait_handoff(): POLLIN
without POLLERR/POLLNVAL AND SYNC_IOC_FILE_INFO (0xc0383e04) status == 1.
Fence errors (< 0) and unsignaled (0) fail the hop. ENOTTY/EINVAL are
accepted only in an explicit mock mode. Live root test: an errored
/dev/iif bridged sync_file is POLLIN-readable with status -5 and is
rejected.
- [P3] The NNAPI submission timer starts after
ANeuralNetworksEvent_createFromSyncFenceFd. Dependency-event time is
reported as nnapi_dep_event_create_us_per_tok.
- [P3] Wrapped CTests pass CMAKE_CROSSCOMPILING_EMULATOR through:
-DEMULATOR= for ctest_run_expect.cmake and --emulator-arg= for
token_loop_json_check.py. Proven with '/usr/bin/env;--', a logging
emulator and a rejecting emulator.
Proof packet regenerated from one binary (sha256 3982f148...) under the
exclusive adb lock on Pixel 11 Pro XL:
- L=12 T=64 d in {512,1024,2048}: all 9 cells pass.
- W8A16, the negatives and --iif-probe-only receipts are regenerated.
- New --nnapi-mem dmabuf guard receipt: fenced arms skipped, 0 exec starts,
HAL pids unchanged.
- New uid-shell smoke receipt.
- On-device unit test transcripts (shell and root).
Host ctest 56/56, ASan/UBSan token-loop 14/14 (halt_on_error), 6-config
-Werror matrix, clean-room audit 0 errors.
…ove on Tensor G6 [P2] Drain failed GPU work before running the next arm - Every fs_iova_pool submission is recorded in an executor ledger until its fence retires. After a failed arm, Executor::recover_after_failure() proves every engine idle (vkDeviceWaitIdle == VK_SUCCESS, no unreleased NNAPI hop, no open IIF fence), then retires the leftover submissions and requires every pool slot IDLE. Otherwise the executor is tainted and every later arm is skipped (executor_tainted) before run_token() writes SLOT_X. A successful arm that leaves work in flight is failed and recovered the same way. - JSON: executor_state and per-arm recovery (drained_retired | tainted). - Mock test seam --fault-inject-gpu-fence / --fault-inject-quiesce-fail (rejected with --live); CTest volcanic_tpu_token_loop_bench_failure_recovery. [P3] Keep mock runs out of the kernel IIF driver - iif_probe() runs only for --live and --iif-probe-only; --mock reports probe.probed=false (not_probed_mock); iif.dev_open_calls counts opens. - Pixel 11 root --mock runs: 0 inotify open events on /dev/iif (probe-only positive control sees the open). CTest ..._mock_never_opens_iif. [P3] Validate the ODPM energy conversion factor - All numeric options use fs_tokloop::parse_strict_* (whole-argument parse, ERANGE/NaN/Inf rejected, unsigned values reject signs, ranges enforced); malformed values exit 2. No atoi/atof/atol remain in the bench. - test_strict_cli_parsing, CTest ..._strict_args_exit2 and WILL_FAIL cases for the U+2212 minus, 0, nan conversion factors and --layers 12x. [P3] Reconcile the receipt with its raw results - scripts/token_loop_capture.py captures every raw file from ONE binary under one exclusive adb lock and writes session.json (per-run argv, uid, exit codes, device binary SHA-256 before each run, stdout SHA-256, health). - scripts/token_loop_receipt.py write generates every measured receipt key and PROOF.md table from the raw files; check (CTest token_loop_proof_receipt_reconciled) fails on any stale value, hash mismatch, second binary, unexpected exit or measured number in prose. - An intermittent r_iif parity failure (d=1024, earlier session of the same binary) is kept under observed-failures/ and documented as an open issue.
…ove on Tensor G6 [P2] Drain libopenbuenos before reusing shared tensor slots - LiveExecutor::quiesce() drains any active ob_context_t via ob_graph_wait_all(ob_, 0u) under FREESCHED_HAVE_LIBOPENBUENOS and fails closed (tainting the executor before any in-flight pool slot is retired) if the drain does not return OB_OK. [P2] Require a newly created directory before recursive device cleanup - scripts/token_loop_capture.py normalizes --device-dir with posixpath.normpath, enforces a single safe child directly under /data/local/tmp, creates it exclusively with mkdir -- (without -p), and enables rm -rf -- cleanup only after mkdir exits 0. [P3] Fail health capture when device logs cannot be read - Device.text() checks command exit codes by default; pre- and post-run dmesg and logcat -b crash -d read failures abort capture and session.json records their exit codes (checked by token_loop_receipt.py check). [P3] Fail capture when an on-device unit test exits unsuccessfully - session.json records each on-device unit test exit_code and pass banner; overall_ok and the capture exit code require all unit tests to pass, and token_loop_receipt.py check reconciles them with unit-test-device.txt. [P3] Require raw output for each recorded unexpected exit - scripts/token_loop_receipt.py requires every archived observed-failures/ manifest entry with an unexpected exit or failed pass state to have its raw output present on disk matching stdout_sha256 in both write and check; successful runs remain manifest-only. - CTest token_loop_proof_scripts_unit tests all four script fixes.
Fail the proof health gate on kernel faults, crashes, and HAL restarts. Distinguish mock pipe waits from kernel sync_file ioctls, validate negative runs and receipts before replace, and resolve the host NDK compiler. Release imported IIF gates before idle waits, recreate a signaled export semaphore after a failed SYNC_FD export, and report unmeasured NNAPI hardware time as null.
W8A16 sync_file_poll waits on FdWaiter, but only the NNAPI setup started that thread. The live CPU-backend arm blocked forever on the first hop.
Refresh the Pixel 11 Pro XL capture after the Generation 8 fence, health-gate, and NNAPI timing repairs. The W8A16 sync_file waiter thread starts, and the unprivileged shell unit test passes.
Stage capture outputs outside --out until overall_ok passes, switch crash log detection to a device-clock logcat -T cursor, validate non-empty numeric HAL PIDs and pidof exit status in both capture and receipt check, verify distinct arm64 CMake configurations and rebuild targets in host-verify, keep NNAPI/Vulkan fence timeout recovery bounded without unbounded waits, and count NNAPI completion polling once in host_wait_us.
Refresh the Pixel 11 Pro XL capture and host-verification receipt after the Generation 9 staged-capture, logcat -T crash-cursor, HAL PID validation, arm64 matrix verification, bounded fence-timeout recovery, and sync_file_poll host_wait_us fixes.
…, and preserve abandoned NNAPI objects
…e, NNAPI pin & feature-level guard, compile ASan/UBSan verify)
…ile SELinux context
Label shell-tmp with chcon before chown, fail the IIF watch if inotifyd dies, reject mismatched sweep dimensions and cached ODPM samples, rebuild host and ASan trees before recording passes, and pin --tpu-backend nnapi in the proof reproduction command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Multi-layer GPU <-> EdgeTPU transformer token decode loop with three fence-handoff arms (
host_staged,sync_file_poll,r_iif), thegoogle,iif/dev/iifUAPI, an NNAPI EdgeTPUQUANT8_ASYMM1x1CONV_2Dbackend, and a live on-silicon proof on a Pixel 11 Pro XL (Tensor G6, PowerVR C-Series CXTP-48-1536 + Google EdgeTPU).Commits:
81aee80multi-layer token decode loop + 3 sync arms, ODPM J/tok, ctx-switch sampling, FP64 parity.8b07943google,iifUAPI + NNAPI EdgeTPU QUANT8 backend, zero-copy AHB tensors, FP32<->QUANT8 bridge shaders.7e2fb44fixes for three issues found on live silicon, plus the proof packet.966644efixes for the 6 Generation 1 autoreview findings.7a840c0fixes for the 4 Generation 2 autoreview findings.f11274afixes for the 6 Generation 3 autoreview findings.b49b564fixes for the 4 Generation 4 autoreview findings.f330390fixes for the 4 Generation 5 autoreview findings, with the proof packet regenerated on this head.Live-silicon fixes (
7e2fb44)AHardwareBuffer_lock+ read/write of a shared tensor inhost_stagedcorrupted later zero-copy handoffs (sync_file_pollcos 0.16-0.48,r_iif0.57-0.88; each arm alone passed).host_stagednow uses its own CPU-visible AHB bridge tensors and command buffers.sync_files.anon_inode:iif_filefds are pollable but failSYNC_IOC_FILE_INFO(ENOTTY), so VulkanSYNC_FDimport rejected ther_iifgate.IifFences::bridge_sync_file()usesFS_IIF_FENCE_BRIDGE_DMAto get a realsync_file(validated), whichr_iifimports.dlclose(libneuralnetworks.so)crashed runtime worker threads at exit; the handle is no longer closed.Review repairs (
966644e)host_stagedbridge sets.VkBufferMemoryBarrierqueue-family release/acquire around every GPU <-> EdgeTPU tensor. UsesVK_QUEUE_FAMILY_FOREIGN_EXT(enabled on PowerVR CXTP-48-1536). TheVK_QUEUE_FAMILY_EXTERNALfallback was removed in7a840c0.--require-iif: requiresr_iifto have run with measured IIF fences > 0, and live runs need the kernel/dev/iifbackend. A live--iif-sw-fallback --require-iifrun now exits 1 (requirement_met=false). Covered by a unit test and a CTest.host_stagedisolation: fails closed (host_staged_isolated_staging_unavailable) instead of CPU-accessing the zero-copy tensors.ANeuralNetworksEvent_waitis checked for every fenced hop (12/token insync_file_pollandr_iif) before the event is freed.sync_file_poll: the TPU fence is exported viaDMA_BUF_IOCTL_EXPORT_SYNC_FILEandpoll()ed before the next GPU submit. A failed export fails the hop. Live W8A16 run: 24 polls and 24 exports per token.Review repairs, Generation 2 (
7a840c0)run_tpumarks(void)c.-Wall -Wextra -Werrorcompile matrix passes:arm64-v8awith and withoutlibopenbuenos(Vulkan headers on), non-Android Linux-fsyntax-onlywith and withoutFREESCHED_HAVE_LIBOPENBUENOS, and the macOS host. The parent head also compiled without libopenbuenos (the fenced CPU path still usedc), so this guard is defensive.vkQueueSubmitwait semaphore usesVK_PIPELINE_STAGE_ALL_COMMANDS_BIT, because each command buffer starts with a foreign -> compute queue-family acquire of EdgeTPU-written tensors.VK_QUEUE_FAMILY_EXTERNALfallback is gone. WithoutVK_EXT_queue_family_foreign, theopenbuenos/nnapibackends report the GPU <-> EdgeTPU zero-copy path unavailable.--tpu-backend cpu(host-only DMA-BUF access) keeps tensors on the compute queue family, records no transfer, and reportsqueue_family = none_host_only.--live --tpu-backend cpu, the fenced arms now count theirstage_in_/stage_out_copies. Live W8A16 run: 24 host copies/token (2L) on every arm, previously 0 onsync_file_poll/r_iif.Review repairs, Generation 3 (
f11274a)IifProbe::bridge_dma_okis true only ifFS_IIF_FENCE_BRIDGE_DMAreturns async_filethat signals onpoll(). It is recorded separately from raw/dev/iifusability. Raw kernel IIF stays available for the CPU-proxy handoffs. The NNAPI arm enables its Vulkan gate only withbridge_dma_ok; otherwise it runs the ungated sync-fence chain with 0 IIF fences, which--require-iifstill rejects. Live check with--iif-ioctl-bridge 0x8004697f(ENOTTY): the run passes ungated (exit 0) and fails with--require-iif(exit 1). Covered by the new unit testtest_iif_raw_without_bridge, which also runs the live probe as root.userspace_wakeupsnow counts only cross-thread wakeups from the NNAPIsync_file_pollwaiter. Inline polls on the submitting thread count only as fence polls: the CPU-proxy IIF handoff, the mock round trip and--tpu-backend cpu. Regenerated W8A16 receipt: 0 wakeups/token on every arm (24 / 36 polls).reference_tokenis an unquantized FP64 float-activation baseline: it skips both activation quantization steps. Thecos >= 0.995gate (0.999264-0.999396 measured) therefore checks end-to-end agreement with that baseline, including INT8 activation quantization error.arms_max_abs_diff = 0checks that the three arms produce identical quantized outputs.PASS_REGULAR_EXPRESSION, because it makes CTest ignore the exit code. The d2048 smoke uses the exit code, and content checks go throughtests/ctest_run_expect.cmake, which requires exit 0 and a match. A new negative test covers the case where nested arms pass but--require-iiffails the run. In a scratch CTest project, the old regex passed that failing run.$TMPDIR, then/data/local/tmp, then/tmp. The test passes from an unprivilegedadb shell, with and withoutTMPDIR.json_finite_or_null(), soinf/nanare emitted asnullandpassstays false. Covered by a unit test and a strictpython3JSON CTest.Review repairs, Generation 4 (
b49b564)[P2] The IOVA proof tracks the actual NNAPI handoff buffers. Each stage submits the pool slots it actually touches:
mid(l)/out(l)writes;dmabuf_fdmode, the EdgeTPU's QUANT8qmid/qoutpool slots, including in ther_iifchain.No EdgeTPU submission is attributed to an FP32 slot any more. In
AHardwareBuffermode (the live Tensor G6 path) the JSON reportsiova_observation_scope = "vulkan_pool_only_nnapi_ahb_external",ahb_hot_loop_allocs = 0andnnapi_ahb_memories_registered_before_hot_loop = 4;dmabuf_fdreportsfull_pool_dmabuf. Scope: in AHB mode,hot_loop_map_count == 0proves zero hot-loop maps only on thefs_iova_poolVulkan buffers. The NNAPIAHardwareBuffers are pre-registered once withANeuralNetworksMemory_createFromAHardwareBufferbefore hot-loop entry. Their driver-internal gralloc/NNAPI mappings are outside userspace pool observation.A failed NNAPI hop now retires its QUANT8 slots once it is drained, so the next arm no longer reports a misleading
pool submit(chain) rejected.[P2] The CPU W8A16 output hop is synchronous. With
--tpu-backend cpu, the CPU writesY[l]inside itsDMA_BUF_IOCTL_SYNCbracket before the handoff, so there is no producer fence. The hop is no longer exported and polled (sync_file_poll) or proxied through an IIF (r_iif); it counts insynchronous_cpu_hops_per_tok. Live W8A16 receipt:fence_handoffs_per_tok = 12(GPU -> CPU VulkanSYNC_FD) andsynchronous_cpu_hops_per_tok = 12for both fenced arms (previously 24 fenced handoffs).[P3] Consistent synchronization timing.
sync_us_per_tokis replaced by two fields with identical interval definitions in every arm:host_wait_us_per_tok:poll()/waiter wait,vkWaitForFences,vkQueueWaitIdleIIF-gate drain,ANeuralNetworksEvent_waitand the/dev/iifwait; submission calls are excluded.dispatch_submit_us_per_tok:vkQueueSubmit+startComputeWithDependenciesonly.The
r_iifwhole-chain duration is reported separately aspipelined_chain_us_per_tok, which isnullfor arms without a pipelined chain.[P3] Every JSON string is escaped.
--iif-devand the probe reason go throughfs_tokloop::json_escape()in the newiif_probe_json(), as does every other JSON string value, including the user-suppliedtpu_backend_requested. No raw"%s"string fields remain. Coverage:test_json_escape("/tmp/iif\"\\test"plus control characters);python3JSON CTest of that probe document;--iif-probe-only --iif-dev '/tmp/iif"\test';iif-probe-only-hostile-dev.jsonreceipt.Review repairs, Generation 5 (
f330390)[P2] Fenced DMA-BUF execution is disabled on the affected EdgeTPU driver. An EdgeTPU device (name contains
edgetpu) withdmabuf_fdshared memory is refused before dispatch:NnEdgeTpu::start()returns before any NNAPI call: no execution, no dependency event, nostartComputeWithDependencies.sync_file_pollandr_iifare skipped withnnapi_fenced_dmabuf_unavailable_on_edgetpu.--nnapi-mem dmabufand the automatic AHB ->dmabuf_fdfallback reach this guard. The pool DMA-BUFs are then imported for the GPU only and never into NNAPI.--allow-edgetpu-dmabuf-fenced-probeis a debug-only opt-in. It was not run.nnapi.fenced_dmabuf_policy,allow_edgetpu_dmabuf_fenced_probe,fenced_dmabuf_refusals,exec_start_calls.Test:
test_nnapi_edgetpu_dmabuf_fenced_guarddrives the sharedstart()path through a host-onlyNnEdgeTputest seam with counting mocks.google-edgetpu+dmabufis refused with and without a dependency fd and never callsexec_start_deps_orevent_from_fd_; AHB memory and the debug probe dispatch once.Live receipt
edgetpu-dmabuf-fenced-blocked-L4-T8-d512.json: fenced arms skipped,exec_start_calls = 0,host_stagedpassed, NNAPI EdgeTPU HAL pids unchanged (9820 9829), crash buffer empty.[P3] Sync-file status is checked before producer output is consumed.
poll_sync_fd()andFdWaiterboth callsync_fd_wait_handoff(), which requires:POLLINwithoutPOLLERR/POLLNVAL;SYNC_IOC_FILE_INFO(0xc0383e04;struct sync_file_infois 56 bytes on every ABI, checked by static_assert) withstatus == 1.status < 0(fence error) and0(unsignaled) fail the hop.ENOTTY/EINVALfail every live handoff and are accepted only in an explicit mock mode for pipe/eventfd stand-ins. Under SELinuxEACCESthe check fails closed.Live root test on the Pixel: an AP IIF fence signaled with
-EIOand bridged withFS_IIF_FENCE_BRIDGE_DMAisPOLLIN-readable, butSYNC_IOC_FILE_INFO.status = -5, so the handoff is rejected. The clean bridge reportsstatus = 1and is accepted. Unit table:-EIO,-ECANCELED, 0,POLLERR,POLLNVAL, timeout,ENOTTY/EINVALkernel vs. mock, real pipe.[P3] The NNAPI submission timer starts after dependency setup. The timer now starts immediately before
startComputeWithDependencies, afterANeuralNetworksEvent_createFromSyncFenceFd.nnapi_start_block_us_per_tokanddispatch_submit_us_per_toktherefore time the same call in both fenced arms. Dependency-event creation is reported asnnapi_dep_event_create_us_per_tok(liver_iif: 17.4 / 20.0 / 21.1 us/token). Mock check: a 30 msevent_from_fdgivesblock_usof about 0.2.[P3] Wrapped CTest cases use the configured emulator. When
CMAKE_CROSSCOMPILINGis on andCMAKE_CROSSCOMPILING_EMULATORis set, the emulator list is passed through:-DEMULATOR=totests/ctest_run_expect.cmake, which prepends it toCMD;--emulator-arg=<arg>per element totests/token_loop_json_check.py, which prepends it to every launched target.Scratch proof (
CMAKE_SYSTEM_NAME=Darwin):"/usr/bin/env;--": 14/14 token-loop tests pass.Live results (L=12, T=64,
--min-cos 0.995, kernel IIF gate withbridge_dma_ok; rerun onf330390)host_stagedsync_file_pollr_iifhost_stagedsync_file_pollr_iifhost_stagedsync_file_pollr_iifm= mJ. Every cell passes parity (cos vs. the unquantized FP64 float-activation baseline;arms_max_abs_diff = 0).hot_loop_map_count == hot_loop_unmap_count == 0on thefs_iova_poolbuffers (AHB scope as above), withtotal_submissions == completed_drains == 3536.r_iifuses 1 IIF fence + 13 importedsync_files per token and 0 userspace polls. Its pipelined chain takes 12.5 / 18.0 / 73.9 ms per token.r_iifreaches 1.82x / 1.76x / 1.27x thehost_stagedtok/s and uses 40% / 38% / 17% less VSYS energy per token. Everysync_file_pollhop (24/token) now also passes theSYNC_IOC_FILE_INFO.status == 1check. Remaining headroom:startComputeWithDependenciesblocks for 7.0-9.3 ms/token inside the NNAPI runtime (submission call only), which accounts for most ofr_iif's dispatch time. Results are within run-to-run noise of theb49b564run. Binary SHA-256:3982f148d96f79dcc080b5f8ff4edce7205145d29664e3c87ca546bbfde48fc5(arm64-v8a, NDK r27,android-35,libopenbuenosstatic).Full details:
proof/tensor-g6-gpu-edgetpu-riif-token-loop/PROOF.mdandreceipt.json.Verification
ctest --output-on-failure: 56/56 PASS.ctestwithhalt_on_error=1: all 14 token-loop tests clean; 54/56 overall. The 2 failures (test_c11_abi,test_freesched) are a pre-existing UBSan enum load insrc/fs_topology.cpp:557, which this PR does not touch.CMAKE_CROSSCOMPILING_EMULATOR="/usr/bin/env;--"gives token-loop 14/14 PASS. A logging emulator sees all 14 launches, and a rejecting emulator fails them.-Wall -Wextra -Werrorcompile matrix (6 configs): PASS for:arm64-v8awith and withoutlibopenbuenos;-fsyntax-onlycheck of the bench with and without it, plus the unit test;test_token_loop_riifcross-compiled forarm64-v8aand run on the device:adb shell, with and withoutTMPDIR): PASS.status = -5, rejected; clean bridgestatus = 1, accepted) and the raw-IIF-without-bridge probe../scripts/clean-room-audit.sh: PASS (0 errors across 237 files)../scripts/audit-no-async-ring.sh: PASS.flockon/tmp/kodiak-pixel11-adb.lock):--nnapi-mem dmabufguard run;/data/local/tmp/fs59g5removed (0 remaining);/data/local/tmpentries that predate the session were left untouched.