Repository navigation
Description
There's some important overlap with the HAL work required for semaphores and it would be good to get it nailed down in one go, mostly focused on how to best return wait handles that would be backed by HAL semaphores.
Getting a wait handle can be expensive and we want to avoid needing to materialize them until a system-level wait is requested. Idea is to have a ref-counted waitable token that can be polled via a vtable method or used to materialize an iree_wait_handle_t. HAL semaphores would implement this interface and use the underlying APIs for polling without needing to materialize the handle and perform API-specific exporting if required. Single waits could also be done via the vtable and allow for more efficient single-wait behavior (no need to export and multi-wait on a single handle).
Once we have this waitable type we can return that on the execution result with a special IREE_STATUS_DEFERRED (or something) status indicating that the caller needs to perform the wait. We already have resume_call but VM stack management and reconstructing the stack on resume is required. In this first pass we could ignore compiler-generated coroutines and focus only on native ones from the HAL letting us keep the resume behavior isolated to the HAL module. An idea would be to have an IREE_VM_STACK_FRAME_WAIT that retains the wait token for as long as the stack is live - a HAL method that wants to wait would push the wait frame and return all the way up to the caller. On resume the wait frame would be checked and if satisfied would pop the frame and resume execution in the caller. The bytecode dispatch needs to be reworked to allow the main dispatch method to run without external_enter. Native modules that call back into bytecode will need special handling but we don't do that anywhere today and can punt. The wait frame retains the wait token and so the execution result doesn't need to.
Phase 1 (no waiting, just suspend/resume):
- Make
vm.yielda terminator. - Add IREE_STATUS_* for indicating deferral/suspension/etc.
- Implement bytecode
vm.yieldto allow for testing. - Externalize stack entry from iree_vm_bytecode_dispatch to allow for resume_call.
- Add wait stack frame and
iree_vm_execution_result_tplumbing to surface wait sources. - Implement
iree_vm_invocation_tto manage the stack across yield points. - Plumb through execution result handling during invocation and checks.
Phase 2a (wait frame):
- HAL implementation of the wait frame entry for submit-and-wait (to start).
- Some tests with HAL integration.
Phase 2b (waitable tokens):
- Add
iree_vm_waitable_tiniree/vm/waitable.h. - Add
!vm.waitable(or something) andvm.await.all/anyops. - HAL implementation of the wait token routing to semaphores.
- Some tests with HAL integration.
Phase 3 (cleanup):
- Get tracing working with the fibers feature disabled (Support manual management of VM stack tracing zones. #9503)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
benvanik commentedon Jan 27, 2022
Depends on #4026.
benvanik commentedon May 27, 2022
Taking another look at this after iree_wait_source_t and iree_loop_t landed.
Enabling bytecode module coroutine begin/resume.
Enabling bytecode module coroutine begin/resume.
Enabling bytecode module coroutine begin/resume. (#9497)
Implementing coroutine semaphore/fence awaits.
Implementing coroutine semaphore/fence awaits.
Implementing coroutine semaphore/fence awaits.
Implementing coroutine semaphore/fence awaits.
Merge pull request #9754 from iree-org/benvanik-timepoint-to-hal
benvanik commentedon Oct 27, 2022
Calling this done for now.