This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Add `memory_space` op attribute
ClosedPublic

Authored by springerm on Jun 21 2022, 6:59 AM.

Details

Summary

This attribute is currently supported on AllocTensorOp only. Future changes will add support to other ops. Furthermore, the memory space is not propagated properly in all bufferization patterns and some of the core bufferization infrastructure. This will be addressed in a subsequent change.

Depends On D128137

Diff Detail

Event Timeline

springerm created this revision.Jun 21 2022, 6:59 AM
springerm requested review of this revision.Jun 21 2022, 6:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2022, 6:59 AM
nicolasvasilache requested changes to this revision.Jun 24 2022, 8:26 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
115 ↗(On Diff #438685)

this looks fishy, this should be an attribute directly on the op you are interested in and with proper Tablegen definition most of this code and tests become unnecessary

What's the rationale behind the current approach?

This revision now requires changes to proceed.Jun 24 2022, 8:26 AM
springerm requested review of this revision.Jun 24 2022, 9:56 AM
springerm marked an inline comment as done.
springerm added inline comments.
mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
115 ↗(On Diff #438685)

memory_space is an attribute that can be added to any op that may bufferize to an allocation. E.g.:

  • bufferization.alloc_tensor
  • sparse_tensor.new
  • sparse_tensor.convert
  • tensor.collapse_shape

By making it a dialect attribute, we can avoid code duplication around those ops, treat them uniformly in the code base, and have some basic verification.

Also, we probably don't want to have this attribute on ops such as tensor.collapse_shape directly (separation of concerns). Ideally, there would be a trait that adds this attribute via an external model registration.... This is not possible in MLIR and this is the next best thing.

springerm marked an inline comment as done.Jun 24 2022, 9:59 AM
springerm added inline comments.
mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
115 ↗(On Diff #438685)

For tensor.collapse_shape and sparse_tensor.convert, we usually would not add the attribute because the memory space can be inferred.

But there is another dialect attribute bufferization.escape that is implemented in the same way. And that attr applies to all 4 ops that I mentioned above.

springerm updated this revision to Diff 440145.Jun 27 2022, 3:10 AM

address comments

springerm retitled this revision from [mlir][bufferization] Add `memory_space` dialect attribute to [mlir][bufferization] Add `memory_space` op attribute.Jun 27 2022, 3:10 AM
nicolasvasilache accepted this revision.Jun 27 2022, 3:10 AM

Thanks! Please update the title before landing.

This revision is now accepted and ready to land.Jun 27 2022, 3:10 AM
This revision was automatically updated to reflect the committed changes.