Commit 1e1df9e
committed
[ET-VK] Add mechanism to trigger command buffer re-encode only when necessary
## Context
Dynamic shape models currently will require the command buffer to be re-encoded every inference. However, this introduces a significant overhead when running models that require dynamic shapes.
The reality is that a command buffer re-encode may not be needed every frame. A command buffer re-encode will only be needed when:
1. Shader dispatch parameters change; i.e. new tensor sizes require a completely different compute shader, require new local work group sizing, or require new work group grid size (i.e. global work group size / local work group size)
2. Push constants containing tensor metadata need to be updated
This diff aims to reduce the overhead of triggering tensor shape change by detecting when a command buffer re-encode is actually needed.
## Changes
`ComputeGraph`:
* Introduce `requires_reencode` flag to `ComputeGraph` to indicate when a command buffer re-encode is needed.
* Introduce a `std::set<ValueRef>` tracking which values were updated when propagating tensor sizes
* "update" can be one of two things: 1) tensor sizes changed 2) symint value changed
`DispatchNode`:
* When propagating new tensor sizes, only execute the resize function if any of the values participating in the computation have been updated
* Mark `requries_reencode` if any push constants associated with tensor metadata need to be udpated
`DynamicDispatchNode`:
* Only recompute compute shader dispatch params if any of the values participating in the computation have been updated
* Mark `requires_reencode` if 1) a new compute shader is required, 2) local work group size changed, 3) work group grid size changed
Differential Revision: [D79813237](https://our.internmc.facebook.com/intern/diff/D79813237/)
[ghstack-poisoned]1 parent 016eece commit 1e1df9e
File tree
9 files changed
+245
-31
lines changed- backends/vulkan/runtime
- graph
- containers
- ops
9 files changed
+245
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
| 585 | + | |
592 | 586 | | |
593 | 587 | | |
594 | 588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
209 | 247 | | |
210 | 248 | | |
211 | 249 | | |
| |||
569 | 607 | | |
570 | 608 | | |
571 | 609 | | |
572 | | - | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
573 | 616 | | |
574 | 617 | | |
575 | 618 | | |
| |||
921 | 964 | | |
922 | 965 | | |
923 | 966 | | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
924 | 973 | | |
925 | 974 | | |
926 | 975 | | |
| |||
938 | 987 | | |
939 | 988 | | |
940 | 989 | | |
941 | | - | |
| 990 | + | |
| 991 | + | |
942 | 992 | | |
943 | 993 | | |
944 | 994 | | |
945 | 995 | | |
946 | 996 | | |
947 | | - | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
948 | 1003 | | |
949 | 1004 | | |
950 | 1005 | | |
951 | 1006 | | |
952 | 1007 | | |
953 | 1008 | | |
954 | | - | |
955 | | - | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
956 | 1014 | | |
957 | 1015 | | |
958 | 1016 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
199 | 205 | | |
200 | 206 | | |
201 | 207 | | |
| |||
419 | 425 | | |
420 | 426 | | |
421 | 427 | | |
422 | | - | |
| 428 | + | |
423 | 429 | | |
| 430 | + | |
| 431 | + | |
424 | 432 | | |
425 | 433 | | |
426 | 434 | | |
427 | | - | |
| 435 | + | |
428 | 436 | | |
429 | 437 | | |
| 438 | + | |
| 439 | + | |
430 | 440 | | |
431 | 441 | | |
432 | 442 | | |
433 | | - | |
| 443 | + | |
434 | 444 | | |
435 | 445 | | |
| 446 | + | |
| 447 | + | |
436 | 448 | | |
437 | 449 | | |
438 | 450 | | |
439 | | - | |
| 451 | + | |
440 | 452 | | |
441 | 453 | | |
| 454 | + | |
| 455 | + | |
442 | 456 | | |
443 | 457 | | |
444 | 458 | | |
445 | | - | |
| 459 | + | |
446 | 460 | | |
| 461 | + | |
| 462 | + | |
447 | 463 | | |
448 | 464 | | |
449 | 465 | | |
| |||
940 | 956 | | |
941 | 957 | | |
942 | 958 | | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
943 | 972 | | |
944 | 973 | | |
945 | 974 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
38 | 43 | | |
| |||
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
63 | 80 | | |
64 | 81 | | |
65 | 82 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
92 | 130 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
| |||
0 commit comments