Commit c8f3cfe
committed
[ET-VK][ez] Fix Vulkan Validation layer errors due to consecutive command buffer encoding
## Changes
* In `VulkanBackend.cpp` do not call `encode_execute()` during model load if the model compile spec specifies `requires_dynamic_shapes` as true
* In test files, do not call `encode_execute()` if `propagate_resize()` is subsequently called.
## Motivation
Recently, it was discovered that a command buffer re-encode was required to update push constant values. This means that for dynamic shapes to work correctly, `encode_execute()` must be called after updating tensor sizes.
As a result, `propagate_resize()` now calls `encode_execute()` internally. This results in scenarios where `encode_execute()` is called once during model load, then again right before the first inference during `propagate_resize()`, without actually executing the command buffer in-between.
This causes Validation layer errors like
```
UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x24086224ec0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x88d2b500000000e2, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x24086224ec0[] expects VkImage 0x88d2b500000000e2[] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.
Objects: 2
[0] 0x24086224ec0, type: 6, name: NULL
[1] 0x88d2b500000000e2, type: 10, name: NULL
UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x24086224ec0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x6caffc00000000e3, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x24086224ec0[] expects VkImage 0x6caffc00000000e3[] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.
Objects: 2
[0] 0x24086224ec0, type: 6, name: NULL
[1] 0x6caffc00000000e3, type: 10, name: NULL
```
because the last access information of image/buffer resources are inaccurate during the second command buffer encoding, since the first command buffer never executed.
## Perf Impact
* Performance improvement for first inference of dynamic shape models if actual tensor sizes are much smaller than maximum possible sizes
* No impact for non-dynamic shape models
Differential Revision: [D76047203](https://our.internmc.facebook.com/intern/diff/D76047203/)
[ghstack-poisoned]1 parent 012f7a3 commit c8f3cfe
File tree
7 files changed
+33
-11
lines changed- backends/vulkan
- runtime
- graph
- test
- op_tests/utils
7 files changed
+33
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
143 | 153 | | |
144 | 154 | | |
145 | 155 | | |
| |||
500 | 510 | | |
501 | 511 | | |
502 | 512 | | |
503 | | - | |
504 | | - | |
505 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
506 | 519 | | |
507 | 520 | | |
508 | 521 | | |
| |||
574 | 587 | | |
575 | 588 | | |
576 | 589 | | |
577 | | - | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
578 | 593 | | |
579 | 594 | | |
580 | 595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
| 622 | + | |
622 | 623 | | |
623 | 624 | | |
624 | 625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1536 | 1536 | | |
1537 | 1537 | | |
1538 | 1538 | | |
1539 | | - | |
1540 | 1539 | | |
1541 | 1540 | | |
1542 | 1541 | | |
| |||
1743 | 1742 | | |
1744 | 1743 | | |
1745 | 1744 | | |
1746 | | - | |
1747 | 1745 | | |
1748 | 1746 | | |
1749 | 1747 | | |
| |||
1820 | 1818 | | |
1821 | 1819 | | |
1822 | 1820 | | |
1823 | | - | |
1824 | 1821 | | |
1825 | 1822 | | |
1826 | 1823 | | |
| |||
2955 | 2952 | | |
2956 | 2953 | | |
2957 | 2954 | | |
2958 | | - | |
2959 | 2955 | | |
2960 | 2956 | | |
2961 | 2957 | | |
| |||
3058 | 3054 | | |
3059 | 3055 | | |
3060 | 3056 | | |
3061 | | - | |
3062 | 3057 | | |
3063 | 3058 | | |
3064 | 3059 | | |
| |||
3125 | 3120 | | |
3126 | 3121 | | |
3127 | 3122 | | |
3128 | | - | |
3129 | 3123 | | |
3130 | 3124 | | |
3131 | 3125 | | |
| |||
0 commit comments