This is an archive of the discontinued LLVM Phabricator instance.

[mlir][spirv] Lower allocation/deallocations of workgroup memory.
ClosedPublic

Authored by mravishankar on May 21 2020, 2:50 PM.

Details

Summary

This allocation of a workgroup memory is lowered to a
spv.globalVariable. Only static size allocation with element type
being int or float is handled. The lowering does account for the
element type that are not supported in the lowered spv.module based on
the extensions/capabilities and adjusts the number of elements to get
the same byte length.

Depends On D80365

Diff Detail

Event Timeline

mravishankar created this revision.May 21 2020, 2:50 PM
Herald added a reviewer: herhut. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
herhut resigned from this revision.May 26 2020, 12:16 AM
antiagainst accepted this revision.May 26 2020, 12:58 PM

Cool, thanks Mahesh! Overall looks good to me. Approval conditional on fixing the workgroup layout annotation issue.

mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.h
46

Returns None

48

Super nit: can we just leave out the t? It does not provide more information here.

mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
240

I feel we should place this logic inside the type converter itself. This is basically getting the SPIR-V "equivalent" lowered memref type for the input memref. Letting each pattern figuring out this is not the proper separation of concerns. Fine for now given this is only used by allocation; but can we put a TODO here to remind ourselves?

273

spv.globalVariable

274

Could you document that this pattern requires the pass to work on module instead of function given it injects stuff to the model?

284

Do we need to unique the symbol manually here? I remember there is infrastructure support for it; but cannot recall off the top of my head.

mlir/test/Conversion/GPUToSPIRV/load-store.mlir
61

Might just want to add -canonicalize to simplify here? I know it's kinda tiding two passes together but in general canonicalization is not changing too frequently and we can have more readable tests here. But up to you. :)

mlir/test/Conversion/StandardToSPIRV/alloc.mlir
23

Ah, this should not have layout annotation at all. Variables in Workgroup should not be explicitly laid out. The layout handling is problematic in the type converter. Could you turn off layout annotation for Workgroup memrefs in TypeConverter? Just do not pass in offsets when handling Workgroup in convertMemrefType.

36

You mean fix? This test is not commented out at the moment.

109

We can trim of the but got ... part given we are not particularly interested in verifying the detailed error here. Similarly for the following case.

This revision is now accepted and ready to land.May 26 2020, 12:58 PM
mravishankar marked 13 inline comments as done.

Addressing comments

mravishankar added inline comments.May 27 2020, 9:37 AM
mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
240

Yup I agree and obviously the type converter already handles this. So removing this from here. Thanks!

284

I verified that we do. I got an error with two allocations if I didnt do this. (Adding a test for that as well).

mlir/test/Conversion/GPUToSPIRV/load-store.mlir
61

True. But this will probably need to make changes to unrelated tests. Would prefer to do this in a later CL.

mlir/test/Conversion/StandardToSPIRV/alloc.mlir
23

THanks. Fixed!

36

Damn. Thanks for catching it. Commented now.
Actually looking at this test again, I realize that if this test worked as expected the generated spv.AtomicOr/spiv.AtomicAnd operations would have the wrong scope. Adjusted the code to handle that, but this cant be tested without the underlying issue being fixed.

This revision was automatically updated to reflect the committed changes.