Hello,
Our downstream recently started to migrate to one-shot bufferization and the existing design (LLVM 17 for us but main seems to be affected as well) doesn’t really work for us.
The topic of this discussion is around the conversions from tensors to memrefs and from memrefs to tensors. From what I can tell, the existing conversion logic is very limited and extremely rigid. Our downstream has the following:
- custom tensors and custom memrefs (and they do not inherit respective MLIR-native types)
- mlir::RankedTensorType with custom
encodingattribute - mlir::MemRefType with custom
layoutattribute
Problem 1: so far it looks like custom types are out of the question completely: operations like bufferization.to_tensor, bufferization.to_memref (and probably others) would complain that our types are not “mlir::TensorType” / “mlir::BaseMemRefType”.
Problem 2: Then, there is no way to convert encoding to layout and layout to encoding, nor there’s a way to customize the general MLIR-native tensor → memref / memref → tensor conversions.
With some upstream patching (see this discussion) - making base tensor / memref types into interfaces - we actually managed to partially solve problem 1. Now we’re trying to deal with the problem 2 in various shapes and forms: generally, we’d want to be able to completely customize the way tensor → memref conversion happens (as well as memref → tensor because apparently it is also necessary). The issue with this is that some conversion functionality is implemented as free-standing functions.
The major questions from us would be:
- Do you envision that tensor → memref conversion route should carry on any user-specified / standard transformations? For instance:
- preserve
layoutduring “memref → tensor → memref” roundtrip (according to this, no?) - preserve
encodingduring “tensor → memref → tensor” roundtrip
- preserve
- Do you have some ideas as to how to introduce the customization points for conversions?
- One idea that I have is via
MLIRContext(which seems to be the only available object that could be fetched in free-standing functions) - having aFuncRefinside of it forgetTensorFromMemref/getMemrefFromTensor(with default implementations as they are now) should work in theory - Another idea that we’re currently running with internally is to introduce a special “conversion” interface to tensor and memref with
getMemrefFromTensorandgetTensorFromMemrefinterface methods respectively + make it possible to replace basic interface implementation with a custom one (seems like it is possible in a dirty way already viaType::attachInterface<>()mechanism)
- One idea that I have is via
Needless to say, we plan to push our patches to upstream but this would only really work out if there’s at least some consensus w.r.t. custom tensors / memrefs support and related functionality.
Thanks in advance for help and suggestions.