Enable Mult-exit Unrolling For Jetstream 3 Benchmarking
Categories
(Core :: JavaScript Engine, enhancement, P4)
Tracking
()
People
(Reporter: koenigseggcc, Assigned: koenigseggcc)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 1 external file)
|
7.17 KB,
text/plain
|
Details |
Steps to reproduce:
Added code to unroll multi-exit loops: UNROLL_DUMP=1 UNROLL_MULTIEXIT_EXITING=1 ./mach run
Actual results:
Partial compatibility (some crashes still)
Expected results:
Full test suite pass + full jit-test pass
Creating a ticket as requested in https://matrix.to/#/!CZEbuMfGYVdQMIBKeP:mozilla.org/$mhfayqH-WqrudjvuPavE6SF74CTSjvU6GsnP7OyVhmc?via=mozilla.org&via=igalia.com
Initial commit. Features disabled by default, and can be enabled
through about:config.
Updated•5 months ago
|
js-tests do not fully pass, nor does Jetstream 3. This is to get initial feedback as discussed on Matrix.
Updated•5 months ago
|
Updated•5 months ago
|
Comment 4•5 months ago
|
||
The question of multi-exit loops was investigated in bug 1959091, in which a
possible approach was suggested. This was not followed up because the
complexity-vs-potential-perf-improvement ratio seemed unfavourable.
I have some big-picture comments about the patch,
https://phabricator.services.mozilla.com/D305079.
Currently, the loop unroller is a pure MIR->MIR transformation pass -- it takes
in MIR, produces more MIR, and that MIR can potentially be subject to further
MIR-level transformations. Later parts of the compilation pipeline (the LIR
level, the CodeGenerator, the register allocator) know nothing about loop
unrolling, because they don't need to.
That is also the situation I would hope would apply even if the unroller could
do multi-exit unrolling. So I was surprised to see that the patch contains
changes to BacktrackingAllocator.cpp, and also that a
AssertExtendedGraphCoherency call in Ion.cpp has effectively been disabled, by
replacing it with AssertGraphCoherency.
Can you explain a bit why the above changes are necessary?
Just as a quick update, I have this working, and passing jit-tests. However, jetstream 3 sqlite3-wasm still fails due to some interaction with some wasm code which I am debugging. I should probably update the Phabricator review with my latest.
Specifically the function appears to be sqlite3_prepare_v3 in the test suite. Unsure what it's doing given the rest of the jit-tests pass now.
Good call, the intended model should remain that loop unrolling is a MIR-to-MIR transform. Later stages should not need to know whether a loop was unrolled.
I re-tested this after removing the BacktrackingAllocator changes and restoring the AssertExtendedGraphCoherency calls. The allocator changes were left over from debugging earlier invalid MIR shapes and are not required by the current version of the patch (they were introduced in prior debugging). With those removed, the focused multi-exit jit-tests, sqlite3-wasm, transformersjs-bert-wasm, and a browser run of kotlin-compose-wasm still pass.
Similarly, replacing AssertExtendedGraphCoherency with AssertGraphCoherency was a temporary debugging workaround while fixing dominance/exit-phi issues in the generated MIR. The current MIR repair should satisfy the stronger invariant, so I restored AssertExtendedGraphCoherency. The remaining required work is MIR-level: split exposed critical/phi edges, rebuild the dominator tree, rebuild phi reverse mappings, and ensure exit phis have operands that dominate their corresponding predecessor edges.
So we can remove allocator-specific handling for unrolling in the final patch, and it should keep the stronger MIR coherency checks.
Do you think these extra checks should be eliminated entirely, or would you want to take them in maybe a separate patch. My testing shows they are unnecessary, and I was basically guessing where problems were while getting this to work.
Comment 10•4 months ago
|
||
Thank you for doing this work. It would be great if it could be brought to a
successful conclusion. I think there is a need to set expectations
appropriately, as follows.
Currently the patch shows interesting potential. Unfortunately it will need
considerable extra work to get it into a state where we might start reviewing
it. The smaller a patch is, the easier it is to discuss and review. That
would mean, at a minimum:
-
removing all the debugging printfs and hacks
-
removing ALLOW_CLONE markings added for some wasm nodes
-
removing the MIR changes needed for unrolling JS. That is a different
problem from unrolling multi-exit loops, and can be done in a different bug.
In general, at least for complex problems like this, it is not enough just to
present a patch, no matter how good it is. It is also important to be able to
explain the purpose of every line in the patch, if asked, so that reviewers can
understand how the patch works, and be able to assess the risks and
opportunities it brings.
Speaking for myself, I would much prefer if you could narrowly focus on the
problem in bug 1959091. In particular my understanding is that multi-exit
unrolling could be implemented mostly as (possibly complex) changes to
AddClosingPhisForLoop and only minor changes elsewhere in UnrollLoops.cpp.
Also I don't understand why multi-exit unrolling would need a rebuild of the
dominator tree (beyond the rebuild we already do, post-unrolling).
Finally there is the question of whether it brings useful speedup. It would be
wise to approximately measure the perf win as soon as you can, so we have a
measure of effort-vs-benefit ratio sooner rather than later. A good way to do
this is using the wasm tests in the JetStream3 suite.
| Assignee | ||
Comment 11•4 months ago
|
||
This is fine. I am still kind of learning the processes and code here. I'll clean up the code, and can maybe see if I can do the comparison. I've purposely left out performance comparisons at this point since I knew I had to clean some of this up.
| Assignee | ||
Comment 12•4 months ago
|
||
| Assignee | ||
Comment 13•4 months ago
|
||
This latest revision I uploaded is starting to look like what you suggested in the other ticket. transformersjs-bert-wasm seems to have some of the bigger gains. Attached some reference output. Gains are probably about 1%?
| Assignee | ||
Comment 14•4 months ago
|
||
I may also have a full IDF implementation that has not been submitted yet.
| Assignee | ||
Comment 15•4 months ago
|
||
I've now implemented a full IDF pass (submitted) for multi-unrolling which should align with that paper. Some caveats:
- the IDF algorithm is also gated by by multi-exit unrolling flag because I found that it caused performance regressions on the 'normal' path
- the IDF path was apparently compiling too much, so I've also given it the scoring threshold. I think I've reused the same kind of value the rest of the code uses, and see a marginal performance uplift transformersjs-bert-wasm, sqlite3-wasm, and kotlin-compose-wasm
I will leave tuning this variable, and integrating IDF into the normal flow as a task for a subsequent ticket. Otherwise this ticket will explode in complexity.
| Assignee | ||
Comment 16•4 months ago
|
||
I tried integrating IDF into the normal unrolling control flow, and I feel it will require too much work for this ticket. Let's keep it separated for now.
| Assignee | ||
Comment 17•4 months ago
|
||
The code currently in review is the IDF solution with scoring threshold. It is probably ready for review.
IDF is only active for multi-exit unrolling. I've kept the score close to the rest of them, but have done some minimal tuning. It could probably use further tuning for truly optimal settings.
However, I have experimentally shown on my end that adding IDF to the regular unrolling path, and tuning the scoring thresholds down significantly improves performance even on multi-exit benchmarks (something in the order of 10%). I do not think it's a good idea to widen the scope of this ticket.
| Assignee | ||
Comment 18•4 months ago
|
||
Do you think the changes need to be split into multiple commits? It is possible to separate some of this code out further, but at least since it's detached from the enabling code that actually uses it for multi-exit loops the change sets would be somewhat theoretical to reason about in individual PRs.
| Assignee | ||
Comment 19•4 months ago
|
||
Test Multi-exit off Multi-exit on Change
Kotlin Compose Wasm 2.478 2.562 +3.40%
sqlite3 Wasm 75.221 75.252 +0.04%
TransformersJS BERT Wasm 65.448 64.937 -0.78%
Description
•