-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][sparse] introduce MapRef, unify conversion/codegen for reader (#…
…68360) 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).
- Loading branch information
Showing
14 changed files
with
437 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//===- MapRef.h - A dim2lvl/lvl2dim map encoding ----------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// A dim2lvl/lvl2dim map encoding class, with utility methods. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_MAPREF_H | ||
#define MLIR_EXECUTIONENGINE_SPARSETENSOR_MAPREF_H | ||
|
||
#include <cinttypes> | ||
|
||
#include <cassert> | ||
#include <vector> | ||
|
||
namespace mlir { | ||
namespace sparse_tensor { | ||
|
||
/// A class for capturing the sparse tensor type map with a compact encoding. | ||
/// | ||
/// Currently, the following situations are supported: | ||
/// (1) map is a permutation | ||
/// (2) map has affine ops (restricted set) | ||
/// | ||
/// The pushforward/backward operations are fast for (1) but incur some obvious | ||
/// overhead for situation (2). | ||
/// | ||
class MapRef final { | ||
public: | ||
MapRef(uint64_t d, uint64_t l, const uint64_t *d2l, const uint64_t *l2d); | ||
|
||
// | ||
// Push forward maps from dimensions to levels. | ||
// | ||
|
||
template <typename T> | ||
inline void pushforward(const T *in, T *out) const { | ||
if (isPermutation) { | ||
for (uint64_t i = 0; i < lvlRank; ++i) | ||
out[i] = in[lvl2dim[i]]; | ||
} else { | ||
assert(0 && "coming soon"); | ||
} | ||
} | ||
|
||
// | ||
// Push backward maps from levels to dimensions. | ||
// | ||
|
||
template <typename T> | ||
inline void pushbackward(const T *in, T *out) const { | ||
if (isPermutation) { | ||
for (uint64_t i = 0; i < dimRank; ++i) | ||
out[i] = in[dim2lvl[i]]; | ||
} else { | ||
assert(0 && "coming soon"); | ||
} | ||
} | ||
|
||
uint64_t getDimRank() const { return dimRank; } | ||
uint64_t getLvlRank() const { return lvlRank; } | ||
|
||
private: | ||
bool isPermutationMap() const; | ||
|
||
const uint64_t dimRank; | ||
const uint64_t lvlRank; | ||
const uint64_t *const dim2lvl; // non-owning pointer | ||
const uint64_t *const lvl2dim; // non-owning pointer | ||
const bool isPermutation; | ||
}; | ||
|
||
} // namespace sparse_tensor | ||
} // namespace mlir | ||
|
||
#endif // MLIR_EXECUTIONENGINE_SPARSETENSOR_MAPREF_H |
Oops, something went wrong.