From: bixia1 Date: Thu, 20 Oct 2022 22:43:03 +0000 (-0700) Subject: [mlir][sparse] Fix getUnorderedCOOFromType for rank 1 tensor. X-Git-Tag: upstream/17.0.6~29978 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf7906cbbdd50cc414c1df40f149c3aaf7a56cba;p=platform%2Fupstream%2Fllvm.git [mlir][sparse] Fix getUnorderedCOOFromType for rank 1 tensor. Previously, it used DimLevelType::SingletonNo to represent an unorder COO tensor of rank 1 while it should use DimLevelType::CompressedNuNo. Reviewed By: Peiming, wrengr Differential Revision: https://reviews.llvm.org/D136387 --- diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp index a852a15..4707115 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp @@ -132,18 +132,19 @@ static RankedTensorType getUnorderedCOOFromType(RankedTensorType src) { auto rank = src.getRank(); SmallVector dims; - // An unordered and non-unique compressed dim at beginning unless the tensor - // is a 1D tensor. - if (rank > 1) - dims.push_back(DimLevelType::CompressedNuNo); - - // TODO: it is actually ordered at the level for ordered input. - // Followed by unordered non-unique n-2 singleton levels. - std::fill_n(std::back_inserter(dims), rank - 2, DimLevelType::SingletonNuNo); - // TODO: only if all the inputs (for concatentate) are unique at the last - // level should the COO has a unique level at the end. Ends by a unordered - // unique singleton level. - dims.push_back(DimLevelType::SingletonNo); + // An unordered and non-unique compressed dim at beginning. + dims.push_back(DimLevelType::CompressedNuNo); + + if (rank > 1) { + // TODO: it is actually ordered at the level for ordered input. + // Followed by unordered non-unique n-2 singleton levels. + std::fill_n(std::back_inserter(dims), rank - 2, + DimLevelType::SingletonNuNo); + // TODO: only if all the inputs (for concatentate) are unique at the last + // level should the COO has a unique level at the end. Ends by a unordered + // unique singleton level unless the tensor rank is 1. + dims.push_back(DimLevelType::SingletonNo); + } SparseTensorEncodingAttr encSrc = getSparseTensorEncoding(src); // TODO: Maybe pick the bitwidth based on input/output tensors (probably the // largest one among them) in the original operation instead of using the