Expand description
Persistent host mapping, decoupled from cache coherency.
map() fuses two separate concerns: establishing a host address, and
bracketing CPU access for coherency. Fusing them makes a whole class of
consumer impossible to express — TFLite’s SetCustomAllocationForTensor
and ONNX Runtime’s external tensors both retain a raw pointer for the
interpreter’s lifetime, far beyond any single access window
(#134).
The blocker is a borrow, not a lifetime: a map guard borrows the tensor,
while ImageProcessor::convert(&mut self, src, dst) needs &mut on that
same tensor every frame, and the two cannot coexist. So HostPin carries
no borrow of the tensor at all — it holds an Arc keepalive over the
memory instead, which is what lets a caller pin once and still mutate the
tensor in the frame loop.
IOSurface is the reference implementation this generalises: it already
separates “address of the surface” (IOSurfaceGetBaseAddress, stable) from
“CPU access window” (IOSurfaceLock), which is why the Apple path already
works and the DMA-BUF one does not.
Structs§
- HostPin
- A stable host address for a tensor’s data, valid until the pin is dropped.