2.4. Hooks define when asynchronous work is finished
A host call can return before a GPU, accelerator, or foreign task has completed. Stopping the clock
at that return would measure submission latency rather than completed work. SpanHooks lets an
adapter define the boundary without putting CUDA, PyTorch, or another runtime into the core
package:
prepare
start clock
run action
completeTiming
stop clock
enrich metadata
prepare creates adapter state before timing. completeTiming may synchronize the selected
runtime before the stop sample. enrich runs outside the measured interval and can attach allocator
or device counters. The metadata should name the timing convention because a synchronized device
span and an unsynchronized host-launch span answer different questions.
The hook does not expose the kernels or operators inside a foreign call. It gives the outer Lean application an honest completion boundary. PyTorch Profiler, Nsight, Perfetto, or another runtime-specific tool remains the right instrument when the question lies below that boundary.