Commit b63b358
authored
[ET-VK] Enable automatic dtype conversion when copying to/from staging buffer (#14244)
## Context
During export, Vulkan sometimes converts certain tensor dtypes. The most common case of this is that int64 and float64 are internally represented as int32 and float32 tensors. The primary reason for this is to reduce the number of dtype variants that need to be generated for each shader, and also due to the fact that 64-bit types are not guaranteed to be supported.
However, this raises an issue if an int64 or float64 tensor is marked as an input/output tensor of the model. The source/destination ETensor will have a different dtype than the internal representation, meaning that the input/output bytes will be interpreted incorrectly.
## Changes
This diff fixes this behaviour by introducing the concept of a "staging dtype". This allows the staging buffer of a tensor to have a different dtype than the underlying GPU buffer or texture. When copying to/from the GPU resource, the dtype can then be converted to the correct dtype expected by the client code.
As a bonus, also add an optional setting to force fp16 to be used internally for fp32 tensors. This allows models to access half precision inference without needing to incur the cost of dtype conversion ops being inserted into the graph, or needing to manually convert inputs/outputs to half type.
Differential Revision: [D82234180](https://our.internmc.facebook.com/intern/diff/D82234180/)1 parent 36c2dd1 commit b63b358
File tree
33 files changed
+447
-99
lines changed- backends/vulkan
- runtime
- api
- containers
- graph
- ops
- glsl
- impl
- utils
- vk_api
- serialization
- test/utils
- examples/vulkan
33 files changed
+447
-99
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
89 | 115 | | |
90 | 116 | | |
91 | 117 | | |
| |||
343 | 369 | | |
344 | 370 | | |
345 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
346 | 381 | | |
347 | 382 | | |
348 | 383 | | |
| |||
359 | 394 | | |
360 | 395 | | |
361 | 396 | | |
362 | | - | |
| 397 | + | |
| 398 | + | |
363 | 399 | | |
364 | 400 | | |
365 | 401 | | |
| |||
384 | 420 | | |
385 | 421 | | |
386 | 422 | | |
387 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
388 | 429 | | |
389 | 430 | | |
390 | 431 | | |
| |||
582 | 623 | | |
583 | 624 | | |
584 | 625 | | |
585 | | - | |
| 626 | + | |
586 | 627 | | |
587 | 628 | | |
588 | | - | |
| 629 | + | |
| 630 | + | |
589 | 631 | | |
590 | 632 | | |
591 | 633 | | |
| |||
617 | 659 | | |
618 | 660 | | |
619 | 661 | | |
620 | | - | |
| 662 | + | |
621 | 663 | | |
622 | 664 | | |
623 | | - | |
| 665 | + | |
| 666 | + | |
624 | 667 | | |
625 | 668 | | |
626 | 669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
120 | 132 | | |
121 | 133 | | |
122 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
| |||
91 | 100 | | |
92 | 101 | | |
93 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
94 | 112 | | |
95 | 113 | | |
96 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
670 | 670 | | |
671 | 671 | | |
672 | 672 | | |
673 | | - | |
| 673 | + | |
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
| |||
679 | 679 | | |
680 | 680 | | |
681 | 681 | | |
682 | | - | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
683 | 701 | | |
684 | 702 | | |
685 | 703 | | |
| |||
713 | 731 | | |
714 | 732 | | |
715 | 733 | | |
716 | | - | |
| 734 | + | |
717 | 735 | | |
718 | 736 | | |
719 | 737 | | |
| |||
762 | 780 | | |
763 | 781 | | |
764 | 782 | | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
769 | 798 | | |
770 | 799 | | |
771 | 800 | | |
| |||
1104 | 1133 | | |
1105 | 1134 | | |
1106 | 1135 | | |
| 1136 | + | |
| 1137 | + | |
1107 | 1138 | | |
1108 | 1139 | | |
1109 | 1140 | | |
| |||
1193 | 1224 | | |
1194 | 1225 | | |
1195 | 1226 | | |
1196 | | - | |
| 1227 | + | |
1197 | 1228 | | |
1198 | 1229 | | |
1199 | 1230 | | |
| |||
1216 | 1247 | | |
1217 | 1248 | | |
1218 | 1249 | | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
1219 | 1254 | | |
1220 | 1255 | | |
1221 | 1256 | | |
| |||
1292 | 1327 | | |
1293 | 1328 | | |
1294 | 1329 | | |
| 1330 | + | |
| 1331 | + | |
1295 | 1332 | | |
1296 | 1333 | | |
1297 | 1334 | | |
| |||
0 commit comments