This is an archive of the discontinued LLVM Phabricator instance.

[mlir][spirv] Detach memory space mapping from type conversion
ClosedPublic

Authored by antiagainst on Aug 8 2022, 9:41 AM.

Details

Summary

This commit moves MemRef memory space to SPIR-V storage class
conversion out of the main SPIR-V type converter. Now the mapping
should happen as a prelimiary step before performing the final
conversion to SPIR-V. Flows are expect to write their own memory
space mappings like the MapMemRefStorageClassPass to handle
memory space mappings according to their needs.

This is needed because SPIR-V is serving multiple client APIs,
including Vulkan and OpenCL. Different client APIs might want
to use different storage classes for buffers in a particular
memory space, e.g., StorageBuffer for Vulkan vs. CrossWorkgroup
for OpenCL when converting the default 0 memory space. Hardcoding
a specific mapping makes that hard. While it's possible to embed
selection logic further inside the main type converter, it will
make the main type converter even complicated. So it's better to
separate the concerns, as mapping the memory space is really
concretizing the meaning of those numeric memory spaces in the
particular context of SPIR-V lowering.

Diff Detail

Event Timeline

antiagainst created this revision.Aug 8 2022, 9:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 9:41 AM
antiagainst requested review of this revision.Aug 8 2022, 9:41 AM
kuhar accepted this revision.Aug 9 2022, 8:44 AM
kuhar added inline comments.
mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
64–65

nit: Consider spelling out these two types instead of using auto. I can't immediately tell the variable type based on the RHS.

This revision is now accepted and ready to land.Aug 9 2022, 8:44 AM
antiagainst marked an inline comment as done.Aug 9 2022, 11:27 AM
This revision was landed with ongoing or failed builds.Aug 9 2022, 11:30 AM
This revision was automatically updated to reflect the committed changes.