Skip to content

feat(bench): live Tensor G6 GPU<->EdgeTPU multi-layer token loop with r_iif fence chain - #59

Merged
saariuslystoned merged 25 commits into
mainfrom
feat/kodiak-riif-multilayer-token-loop
Dec 4, 2026
Merged

saariuslystoned merged 25 commits into
mainfrom
feat/kodiak-riif-multilayer-token-loop

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Multi-layer GPU <-> EdgeTPU transformer token decode loop with three fence-handoff arms (host_staged, sync_file_poll, r_iif), the google,iif /dev/iif UAPI, an NNAPI EdgeTPU QUANT8_ASYMM 1x1 CONV_2D backend, and a live on-silicon proof on a Pixel 11 Pro XL (Tensor G6, PowerVR C-Series CXTP-48-1536 + Google EdgeTPU).

Commits:

  • 81aee80 multi-layer token decode loop + 3 sync arms, ODPM J/tok, ctx-switch sampling, FP64 parity.
  • 8b07943 google,iif UAPI + NNAPI EdgeTPU QUANT8 backend, zero-copy AHB tensors, FP32<->QUANT8 bridge shaders.
  • 7e2fb44 fixes for three issues found on live silicon, plus the proof packet.
  • 966644e fixes for the 6 Generation 1 autoreview findings.
  • 7a840c0 fixes for the 4 Generation 2 autoreview findings.
  • f11274a fixes for the 6 Generation 3 autoreview findings.
  • b49b564 fixes for the 4 Generation 4 autoreview findings.
  • f330390 fixes for the 4 Generation 5 autoreview findings, with the proof packet regenerated on this head.

Live-silicon fixes (7e2fb44)

  1. Zero-copy tensors are device-only. A CPU AHardwareBuffer_lock + read/write of a shared tensor in host_staged corrupted later zero-copy handoffs (sync_file_poll cos 0.16-0.48, r_iif 0.57-0.88; each arm alone passed). host_staged now uses its own CPU-visible AHB bridge tensors and command buffers.
  2. IIF fence fds are not sync_files. anon_inode:iif_file fds are pollable but fail SYNC_IOC_FILE_INFO (ENOTTY), so Vulkan SYNC_FD import rejected the r_iif gate. IifFences::bridge_sync_file() uses FS_IIF_FENCE_BRIDGE_DMA to get a real sync_file (validated), which r_iif imports.
  3. NNAPI runtime stays resident. dlclose(libneuralnetworks.so) crashed runtime worker threads at exit; the handle is no longer closed.

Review repairs (966644e)

  1. Descriptor pool: budgets 6 sets / 24 storage-buffer descriptors per layer, including the isolated host_staged bridge sets.
  2. Ownership transfers: explicit VkBufferMemoryBarrier queue-family release/acquire around every GPU <-> EdgeTPU tensor. Uses VK_QUEUE_FAMILY_FOREIGN_EXT (enabled on PowerVR CXTP-48-1536). The VK_QUEUE_FAMILY_EXTERNAL fallback was removed in 7a840c0.
  3. --require-iif: requires r_iif to have run with measured IIF fences > 0, and live runs need the kernel /dev/iif backend. A live --iif-sw-fallback --require-iif run now exits 1 (requirement_met=false). Covered by a unit test and a CTest.
  4. host_staged isolation: fails closed (host_staged_isolated_staging_unavailable) instead of CPU-accessing the zero-copy tensors.
  5. NNAPI status: ANeuralNetworksEvent_wait is checked for every fenced hop (12/token in sync_file_poll and r_iif) before the event is freed.
  6. W8A16 sync_file_poll: the TPU fence is exported via DMA_BUF_IOCTL_EXPORT_SYNC_FILE and poll()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)

  1. [P1] Builds without libopenbuenos: run_tpu marks (void)c. -Wall -Wextra -Werror compile matrix passes: arm64-v8a with and without libopenbuenos (Vulkan headers on), non-Android Linux -fsyntax-only with and without FREESCHED_HAVE_LIBOPENBUENOS, and the macOS host. The parent head also compiled without libopenbuenos (the fenced CPU path still used c), so this guard is defensive.
  2. [P2] Wait stage for the ownership acquire: every vkQueueSubmit wait semaphore uses VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, because each command buffer starts with a foreign -> compute queue-family acquire of EdgeTPU-written tensors.
  3. [P2] Foreign queue family required: the VK_QUEUE_FAMILY_EXTERNAL fallback is gone. Without VK_EXT_queue_family_foreign, the openbuenos / nnapi backends 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 reports queue_family = none_host_only.
  4. [P3] CPU backend host copies: with --live --tpu-backend cpu, the fenced arms now count their stage_in_ / stage_out_ copies. Live W8A16 run: 24 host copies/token (2L) on every arm, previously 0 on sync_file_poll / r_iif.

Review repairs, Generation 3 (f11274a)

  1. [P2] NNAPI IIF gate needs a working bridge: IifProbe::bridge_dma_ok is true only if FS_IIF_FENCE_BRIDGE_DMA returns a sync_file that signals on poll(). It is recorded separately from raw /dev/iif usability. Raw kernel IIF stays available for the CPU-proxy handoffs. The NNAPI arm enables its Vulkan gate only with bridge_dma_ok; otherwise it runs the ungated sync-fence chain with 0 IIF fences, which --require-iif still 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 test test_iif_raw_without_bridge, which also runs the live probe as root.
  2. [P2] Wakeup accounting: userspace_wakeups now counts only cross-thread wakeups from the NNAPI sync_file_poll waiter. 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).
  3. [P2] Parity description: reference_token is an unquantized FP64 float-activation baseline: it skips both activation quantization steps. The cos >= 0.995 gate (0.999264-0.999396 measured) therefore checks end-to-end agreement with that baseline, including INT8 activation quantization error. arms_max_abs_diff = 0 checks that the three arms produce identical quantized outputs.
  4. [P3] CTest checks the overall result: the token-loop tests no longer use PASS_REGULAR_EXPRESSION, because it makes CTest ignore the exit code. The d2048 smoke uses the exit code, and content checks go through tests/ctest_run_expect.cmake, which requires exit 0 and a match. A new negative test covers the case where nested arms pass but --require-iif fails the run. In a scratch CTest project, the old regex passed that failing run.
  5. [P3] Android temp dir: test fixtures try $TMPDIR, then /data/local/tmp, then /tmp. The test passes from an unprivileged adb shell, with and without TMPDIR.
  6. [P3] Valid JSON: every floating JSON field goes through json_finite_or_null(), so inf/nan are emitted as null and pass stays false. Covered by a unit test and a strict python3 JSON CTest.

Review repairs, Generation 4 (b49b564)

  1. [P2] The IOVA proof tracks the actual NNAPI handoff buffers. Each stage submits the pool slots it actually touches:

    • the GPU's FP32 mid(l) / out(l) writes;
    • in dmabuf_fd mode, the EdgeTPU's QUANT8 qmid / qout pool slots, including in the r_iif chain.

    No EdgeTPU submission is attributed to an FP32 slot any more. In AHardwareBuffer mode (the live Tensor G6 path) the JSON reports iova_observation_scope = "vulkan_pool_only_nnapi_ahb_external", ahb_hot_loop_allocs = 0 and nnapi_ahb_memories_registered_before_hot_loop = 4; dmabuf_fd reports full_pool_dmabuf. Scope: in AHB mode, hot_loop_map_count == 0 proves zero hot-loop maps only on the fs_iova_pool Vulkan buffers. The NNAPI AHardwareBuffers are pre-registered once with ANeuralNetworksMemory_createFromAHardwareBuffer before 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.

  2. [P2] The CPU W8A16 output hop is synchronous. With --tpu-backend cpu, the CPU writes Y[l] inside its DMA_BUF_IOCTL_SYNC bracket 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 in synchronous_cpu_hops_per_tok. Live W8A16 receipt: fence_handoffs_per_tok = 12 (GPU -> CPU Vulkan SYNC_FD) and synchronous_cpu_hops_per_tok = 12 for both fenced arms (previously 24 fenced handoffs).

  3. [P3] Consistent synchronization timing. sync_us_per_tok is replaced by two fields with identical interval definitions in every arm:

    • host_wait_us_per_tok: poll()/waiter wait, vkWaitForFences, vkQueueWaitIdle IIF-gate drain, ANeuralNetworksEvent_wait and the /dev/iif wait; submission calls are excluded.
    • dispatch_submit_us_per_tok: vkQueueSubmit + startComputeWithDependencies only.

    The r_iif whole-chain duration is reported separately as pipelined_chain_us_per_tok, which is null for arms without a pipelined chain.

  4. [P3] Every JSON string is escaped. --iif-dev and the probe reason go through fs_tokloop::json_escape() in the new iif_probe_json(), as does every other JSON string value, including the user-supplied tpu_backend_requested. No raw "%s" string fields remain. Coverage:

    • unit test test_json_escape ("/tmp/iif\"\\test" plus control characters);
    • a strict python3 JSON CTest of that probe document;
    • a bench CTest for --iif-probe-only --iif-dev '/tmp/iif"\test';
    • the on-device iif-probe-only-hostile-dev.json receipt.

Review repairs, Generation 5 (f330390)

  1. [P2] Fenced DMA-BUF execution is disabled on the affected EdgeTPU driver. An EdgeTPU device (name contains edgetpu) with dmabuf_fd shared memory is refused before dispatch:

    • NnEdgeTpu::start() returns before any NNAPI call: no execution, no dependency event, no startComputeWithDependencies.
    • sync_file_poll and r_iif are skipped with nnapi_fenced_dmabuf_unavailable_on_edgetpu.
    • Both --nnapi-mem dmabuf and the automatic AHB -> dmabuf_fd fallback reach this guard. The pool DMA-BUFs are then imported for the GPU only and never into NNAPI.
    • --allow-edgetpu-dmabuf-fenced-probe is a debug-only opt-in. It was not run.
    • JSON: nnapi.fenced_dmabuf_policy, allow_edgetpu_dmabuf_fenced_probe, fenced_dmabuf_refusals, exec_start_calls.

    Test: test_nnapi_edgetpu_dmabuf_fenced_guard drives the shared start() path through a host-only NnEdgeTpu test seam with counting mocks. google-edgetpu + dmabuf is refused with and without a dependency fd and never calls exec_start_deps_ or event_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_staged passed, NNAPI EdgeTPU HAL pids unchanged (9820 9829), crash buffer empty.

  2. [P3] Sync-file status is checked before producer output is consumed. poll_sync_fd() and FdWaiter both call sync_fd_wait_handoff(), which requires:

    • POLLIN without POLLERR/POLLNVAL;
    • SYNC_IOC_FILE_INFO (0xc0383e04; struct sync_file_info is 56 bytes on every ABI, checked by static_assert) with status == 1.

    status < 0 (fence error) and 0 (unsignaled) fail the hop. ENOTTY/EINVAL fail every live handoff and are accepted only in an explicit mock mode for pipe/eventfd stand-ins. Under SELinux EACCES the check fails closed.

    Live root test on the Pixel: an AP IIF fence signaled with -EIO and bridged with FS_IIF_FENCE_BRIDGE_DMA is POLLIN-readable, but SYNC_IOC_FILE_INFO.status = -5, so the handoff is rejected. The clean bridge reports status = 1 and is accepted. Unit table: -EIO, -ECANCELED, 0, POLLERR, POLLNVAL, timeout, ENOTTY/EINVAL kernel vs. mock, real pipe.

  3. [P3] The NNAPI submission timer starts after dependency setup. The timer now starts immediately before startComputeWithDependencies, after ANeuralNetworksEvent_createFromSyncFenceFd. nnapi_start_block_us_per_tok and dispatch_submit_us_per_tok therefore time the same call in both fenced arms. Dependency-event creation is reported as nnapi_dep_event_create_us_per_tok (live r_iif: 17.4 / 20.0 / 21.1 us/token). Mock check: a 30 ms event_from_fd gives block_us of about 0.2.

  4. [P3] Wrapped CTest cases use the configured emulator. When CMAKE_CROSSCOMPILING is on and CMAKE_CROSSCOMPILING_EMULATOR is set, the emulator list is passed through:

    • '|'-joined as -DEMULATOR= to tests/ctest_run_expect.cmake, which prepends it to CMD;
    • one --emulator-arg=<arg> per element to tests/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.
    • A logging emulator records all 14 launches (3 CMake-wrapped, 4 Python-wrapped, 7 direct).
    • A rejecting emulator fails all 10 positive token-loop tests.

Live results (L=12, T=64, --min-cos 0.995, kernel IIF gate with bridge_dma_ok; rerun on f330390)

d arm tok/s ms/tok p50 ms/tok p99 vol. ctx-sw/tok userspace polls/tok cross-thread wakeups/tok host copies/tok cos GPU J/tok EdgeTPU J/tok VSYS J/tok host wait us/tok dispatch us/tok
512 host_staged 41.8 23.77 28.72 25.02 0 0 24 0.999396 1.441 m 1.110 m 95.4 m 8405 726
512 sync_file_poll 54.0 18.33 21.28 49.25 24 24 0 0.999396 1.259 m 0.940 m 76.3 m 8047 9920
512 r_iif 76.2 12.89 15.20 21.66 0 0 0 0.999396 1.078 m 0.756 m 57.6 m 2083 10418
1024 host_staged 30.3 32.81 36.85 25.17 0 0 24 0.999312 3.327 m 1.602 m 139.6 m 13263 677
1024 sync_file_poll 41.4 23.61 28.51 48.48 24 24 0 0.999312 3.022 m 1.264 m 104.5 m 13221 10336
1024 r_iif 53.2 18.52 20.51 26.61 0 0 0 0.999312 2.918 m 1.049 m 87.1 m 6646 11418
2048 host_staged 10.5 96.46 106.48 26.52 0 0 24 0.999264 18.500 m 4.630 m 421.6 m 64807 1237
2048 sync_file_poll 11.8 83.49 101.50 45.78 24 24 0 0.999264 18.079 m 4.321 m 385.5 m 70230 13965
2048 r_iif 13.4 74.18 82.50 43.05 0 0 0 0.999264 17.686 m 3.839 m 350.2 m 60813 13193

m = 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 == 0 on the fs_iova_pool buffers (AHB scope as above), with total_submissions == completed_drains == 3536. r_iif uses 1 IIF fence + 13 imported sync_files per token and 0 userspace polls. Its pipelined chain takes 12.5 / 18.0 / 73.9 ms per token. r_iif reaches 1.82x / 1.76x / 1.27x the host_staged tok/s and uses 40% / 38% / 17% less VSYS energy per token. Every sync_file_poll hop (24/token) now also passes the SYNC_IOC_FILE_INFO.status == 1 check. Remaining headroom: startComputeWithDependencies blocks for 7.0-9.3 ms/token inside the NNAPI runtime (submission call only), which accounts for most of r_iif's dispatch time. Results are within run-to-run noise of the b49b564 run. Binary SHA-256: 3982f148d96f79dcc080b5f8ff4edce7205145d29664e3c87ca546bbfde48fc5 (arm64-v8a, NDK r27, android-35, libopenbuenos static).

Full details: proof/tensor-g6-gpu-edgetpu-riif-token-loop/PROOF.md and receipt.json.

Verification

  • Host ctest --output-on-failure: 56/56 PASS.
  • ASan + UBSan ctest with halt_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 in src/fs_topology.cpp:557, which this PR does not touch.
  • Cross-compiling emulator (scratch): 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 -Werror compile matrix (6 configs): PASS for:
    • arm64-v8a with and without libopenbuenos;
    • the non-Android Linux -fsyntax-only check of the bench with and without it, plus the unit test;
    • the macOS host.
  • test_token_loop_riif cross-compiled for arm64-v8a and run on the device:
    • uid 2000 (adb shell, with and without TMPDIR): PASS.
    • root: PASS, including the live errored-bridge check (status = -5, rejected; clean bridge status = 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.
  • Device health gate (each session under one exclusive adb lock, flock on /tmp/kodiak-pixel11-adb.lock):
    • 0 GPU/Vulkan/EdgeTPU/IIF errors or faults; crash buffer empty in both sessions;
    • NNAPI EdgeTPU HAL pids identical throughout, including across the --nnapi-mem dmabuf guard run;
    • /data/local/tmp/fs59g5 removed (0 remaining); /data/local/tmp entries that predate the session were left untouched.

saariuslystoned and others added 25 commits December 2, 2026 17:55
…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.
…e, NNAPI pin & feature-level guard, compile ASan/UBSan verify)
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.
@saariuslystoned
saariuslystoned merged commit a3146a5 into main Dec 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant