Skip to content

Implement task executor thread donation. #5507

Closed as not planned
Closed as not planned

Description

@benvanik

#5501 prepares iree_hal_device_submit_and_wait and plumbs it down into iree_hal_task_queue_submit_and_wait:
image

There's two major things required to finish this work as intended: we need a wait_handle to pass to iree_task_executor_donate_caller derived from the submission signal semaphores and _donate_caller needs to actually be implemented.

The wait_handle can probably be obtained by acquiring a timepoint from the last signal semaphore of the last batch - though this may not be guaranteed by the API (maybe?) it's probably good enough to start. The advantage we have here is that all of this is strictly an optimization and if it returns a bit early that's fine.

Donation is a bit more involved but may require only minor trickery to setup a donated iree_task_worker_t with no backing thread that is used to process tasks. When the submit_and_wait issues its flush and calls iree_task_executor_coordinate this worker can be provided as current_worker to receive any immediately runnable tasks and then a pump loop similar to iree_task_worker_pump_until_exit can be used to drain the queues. This may take the form of a iree_task_worker_pump_until_ready(..., wait_handle, timeout).

The larger design question here is how much to share between the donated workers code path and the normal workers code path: if a simple loop try_steal_tasking work is enough then that may keep things much simpler at the cost of potential spurious thread wakeups. For example, if we flush and post work to another thread, request a wake of that thread, and then immediately steal the work from it the thread will have nothing todo once woken. This is likely still a win as overall latency will go way down and in anything but stupid simple programs (like ++i from HLO) the woken thread may already have more work waiting for it by the time it's ready also helping lower latency. The largest benefit would be avoiding the iree_task_post_batch_wake_workers that can take several us.

Activity

  1. added
    performance ⚡
    hal/cpu
    on Apr 18, 2021
  2. self-assigned this
    on Apr 18, 2021
  3. benvanik commented on Jun 22, 2022

    @benvanik
    CollaboratorAuthor

    Don't think we want this, given that it bypasses our controls and conflicts with multi-tenancy.

  4. moved this to Done in IREEon Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

hal/cpuperformance ⚡

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions