You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use tile and distribute for all compute operations #5045
The current dispatch region creation uses the tile + distribute for only named ops. For elemntwise operations represented as linalg.generic and linalg.indexed_generic operations they are not tiled during dispatch region creation. Instead they are left as is and
Lowered to loops on CPU side to execute sequentially
On GPU side the patterns that lower an untiled operations to scalar code by distributing them to invocations using GlobalInvocationId kick in to distribute one iteration per invocation.
Both of this is not satisfactory. We need to parallelize the work on CPU side, and we also should have such low computation per thread on the GPU side. Instead it might be worth using tile + distribute on these operations as well to do some coarse-grain partitioning of the work. On the GPU side we can then try to use vectorization to get vector loads/stores (which also can be done on the CPU side).
Points to consider
On GPU side we might map this directly to invocations (using global invocation id) so that we dont add unnecessary loop overhead (by default the tiles created at the flow level are mapped to workgroups)
+1 to this! Not sure we've ever explicitly mentioned it but that was always my hope for elementwise/transfer/etc operations: parallelized copies or permutes woo!
changed the title [-]Use tile and distribute for `linalg.generic`/`linalg.indexed_generic` operations[/-][+]Use tile and distribute for all compute operations[/+]on Sep 2, 2021
Picking this up again to fill out places that are still missing. With the TiledOpInterface a lot more ops are tiled and distributed through multiple levels of processor hierarchy (1 level on CPU to target threads, 2 levels on GPUs to target workgroups and workitems). There are still a few operations that do not go through this path. Following are a list of these.
tensor.insert_slice : The basic tiling and distribution of these is prototyped using the TiledOpInterface (here). This needs to be plumbed through the CPU and GPU backends. Ideally, instead of doing this in a piecewise manner per op, all the places that need tile + distribution just use the TiledOpInterface. (Note: This is WIP already, and is exposing some very hairy issues upstream with rank-reducing subviews).
linalg.pad_tensor : Currently these operations are converted to a fill + tensor.insert_slice (here). This is inefficient. It is better to leave it as is and tile and distribute these operations. There is a pattern upstream (here) that can be used to tile and distribute this operation. This pattern uses the TilingInterface which is the upstream version of the TiledOpInterface. So it is also possible to just implement the TiledOpInterface for linalg.pad_tensor as an ExternalModel and redirect to the implementation of TilingInterface upstream. With the use of TiledOpInterface plumbed through this "should just work".
linalg.generic where indexing_maps are not all project permutations (see here) : The main operation that falls into this category from our inputs is the reverse operation. The issue is the getLoopsToShapesMap. Just using a concatenation of the indexing_maps as done here to compute the shapes of operands does not work for reverse operation since an expression of type 10-d0 results in a shape of 0.
linalg.*conv* : While most operations have a default configuration set that allows them to be tiled and distributed, the default configuration does not work well for convolution operations. A default configuration is needed for conv operations. Ideally we should add a LinalgConvolutionOpInterface (similar to LinalgContractionOpInterface) and set the configuration based on that. Note that the SPIR-V backend does have a default configuration for some versions of the convolution operations, but its very specific to the MobileNet use cases that have been looked at deeply.
AFAIK, these are the only remaining ops that dont get tiled and distributed. Once these are done, several things can be cleaned up
Currently DispatchLinalgOnTensors pass sets the workgroup marker on operations that are tiled and distributed (here). If all ops are tiled and distributed, this marker can be dropped. The workgroup marker can actually be dropped completely from the codebase.
The SPIRVDistributeToGlobalID pass can be finally deleted. For now this is well siloed since only dispatches that contain the above operation go through this path. The pipeline that contains this path can be deleted also.
Activity
benvanik commentedon Mar 10, 2021
+1 to this! Not sure we've ever explicitly mentioned it but that was always my hope for elementwise/transfer/etc operations: parallelized copies or permutes woo!
antiagainst commentedon Mar 10, 2021
I think if we can handle fusion with consumer elementwise ops (#5040) , we might not seeing a lot of such cases being standalone?
Enable dispatching linalg.generic ops into workgroups and set tiling …
MaheshRavishankar commentedon Apr 26, 2021
There are still some missing cases.
[-]Use tile and distribute for `linalg.generic`/`linalg.indexed_generic` operations[/-][+]Use tile and distribute for all compute operations[/+]MaheshRavishankar commentedon Sep 5, 2021
Picking this up again to fill out places that are still missing. With the
TiledOpInterfacea lot more ops are tiled and distributed through multiple levels of processor hierarchy (1 level on CPU to target threads, 2 levels on GPUs to target workgroups and workitems). There are still a few operations that do not go through this path. Following are a list of these.tensor.insert_slice: The basic tiling and distribution of these is prototyped using theTiledOpInterface(here). This needs to be plumbed through the CPU and GPU backends. Ideally, instead of doing this in a piecewise manner per op, all the places that need tile + distribution just use theTiledOpInterface. (Note: This is WIP already, and is exposing some very hairy issues upstream with rank-reducing subviews).linalg.pad_tensor: Currently these operations are converted to afill+tensor.insert_slice(here). This is inefficient. It is better to leave it as is and tile and distribute these operations. There is a pattern upstream (here) that can be used to tile and distribute this operation. This pattern uses theTilingInterfacewhich is the upstream version of theTiledOpInterface. So it is also possible to just implement theTiledOpInterfaceforlinalg.pad_tensoras anExternalModeland redirect to the implementation ofTilingInterfaceupstream. With the use ofTiledOpInterfaceplumbed through this "should just work".linalg.genericwhereindexing_mapsare not all project permutations (see here) : The main operation that falls into this category from our inputs is thereverseoperation. The issue is thegetLoopsToShapesMap. Just using a concatenation of theindexing_mapsas done here to compute the shapes of operands does not work forreverseoperation since an expression of type10-d0results in a shape of0.linalg.*conv*: While most operations have a default configuration set that allows them to be tiled and distributed, the default configuration does not work well for convolution operations. A default configuration is needed for conv operations. Ideally we should add aLinalgConvolutionOpInterface(similar toLinalgContractionOpInterface) and set the configuration based on that. Note that the SPIR-V backend does have a default configuration for some versions of the convolution operations, but its very specific to the MobileNet use cases that have been looked at deeply.AFAIK, these are the only remaining ops that dont get tiled and distributed. Once these are done, several things can be cleaned up
DispatchLinalgOnTensorspass sets theworkgroupmarker on operations that are tiled and distributed (here). If all ops are tiled and distributed, this marker can be dropped. Theworkgroupmarker can actually be dropped completely from the codebase.SPIRVDistributeToGlobalIDpass can be finally deleted. For now this is well siloed since only dispatches that contain the above operation go through this path. The pipeline that contains this path can be deleted also.Introduce reverse op to LinalgExt dialect. (#7124)
Update semantics of linalg_ext.reverse. (#7155)
Implement tiling method for linalg_ext.reverse ops. (#7159)
Lowering mhlo.reverse to linalg_ext.reverse. (#7163)
Drop "workgroup" marker.
Drop "workgroup" marker.
Drop "workgroup" marker.
Drop "workgroup" marker. (#7522)