Skip to content

Replacing hal.ex.submit_and_wait with queued operations and fences. - #9754

Merged
benvanik merged 17 commits into
mainfrom
benvanik-timepoint-to-hal
Aug 2, 2022
Merged

benvanik merged 17 commits into
mainfrom
benvanik-timepoint-to-hal

Conversation

@benvanik

@benvanik benvanik commented Jul 11, 2022 •

Copy link
Copy Markdown
Collaborator

Adding compiler/runtime support for lowering the asynchronous stream dialect ops into HAL ops, materializing a timeline (today just one but multiple in the future), and passing through to the runtime HAL module. This allowed for the removal of the existing placeholder submit_and_wait op and enables queue-ordered allocations to be implemented in the HAL.

This is likely not the final design but unblocks work on coroutines, queue-ordered allocations, webgpu, and plumbing fences through the user-facing API/native ABI. Future refinements may create overrides that use semaphores instead of fences to avoid fence heap allocations when not required, but for most single-function classic ML models once we plumb fences through the ABI no internal fences are required. The current timeline materialization also strictly orders all invocations where instead we should be able to elide those when there's no internal program state to protect.

Because the various HAL backends all need work (CUDA/ROCM in particular need massive work) nearly everything is synchronized exactly as it was before but now that synchronization happens in the IR we emit and we can selectively start supporting async per target.

Progress on #1285 (just need to put fences on the ABI!).
Progress on #8093 (added yieldable fence waits).
Progress on #9572 (added compiler/runtime glue for queue-ordered allocs).

@benvanik benvanik added compiler/dialects Relating to the IREE compiler dialects (flow, hal, vm) performance ⚡ Performance/optimization related work across the compiler and runtime hal/api IREE's public C hardware abstraction layer API cleanup 🧹 labels Jul 11, 2022
@benvanik
benvanik force-pushed the benvanik-timepoint-to-hal branch 3 times, most recently from 0a75695 to d6a8151 Compare July 11, 2022 19:00
@benvanik
benvanik force-pushed the benvanik-timepoint-to-hal branch 3 times, most recently from 6547ac4 to 2bd3437 Compare July 20, 2022 22:12
@benvanik benvanik changed the title Replacing hal.ex.submit_and_wait with proper queued operations and fences. Replacing hal.ex.submit_and_wait with queued operations and fences. Jul 20, 2022
@benvanik
benvanik force-pushed the benvanik-timepoint-to-hal branch from 2bd3437 to aa7c0de Compare July 21, 2022 01:42
@benvanik
benvanik requested a review from ScottTodd July 21, 2022 02:15
@benvanik
benvanik marked this pull request as ready for review July 21, 2022 02:15
@benvanik
benvanik force-pushed the benvanik-timepoint-to-hal branch from aa7c0de to cde102e Compare July 25, 2022 17:12

@ScottTodd ScottTodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome :)

This makes it possible to print information about Values consistently.
This will be used during stream->hal lowering as a placeholder for where
a program timeline is advanced. It's currently a placeholder for what
it'll need to be with multiple devices but fine for now.
Today with our single device and single queue usage there's only ever
one global timeline. In the future we can have independent timelines
based on device queues managed by stream partitioning.
@benvanik
benvanik force-pushed the benvanik-timepoint-to-hal branch from cde102e to 4e6397a Compare August 2, 2022 17:52
@benvanik

benvanik commented Aug 2, 2022 •

Copy link
Copy Markdown
Collaborator Author

I reworked the elide timepoints pass in Adding --iree-stream-elide-timepoints pass. to be simpler/support more cases (and have tests) - no major changes anywhere else and it's just simpler now (replaced nasty flaky fixed-point iteration algo with a single loop).

@benvanik
benvanik force-pushed the benvanik-timepoint-to-hal branch from 4e6397a to fb67161 Compare August 2, 2022 18:03
This runs as part of a fixed-point iteration alongside IPO and
canonicalization to allow us to fully propagate timepoint dependencies
across the program.
This is not going to work with the incomplete CUDA/ROCM backends :(
We want to support SCF here but it needs some reworking.
Pass needs to be rewritten to use data flow analysis.
This will allow the new async behavior to be selectively enabled for
targets that are known to support it.

Remove the stone of submit_and_wait... attach the stone of wait and
execute and wait.
It's possible for null fences to come in from external sources
or conditional globals.
@iree-github-actions-bot

Copy link
Copy Markdown
Contributor

Abbreviated Benchmark Summary

@ commit b1688f4991a9e22ac024902ac35ea737efeb03d3 (vs. base 29c6ab50d4565928fca557e2731dc1004bb90b36)

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV2 [fp32,imagenet] (TFLite) big-core,full-inference,default-flags with IREE-Dylib-Sync @ Pixel-6-Pro (CPU-ARMv8.2-A) 24.597 (vs. 26.816, 8.27%↓) 24.633 0.211
MobileNetV3Small [fp32,imagenet] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 10.455 (vs. 11.134, 6.10%↓) 10.412 0.147
MobileSSD [fp32] (TFLite) full-inference,default-flags with IREE-Vulkan @ Pixel-6-Pro (GPU-Mali-G78) 43.504 (vs. 46.274, 5.99%↓) 43.583 0.625

[Top 3 out of 5 results showed]

No improved or regressed compilation metrics 🏖️

For more information:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup 🧹 compiler/dialects Relating to the IREE compiler dialects (flow, hal, vm) hal/api IREE's public C hardware abstraction layer API performance ⚡ Performance/optimization related work across the compiler and runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants