vulkan: optimize operations in the IM2COL shader#22685
vulkan: optimize operations in the IM2COL shader#22685daniandtheweb wants to merge 2 commits intoggml-org:masterfrom
Conversation
|
Perf on RTX 5090: |
| const uint delta_ic = BLOCK_SIZE / KHKW; | ||
| const uint delta_rem = BLOCK_SIZE % KHKW; | ||
| const uint delta_ky = delta_rem / p.KW; | ||
| const uint delta_kx = delta_rem % p.KW; |
There was a problem hiding this comment.
I'm not totally following this. In general it seems unsafe to precompute divs/mods and add them, as sometimes you would wrap to the next value and need to do a fixup. Maybe that's what the fixup logic is doing, but it's not clear.
I wonder if it might be better to pass KW as a spec constant and let the compiler transform it into something faster.
There was a problem hiding this comment.
kx_wrap and ky_wrap should take care of the wrapping. Moreover it shouldn't be possible for the values to wrap around twice as:
delta_kxby using a modulo is always less thanp.KW,kxis always less thanp.KWbecause of the modulo and the maximum value that it can reach is2 * p.KW - 2which is always less than2 * p.KW.delta_ky's max value isp.KH - 1so always less thanp.KH,kyis at mostp.KH - 1and the maximum value that it can reach is2 * p.KH - 1so less than2 * p.KH.
There was a problem hiding this comment.
I'm not that experienced on vulkan shaders so the most I could confidently achieve was this as it should (in theory) be mathematically correct. If there are better approaches I'll gladly look into them.
There was a problem hiding this comment.
Maybe it's better if I add some comments on the wrap values to make it more clear?
There was a problem hiding this comment.
Comments would help, but I think spec constants would keep the code more clear. I'll defer to @0cc4m on what to do.
There was a problem hiding this comment.
Got it, I'll start by adding some comments on the most confusing parts for now.
Overview
This optimizes the IM2COL shader by extracting redundant operations from the loops, similar to how I already did it in this: #11826.
Radeon RX 7800XTRadeon RX 5700XTRequirements