Commit 0fbb318
Gate output-centric image_to_nchw staging to discrete GPUs (#21022)
Summary:
The `image_to_nchw` output-staging shader can dispatch one thread per NCHW
output element so writes to the host-visible staging buffer are fully coalesced.
On a discrete GPU the staging buffer is host-visible but not device-local
(PCIe-backed system RAM), where coalescing writes is a large win: ~11x
end-to-end on an RTX 4080 laptop for an ESPCN 2x super-resolution model.
That output-centric scheme fetches each texel up to 4 times (once per
component). On unified-memory (mobile) GPUs the staging buffer is not
PCIe-backed, so write coalescing buys nothing and the redundant fetches are a
net loss: measured +15-42% `image_to_nchw` per-dispatch on Mali-G715 and +3-6%
on Adreno 750.
Gate the two strategies on `Adapter::has_unified_memory()`:
- discrete (no unified memory) -> `image_to_nchw_coalesced_*` (output-centric)
- unified memory (mobile) -> `image_to_nchw_*` texel-centric (one thread per
texel, single fetch, contiguous NCHW writes), which is the default.
`image_to_nchw.glsl` emits both variants via a `COALESCED_WRITES` codegen flag
(default False). `get_tensor_to_nchw_shader` selects the coalesced variant when
`!has_unified_memory()`; the global-workgroup-size picker keys off the shader
name so the dispatch topology matches the chosen variant.
Reviewed By: metascroy
Differential Revision: D1125997101 parent 21554e5 commit 0fbb318
4 files changed
Lines changed: 103 additions & 22 deletions
File tree
- backends/vulkan/runtime/graph/ops
- glsl
- impl
- utils
Lines changed: 64 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
22 | 35 | | |
23 | 36 | | |
24 | 37 | | |
| |||
39 | 52 | | |
40 | 53 | | |
41 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
42 | 91 | | |
43 | 92 | | |
44 | 93 | | |
45 | 94 | | |
46 | 95 | | |
47 | 96 | | |
48 | | - | |
| 97 | + | |
49 | 98 | | |
50 | | - | |
| 99 | + | |
51 | 100 | | |
52 | | - | |
| 101 | + | |
53 | 102 | | |
54 | 103 | | |
55 | 104 | | |
| |||
77 | 126 | | |
78 | 127 | | |
79 | 128 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
90 | 140 | | |
91 | 141 | | |
92 | 142 | | |
| |||
98 | 148 | | |
99 | 149 | | |
100 | 150 | | |
| 151 | + | |
101 | 152 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
| |||
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
109 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
110 | 122 | | |
111 | 123 | | |
112 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
84 | 96 | | |
85 | 97 | | |
86 | 98 | | |
| |||
0 commit comments