This patch adds a new flag named -bottleneck-analysis to print out information about throughput bottlenecks.
MCA knows how to identify and classify dynamic dispatch stalls. However, it doesn't know how to analyze and highlight kernel bottlenecks.
The goal of this patch is to teach MCA how to correlate increases in backend pressure to backend stalls (and therefore, the loss of throughput).
From a Scheduler point of view, backend pressure is a function of the scheduler buffer usage (i.e. how the number of uOps in the scheduler buffers changes over time). Backend pressure increases (or decreases) when there is a mismatch between the number of opcodes dispatched, and the number of opcodes issued in the same cycle.
Since buffer resources are limited, continuous increases in backend pressure would eventually leads to dispatch stalls. So, there is a strong correlation between dispatch stalls, and how backpressure changed over time.
This patch teaches how to identify situations where backend pressure increases due to:
- unavailable pipeline resources.
- data dependencies.
Data dependencies may delay execution of instructions and therefore increase the time that uOps have to spend in the scheduler buffers. That often translates to an increase in backend pressure which may eventually lead to a bottleneck.
Contention on pipeline resources may also delay execution of instructions, and lead to a temporary increase in backend pressure.
Internally, the Scheduler classifies instructions based on whether register/memory operands are available or not.
An instruction is marked as "ready to execute" only if data dependencies are fully resolved.
Every cycle, the Scheduler attempts to execute all instructions that are ready to execute. If an instruction cannot execute because of unavailable pipeline resources, then the Scheduler internally updates a BusyResourceUnits mask with the ID of each unavailable resource.
ExecuteStage is responsible for tracking changes in backend pressure. If backend pressure increases during a cycle because of contention on pipeline resources, then ExecuteStage sends a "backend pressure" event to the listeners.
That event would contain information about instructions delayed by resource pressure, as well as the BusyResourceUnits mask.
Note that ExecuteStage also knows how to identify situations where backpressure increased because of delays introduced by data dependencies.
The SummaryView observes "backend pressure" events and prints out a "bottleneck report".
Example of bottleneck report:
Cycles with backend pressure increase [ 99.89% ] Throughput Bottlenecks: Resource Pressure [ 0.00% ] Data Dependencies: [ 99.89% ] - Register Dependencies [ 0.00% ] - Memory Dependencies [ 99.89% ]
A bottleneck report is printed out only if increases in backend pressure eventually caused backend stalls.
About the time complexity:
The average slowdown tends to be in the range of ~5-6%.
Time complexity is linear in the number of instructions in the Scheduler::PendingSet.
For memory intensive kernels, the slowdown can be significant if flag -noalias=false is specified. In the worst case scenario I have observed a slowdown of ~30% when flag -noalias=false was specified.
We can definitely recover part of that slowdown if we optimize class LSUnit (by doing extra bookkeeping to speedup queries).
This new analysis is disabled by default, and it can be enabled via flag -bottleneck-analysis.
Users of MCA as a library can enable the generation of pressure events through the constructor of ExecuteStage.
This patch partially addresses https://bugs.llvm.org/show_bug.cgi?id=37494
A follow up patch will extend the "scheduler-stats" view to also print out:
- the most problematic register dependencies (top 3)
- the most problematic memory dependencies (top 3)
- instructions mostly affected by bottlenecks caused by pipeline pressures (top 3).
That change plus this patch should fully address PR37494.
Let me know if okay to commit.