Skip to content

Commit

Permalink
[mlir][sparse] add source materizalization callback for sparse tensor…
Browse files Browse the repository at this point in the history
… codegen type converter.

Required by scf.for to achieve 1:N type conversion (See D136314).

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D136367
  • Loading branch information
PeimingLiu committed Oct 20, 2022
1 parent 4c49097 commit d12d485
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
Expand Up @@ -745,6 +745,17 @@ class SparseConvertConverter : public OpConversionPattern<ConvertOp> {
mlir::SparseTensorTypeToBufferConverter::SparseTensorTypeToBufferConverter() {
addConversion([](Type type) { return type; });
addConversion(convertSparseTensorType);

// Required by scf.for 1:N type conversion.
addSourceMaterialization([](OpBuilder &builder, RankedTensorType tp,
ValueRange inputs,
Location loc) -> Optional<Value> {
if (!getSparseTensorEncoding(tp))
// Not a sparse tensor.
return llvm::None;
// Sparse compiler knows how to cancel out these casts.
return genTuple(builder, loc, tp, inputs);
});
}

//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit d12d485

Please sign in to comment.