Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize together all the memref flatteners #20226

Open
4 tasks
krzysz00 opened this issue Mar 12, 2025 · 0 comments
Open
4 tasks

Generalize together all the memref flatteners #20226

krzysz00 opened this issue Mar 12, 2025 · 0 comments
Assignees

Comments

@krzysz00
Copy link
Contributor

Context

Upstream and IREE have several , sometimes half-baked, copies of "make all N > 0-D memrefs 1D, exposing their indexing math".

Upstream has one in EmulateNarrowTypes

... and GPU/DecomposeMemRefs, which is throwing away size information for no good reason

... and I wouldn't be surprised if there's one in the SPIR-V lowering somewhere.

IREE definitely has its own flattener over in the SPIR-V path, and, if I remember right, has a different one in the VMVX path.

Tasks

This has gone on long enough. So, we must:

  • Add an upstream pass, something like -memref-flatten, that rewrites N-D memrefs to 1-D memrefs where possible
  • Refactor the memref narrow type emulator to either use those flattening patterns or to have it as a prerequisite that they've been run
  • Probably put up a deprecation notice on GPU's decompose-memrefs saying folks should migrate to running the flattener on their gpu.module
  • Find all the cases where IREE uses a custom memref flattener and replace them with a unified -iree-memref-flatten (that'll grow patterns for HAL subspan bindings)

Note: subviews

During this sort of flattening, there're two approaches to subviews that are noticable. They roughly correspond to the two functions in ExtractStridedMetadata - the one that has the subview -> reinterpret_cast fold (populateExpandStridedMetadataPatterns) and the one that assumes that subviews have already been dealt with by -memref-fold-alias-ops (populateResolveExtractStridedMetadataPatterns)

That is, one can either rewrite a subview into a reinterpret_cast, adding the base of the subview to the offset of your memref, or you can declare that subview is not allowed this far down the lowering pipeline.

Different pipelines might have different opinions on this, so I figure this pass should implement both options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants