Commit 85dd208
authored
[HAL] Add pass pipeline caching to executable translation and configuration (#23643)
Adds a PipelineCache utility (in Utils/PassUtils.h) that caches
constructed OpPassManagers keyed by ExecutableTargetAttr. When multiple
executable variants share the same target attribute, the pass pipeline
only needs to be constructed once rather than being rebuilt from scratch
for every variant.
The cache is shared across clones of the outer per-ExecutableOp pass via
shared_ptr, so MLIR's parallel pass execution across different
ExecutableOps all benefit from the same cached pipelines.
getOrCreate() returns a deep copy of the cached pipeline rather than a
reference because MLIR passes carry mutable state (analysis caches,
statistics) that is modified during execution. Since the outer
per-ExecutableOp passes run in parallel, two threads processing
different executables with the same target attribute would race on a
shared OpPassManager. The copy cost is negligible compared to pipeline
execution; the savings come from avoiding redundant pipeline
construction (registry lookups, dynamic pass creation) for every
variant.
A quick local benchmark with varying dispatch counts shows substantial
savings:
```
┌────────────────┬──────────┬───────────┬────────┐
│ Input │ Ref (ms) │ Feat (ms) │ Delta │
├────────────────┼──────────┼───────────┼────────┤
│ 50 dispatches │ 869 │ 524 │ -39.7% │
├────────────────┼──────────┼───────────┼────────┤
│ 200 dispatches │ 1,084 │ 725 │ -33.1% │
├────────────────┼──────────┼───────────┼────────┤
│ 500 dispatches │ 2,129 │ 1,684 │ -20.9% │
├────────────────┼──────────┼───────────┼────────┤
│ TOTAL │ 4,082 │ 2,933 │ -28.1% │
└────────────────┴──────────┴───────────┴────────┘
```
One last note, in theory we could skip this caching altogether by
forcing the target backend to construct the pass pipeline on
initialization and return the OpPassManager directly rather than
constructing it on the fly, but that's a more substantial refactor.1 parent 61e8c44 commit 85dd208
3 files changed
Lines changed: 109 additions & 10 deletions
File tree
- compiler/src/iree/compiler
- Dialect/HAL/Transforms
- Utils
Lines changed: 37 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
42 | 54 | | |
43 | 55 | | |
44 | 56 | | |
| |||
59 | 71 | | |
60 | 72 | | |
61 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
62 | 78 | | |
63 | | - | |
64 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
65 | 88 | | |
66 | 89 | | |
67 | 90 | | |
| |||
88 | 111 | | |
89 | 112 | | |
90 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
91 | 121 | | |
92 | 122 | | |
93 | 123 | | |
| |||
102 | 132 | | |
103 | 133 | | |
104 | 134 | | |
105 | | - | |
106 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
107 | 139 | | |
108 | 140 | | |
109 | 141 | | |
| |||
Lines changed: 36 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
43 | 53 | | |
44 | 54 | | |
45 | 55 | | |
| |||
65 | 75 | | |
66 | 76 | | |
67 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
68 | 82 | | |
69 | | - | |
70 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
71 | 93 | | |
72 | 94 | | |
73 | 95 | | |
| |||
88 | 110 | | |
89 | 111 | | |
90 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
91 | 120 | | |
92 | 121 | | |
93 | 122 | | |
| |||
103 | 132 | | |
104 | 133 | | |
105 | 134 | | |
106 | | - | |
107 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
108 | 139 | | |
109 | 140 | | |
110 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
17 | 53 | | |
18 | 54 | | |
19 | 55 | | |
| |||
0 commit comments