Repository navigation
Description
Dispatch ops (such as flow.dispatch and hal.command_buffer.dispatch) don't use nested references to specify the executable and entry point target. This makes work such as #1144 and #1587 that may need to update references much more difficult. We should switch to nested references across all of the dialects.
Today, things like flow.dispatch take a FlatSymbolRefAttr for the executable and the entry point, so the signature is something like flow.dispatch @executable, @entry_point, .... This prevents fancy MLIR features. Instead, we should be using the nested references like @executable::@entry_point. This means changing the FlatSymbolRefAttr (to just SymbolRefAttr maybe?) and places that are performing the lookup changing to using the right SymbolTable methods (like lookupNearest...). We may also need to adjust some symbol visibility; for example some public symbols (such as entry points in flow.executable/hal.executable) should probably be nested.
Example of badness:
- https://github.com/google/iree/blob/20919fcdfff77b3ae347a5c985c29bf4f21370a4/iree/compiler/Dialect/Flow/IR/FlowOps.td#L349-L352
- https://github.com/google/iree/blob/6f30e7216cf22fb4a77f4d47d7c70145091c21fc/iree/compiler/Dialect/HAL/IR/HALOps.td#L1139-L1140
The HAL one is interesting as it has an executable instance as an arg (%foo) as well as the entry point; what's currently just an ordinal should instead be a symbol reference.
Before: hal.command_buffer.dispatch %cmd, %executable, entry_point = 0, ...
After: hal.command_buffer.dispatch %cmd, %executable, entry_point = @MyExecutable::EntryPoint, ...
This will allow us to merge/split executables after generating command buffers and is required for linking support (#1587).
Activity
ScottTodd commentedon Jul 20, 2020
I've made progress on using nested references in
hal.command_buffer.dispatchfor the VMLA backend (see code here). I'm still trying to figure out how to update Vulkan-SPIRV though. #1816 introduced a concept of generating multiple entry points for a single dispatch function, without also generating multiplehal.executable.entry_pointops. Should thehal.executable.entry_pointops correspond 1:1 withspv.EntryPointops?Click to expand `fullyconnected.mlir` snippet
benvanik commentedon Jul 21, 2020
Good question - that flow is a little messed up right now. I'll take a peek and see if any solution sticks out and otherwise we may need to rework things a bit (as they wouldn't be compatible with linking as-is anyway).
ScottTodd commentedon Jul 21, 2020
That was my concern too. I could hack around the Vulkan-SPIRV lowering by keeping an ordinal index on
hal.command_buffer.dispatchor I could insert additionalhal.executable.entry_pointops, but I want to make sure that whatever changes here helps with the linking changes that we want to come next.This
seems like special SPIR-V logic that could be replaced with core
hal.executableconcepts? Or is it complementary?ScottTodd commentedon Jul 22, 2020
Chatted with @antiagainst and learned some more about how the Vulkan-SPIRV lowering is working:
iree-hal-materialize-interfacesgoes fromflow.executableops tohal.executableops. As part of that it createshal.executable.entry_pointops.iree-codegen-split-dispatch-functionlater runs on each module, optionally splitting each workload up further depending on "GPU lowering dependencies". It also addsvkspv.entry_point_scheduleattributes for use later.SPIRVLowerABIAttributesaddsspv.EntryPointopsConvertFlowToHALPasspulls the SPIRV and hal ops together and has a mismatch betweenhal.executable.entry_pointops andspv.EntryPointops. It uses thevkspv.entry_point_scheduleattribute to reconcile.Letting backends split up work as needed like in (2) makes sense, but at some point they should create corresponding
hal.executable.entry_pointops (and update existing ones as needed?). I could try creating new entry point ops inConvertFlowToHALPass, but would that be too late? Should there be a hook earlier in the lowerings that lets HAL target backends manipulate entry points / work granularity?ScottTodd commentedon Jul 22, 2020
Also important: the VulkanSPIRVTarget lowering inserts execution barriers between its split dispatch ops. This ordering relationship between calling entry points should be preserved after any linking (if it isn't naturally).
ScottTodd commentedon Jul 28, 2020
After some more discussion with @benvanik , another refactoring that may help here would be to move
hal.executable.entry_pointops intohal.executable.targetmodules and defer their creation fromIREE::HAL::MaterializeInterfacesPasstoIREE::HAL::TranslateExecutablesPass. By that point, each target backend should be ready to define its entry points, even after lowering through other dialects and splitting dispatches as needed.Move hal.executable.entry_point ops into hal.executable.target. (#2893)
Use nested references in HAL command buffer dispatches. (#3047)
Clean up HAL dispatch ops to not track redundant state. (#3121)
Clean up HAL dispatch ops to not track redundant state. (iree-org#3121)
Switch flow.dispatch ops to use nested references to entry points. (#…