This revision introduces a MapRef, which will support a future generalization beyond permutations (e.g. block sparsity). This revision also unifies the conversion/codegen paths for the sparse_tensor.new operation from file (eg. the readers). Note that more unification is planned as well as general affine dim2lvl and lvl2dim (all marked with TODOs).
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
//===- MapRef.cpp - A dim2lvl/lvl2dim map reference wrapper ---------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/ExecutionEngine/SparseTensor/MapRef.h"
|
|
|
|
mlir::sparse_tensor::MapRef::MapRef(uint64_t d, uint64_t l, const uint64_t *d2l,
|
|
const uint64_t *l2d)
|
|
: dimRank(d), lvlRank(l), dim2lvl(d2l), lvl2dim(l2d),
|
|
isPermutation(isPermutationMap()) {
|
|
if (isPermutation) {
|
|
for (uint64_t i = 0; i < dimRank; i++)
|
|
assert(lvl2dim[dim2lvl[i]] == i);
|
|
}
|
|
}
|
|
|
|
bool mlir::sparse_tensor::MapRef::isPermutationMap() const {
|
|
if (dimRank != lvlRank)
|
|
return false;
|
|
std::vector<bool> seen(dimRank, false);
|
|
for (uint64_t i = 0; i < dimRank; i++) {
|
|
const uint64_t j = dim2lvl[i];
|
|
if (j >= dimRank || seen[j])
|
|
return false;
|
|
seen[j] = true;
|
|
}
|
|
return true;
|
|
}
|