[mlir][sparse] fully implement sparse tensor to sparse tensor conversions

with rigorous integration test

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D108721
This commit is contained in:
Aart Bik
2021-08-25 22:23:46 -07:00
parent 063af63b96
commit 0a7b8cc5dd
3 changed files with 277 additions and 4 deletions

View File

@@ -283,11 +283,23 @@ class SparseTensorConvertConverter : public OpConversionPattern<ConvertOp> {
Type resType = op.getType();
auto encDst = getSparseTensorEncoding(resType);
auto encSrc = getSparseTensorEncoding(op.source().getType());
// TODO: implement sparse => sparse
// and sparse => dense
if (!encDst || encSrc)
if (encDst && encSrc) {
// This is a sparse => sparse conversion, which is handled as follows:
// t = src->asCOO(); ; src to COO in dst order
// dst = newSparseTensor(t)
// Using the coordinate scheme as an intermediate does not always
// yield the fastest conversion but avoids the need for a full
// O(N^2) conversion matrix.
Value perm;
Value coo = genNewCall(rewriter, op, encDst, 3, perm, operands[0]);
rewriter.replaceOp(op, genNewCall(rewriter, op, encDst, 1, perm, coo));
return success();
}
if (!encDst || encSrc) {
// TODO: sparse => dense
return failure();
// This is a dense => sparse conversion, that is handled as follows:
}
// This is a dense => sparse conversion, which is handled as follows:
// t = newSparseCOO()
// for i1 in dim1
// ..