This is an archive of the discontinued LLVM Phabricator instance.

[mlir][spirv] Fix crash in convert-gpu-to-spirv pass with memrefs with affine maps
ClosedPublic

Authored by Hardcode84 on Jul 28 2021, 12:40 PM.

Details

Summary

spirv::getElementPtr can return null (for memrefs with affine map) but patterns didn't handle this.

Diff Detail

Event Timeline

Hardcode84 created this revision.Jul 28 2021, 12:40 PM
Hardcode84 requested review of this revision.Jul 28 2021, 12:40 PM
antiagainst requested changes to this revision.Jul 28 2021, 1:38 PM

Thanks for fixing this! Just one nit: could you also update the comment for spirv::getElementPtr to mention that it can return nullptr when it cannot perform the index calculation?

This revision now requires changes to proceed.Jul 28 2021, 1:38 PM

Add comment to getElementPtr

Also, is there any plans to actually support memrefs with dynamic offset and strides?

antiagainst accepted this revision.Jul 29 2021, 1:03 PM

Awesome, thanks!

Also, is there any plans to actually support memrefs with dynamic offset and strides?

Dynamic shapes / strides are a bit tricky for the SPIR-V side due to that we cannot always use a memref descriptor for it like LLVM (see the details here). In IREE we have been working with another approach towards it, without the memref descriptor. Basically we flatten the n-D memref into 1-D (effectively what the memref descriptor is doing under the hood for CPU side, relying on LLVM proper) before converting to SPIR-V using this pass. And then SPIR-V conversion only needs to handle the case where we have a 1-D flat memref/buffer. It effectively pushes the index calculation to a previous stage; instead of relying it being done at SPIR-V level. I'd like to upstream that sometime later.

This revision is now accepted and ready to land.Jul 29 2021, 1:03 PM