[mlir][bufferization] Alternate op bufferization approach#199898
[mlir][bufferization] Alternate op bufferization approach#199898andrey-golubev wants to merge 2 commits into
Conversation
The implementation for a builtin TensorType's TensorLikeType interface is a bit overly complex for no reason: it calls `getMemRefType()` whereas in reality `options.unknownTypeConverterFn()` would directly be called due to the way the current code is written. Remove what is effectively a wrapper function so that the current semantics is a bit clearer.
Make op bufferization go through type bufferization, by differentiating between "known" and "unknown" cases better: when the type is known, i.e. it is upstream-MLIR-aligned, TensorLikeType::getBufferType() would dispatch to an op-provided bufferization callback; when the type is unknown, unknown type converter would be called instead. In return, this allows operation bufferization to be extended with custom semantics without sacrificing the upstream's default behaviour.
🐧 Linux x64 Test ResultsThe build failed before running any tests. Click on a failure below to see the details. lib/Target/RISCV/CMakeFiles/LLVMRISCVCodeGen.dir/RISCVISelLowering.cpp.oIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
🪟 Windows x64 Test ResultsThe build failed before running any tests. Click on a failure below to see the details. [code=1] lib/Target/RISCV/CMakeFiles/LLVMRISCVCodeGen.dir/RISCVISelLowering.cpp.objIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
| return cast<TensorLikeType>(getType()).getBufferType( | ||
| options, [&]() { return emitError(); }, defaultGetBufferType); |
There was a problem hiding this comment.
@matthias-springer this would be the way I'd love to see bufferization done (or somehow similarly) for "owners" of values. what we have from this is 2 things:
a) custom type bufferization (e.g. for non-upstream-tensors) is now "natively" supported - i.e. we don't need any special dispatch, it just works due to an interface
b) "unknown" encoding causes unknown type conversion behind the scenes for upstream tensor; and users can define what "unknown encoding" means also.
at the same time, the "fallback" bufferization also exists and can still be used if desired.
I am not 100% sure about the new API, but this feels to be the direction.
Make op bufferization go through type bufferization, by differentiating
between "known" and "unknown" cases better: when the type is known, i.e.
it is upstream-MLIR-aligned, TensorLikeType::getBufferType() would
dispatch to an op-provided bufferization callback; when the type is
unknown, unknown type converter would be called instead.
In return, this allows operation bufferization to be extended with
custom semantics without sacrificing the upstream's default behaviour.