iree icon indicating copy to clipboard operation
iree copied to clipboard

Add ReplacePushConstants pass for WebGPU.

Open ScottTodd opened this issue 3 years ago • 2 comments

WebGPU does not (today) support push constants, so we plan on emulating them using storage buffer bindings. This is the compiler side of that work - it replaces hal.interface.constant.load ops with hal.interface.binding.subspan ops. The actual HAL pipeline layouts are unchanged (so they will still include push_constants = 1).

This should fix errors like error: unknown SPIR-V storage class: 9SPIR-V pointer type with ID 6 has invalid storage class 9.

Here's a diff of some generated .spvasm files for unidirectional_lstm.mlir: image (raw files here: https://gist.github.com/ScottTodd/713a464e8a1c8af6ebd2a66db9348370)

ScottTodd avatar Aug 26 '22 17:08 ScottTodd

Ill look in detail, but dont you also need to update the hal.executable.variant to reflect the new sets?

My understanding is that the pipeline layouts will still mention push constants as before, then the WebGPU HAL will understand that the push constants are actually using buffer bindings (at least - that's how @benvanik has it implemented in the HAL right now AFAICT). I'm not sure if it would be better to fully remove the concept of push constants instead.

ScottTodd avatar Sep 13 '22 21:09 ScottTodd

Correct - the runtime still sees push constants as a way to build the argument buffers and doesn't know about the hidden runtime buffer. Incidentally this is how we'd add support for printf and such in dispatches as well (runtime inserts a binding to append string contents into but from the vmfb perspective it's not there).

benvanik avatar Sep 13 '22 21:09 benvanik