Skip to content

Conversation

@andrey-golubev
Copy link
Contributor

@andrey-golubev andrey-golubev commented Nov 6, 2025

Summary

Please add a short but exhaustive summary why you think your pull request is useful

Over the course of the year, upstream MLIR was gradually updated to allow custom types in one-shot bufferization. The result of it is a collection of patches that, from my perspective, should be sufficient to allow us to use "upstream" MLIR directly, without needing to maintain our own patches. This PR summarizes all of this work.

Notable changes:

  • Our custom patches related to one-shot bufferization are reverted
  • Upstream patches are cherry-picked
    • New type interfaces are added: TensorLikeTypeInterface and BufferLikeTypeInterface
    • Multiple facilities (but not all) within one-shot bufferization are updated to work with these new type interfaces

JIRA ticket

Related PR in NPU Compiler and/or OpenVINO repository with sub-module update

  • PR-xxx

Other related tickets

List tickets for additional work, eg, something was found during review but you agreed to address it in another Jira

  • E-xxxxx

@andrey-golubev andrey-golubev requested a review from a team as a code owner November 6, 2025 15:04
Copy link
Contributor

@hrotuna hrotuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for handling this! Do you know if all of these patches have already landed in LLVM 21?

@andrey-golubev
Copy link
Contributor Author

Thank you for handling this! Do you know if all of these patches have already landed in LLVM 21?

Not all. I think a couple of them are in LLVM 21, the rest are in LLVM 22.

@andrey-golubev andrey-golubev force-pushed the agolubev/new_bufferization branch from 37ba4b2 to 9c1649d Compare November 10, 2025 08:22
…4220)

Current one-shot bufferization infrastructure operates on top of
TensorType and BaseMemRefType. These are non-extensible base classes of
the respective builtins: tensor and memref. Thus, the infrastructure is
bound to work only with builtin tensor/memref types. At the same time,
there are customization points that allow one to provide custom logic to
control the bufferization behavior.

This patch introduces new type interfaces: tensor-like and buffer-like
that aim to supersede TensorType/BaseMemRefType within the bufferization
dialect and allow custom tensors / memrefs to be used. Additionally,
these new type interfaces are attached to the respective builtin types
so that the switch is seamless.

Note that this patch does very minimal initial work, it does NOT
refactor bufferization infrastructure.

See https://discourse.llvm.org/t/rfc-changing-base-types-for-tensors-and-memrefs-from-c-base-classes-to-type-interfaces/85509
As part of the work on transitioning bufferization dialect, ops, and
associated logic to operate on newly added type interfaces (see
00eaff3), rename the
bufferization.to_memref to highlight the generic nature of the op.

Bufferization process produces buffers while memref is a builtin type
rather than a generic term.

Preserve the current API (to_buffer still produces a memref), however,
as the new type interfaces are not used yet.
… (#144658)

Generally, bufferization should be able to create a memref from a tensor
without needing to know more than just a mlir::Type. Thus, change
BufferizationOptions::UnknownTypeConverterFn to accept just a type
(mlir::TensorType for now) instead of mlir::Value. Additionally, apply
the same rationale to getMemRefType() helper function.

Both changes are prerequisites to enable custom types support in
one-shot bufferization.
Following the addition of TensorLike and BufferLike type interfaces (see
00eaff3), introduce minimal changes
required to bufferize a custom tensor operation into a custom buffer
operation.

To achieve this, new interface methods are added to TensorLike type
interface that abstract away the differences between existing (tensor ->
memref) and custom conversions.

The scope of the changes is intentionally limited (for example,
BufferizableOpInterface is untouched) in order to first understand the
basics and reach consensus design-wise.

---
Notable changes:
* mlir::bufferization::getBufferType() returns BufferLikeType (instead
of BaseMemRefType)
* ToTensorOp / ToBufferOp operate on TensorLikeType / BufferLikeType.
Operation argument "memref" renamed to "buffer"
* ToTensorOp's tensor type inferring builder is dropped (users now need
to provide the tensor type explicitly)
…e (#144867)

Support custom types (2/N): allow value-owning operations (e.g.
allocation ops) to bufferize custom tensors into custom buffers. This
requires BufferizableOpInterface::getBufferType() to return
BufferLikeType instead of BaseMemRefType.

Affected implementors of the interface are updated accordingly.

Relates to ee070d0.
…59766)

Support custom types (3/N): allow custom tensor and buffer types in
function signatures and at call-sites. This is one of the major building
blocks to move in the direction of module-level one-shot-bufferization
support.

To achieve this, `BufferizationOptions::FunctionArgTypeConverterFn`
callback is converted to work with tensor-like and buffer-like types,
instead of the builtin counterparts. The default behavior for builtins
remains unchanged, while custom types by default go through
`TensorLikeType::getBufferType()` which is a general conversion
interface.
@andrey-golubev andrey-golubev merged commit a765903 into npu/release/20.x Nov 10, 2025
8 checks passed
@andrey-golubev andrey-golubev deleted the agolubev/new_bufferization branch November 11, 2025 08:07
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

Successfully merging this pull request may close these issues.

4 participants