MLIR
18.0.0git
|
The code generation environment class aggregates a number of data structures that are needed during the code generation phase of sparsification. More...
#include "Dialect/SparseTensor/Transforms/CodegenEnv.h"
Public Member Functions | |
CodegenEnv (linalg::GenericOp linop, SparsificationOptions opts, unsigned numTensors, unsigned numLoops, unsigned maxRank) | |
Constructs a code generation environment which can be passed around during sparsification for bookkeeping together with some consistency asserts. More... | |
LogicalResult | initTensorExp () |
ExprId | getExprId () const |
linalg::GenericOp | op () const |
const SparsificationOptions & | options () const |
Merger & | merger () |
LoopEmitter & | emitter () |
void | startEmit () |
std::optional< Operation * > | genLoopBoundary (function_ref< std::optional< Operation * >(MutableArrayRef< Value > parameters)> callback) |
Generates loop boundary statements (entering/exiting loops). More... | |
constexpr TensorId | makeTensorId (unsigned t) const |
constexpr LoopId | makeLoopId (unsigned i) const |
constexpr TensorLoopId | makeTensorLoopId (unsigned t, unsigned i) const |
const TensorExp & | exp (ExprId e) const |
const LatPoint & | lat (LatPointId l) const |
ArrayRef< LatPointId > | set (LatSetId s) const |
LevelType | lt (TensorId t, LoopId i) const |
LevelType | lt (TensorLoopId b) const |
unsigned | getLoopNum () const |
TensorLevel | makeTensorLevel (TensorId t, Level l) const |
TensorLevel | makeTensorLevel (std::pair< TensorId, Level > tlPair) const |
std::pair< TensorId, Level > | unpackTensorLevel (TensorLevel tl) const |
template<class ContainerTy > | |
auto | unpackTensorLevelRange (ContainerTy &&c) const |
unsigned | getLoopDepth () const |
bool | isAdmissibleTensorExp (ExprId e) |
Whether the tensor expression is admissible for codegen. More... | |
Value | getLoopVar (LoopId i) const |
Returns the induction-variable for the loop identified by the given LoopId . More... | |
bool | hasSparseOutput () const |
bool | isSparseOutput (OpOperand *o) const |
Value | getInsertionChain () const |
void | updateInsertionChain (Value chain) |
bool | atExpandLevel (OpOperand *o, unsigned rank, LoopOrd n) const |
void | startExpand (Value values, Value filled, Value added, Value count) |
bool | isExpand () const |
void | updateExpandCount (Value count) |
Value | getExpandValues () const |
Value | getExpandFilled () const |
Value | getExpandAdded () const |
Value | getExpandCount () const |
void | endExpand () |
void | startReduc (ExprId exp, Value val) |
bool | isReduc () const |
void | updateReduc (Value val) |
Value | getReduc () const |
Value | endReduc () |
void | setValidLexInsert (Value val) |
void | clearValidLexInsert () |
Value | getValidLexInsert () const |
void | startCustomReduc (ExprId exp) |
bool | isCustomReduc () const |
Value | getCustomRedId () |
void | endCustomReduc () |
The code generation environment class aggregates a number of data structures that are needed during the code generation phase of sparsification.
This environment simplifies passing around such data during sparsification (rather than passing around all the individual compoments where needed). Furthermore, it provides convience methods that keep implementation details transparent to sparsification while asserting on internal consistency.
Definition at line 35 of file CodegenEnv.h.
CodegenEnv::CodegenEnv | ( | linalg::GenericOp | linop, |
SparsificationOptions | opts, | ||
unsigned | numTensors, | ||
unsigned | numLoops, | ||
unsigned | maxRank | ||
) |
Constructs a code generation environment which can be passed around during sparsification for bookkeeping together with some consistency asserts.
Definition at line 44 of file CodegenEnv.cpp.
Definition at line 210 of file CodegenEnv.cpp.
void CodegenEnv::clearValidLexInsert | ( | ) |
Definition at line 266 of file CodegenEnv.cpp.
References isReduc().
|
inline |
Definition at line 53 of file CodegenEnv.h.
Referenced by endLoop(), endLoopSeq(), genCoIteration(), genIf(), genSubscript(), startLoop(), and startLoopSeq().
void CodegenEnv::endCustomReduc | ( | ) |
Definition at line 281 of file CodegenEnv.cpp.
References isCustomReduc(), and mlir::sparse_tensor::detail::kInvalidId.
void CodegenEnv::endExpand | ( | ) |
Definition at line 229 of file CodegenEnv.cpp.
Value CodegenEnv::endReduc | ( | ) |
Definition at line 252 of file CodegenEnv.cpp.
References mlir::sparse_tensor::Merger::clearExprValue(), isReduc(), and mlir::sparse_tensor::detail::kInvalidId.
Definition at line 77 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::exp().
Referenced by genInvariants(), genInvariantValue(), genTensorLoad(), genTensorStore(), getCustomRedId(), isAdmissibleTensorExp(), startCustomReduc(), and startReduc().
std::optional< Operation * > CodegenEnv::genLoopBoundary | ( | function_ref< std::optional< Operation * >(MutableArrayRef< Value > parameters)> | callback | ) |
Generates loop boundary statements (entering/exiting loops).
The function passes and updates the passed-in parameters.
Definition at line 112 of file CodegenEnv.cpp.
References isExpand(), isReduc(), setValidLexInsert(), updateExpandCount(), updateInsertionChain(), and updateReduc().
Referenced by endLoop(), and genCoIteration().
Value CodegenEnv::getCustomRedId | ( | ) |
Definition at line 276 of file CodegenEnv.cpp.
References exp(), isCustomReduc(), and op().
|
inline |
Definition at line 143 of file CodegenEnv.h.
|
inline |
Definition at line 144 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), and genStmt().
|
inline |
Definition at line 142 of file CodegenEnv.h.
|
inline |
Definition at line 141 of file CodegenEnv.h.
|
inline |
Definition at line 48 of file CodegenEnv.h.
|
inline |
Definition at line 133 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), genIf(), and genStmt().
|
inline |
Definition at line 111 of file CodegenEnv.h.
References mlir::sparse_tensor::LoopEmitter::getCurrentDepth().
|
inline |
Definition at line 85 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::getNumLoops().
Referenced by genStmt(), isAdmissibleTensorExp(), and startEmit().
Returns the induction-variable for the loop identified by the given LoopId
.
This method handles application of the topological sort in order to convert the LoopId
into the corresponding LoopOrd
.
Definition at line 196 of file CodegenEnv.cpp.
References mlir::sparse_tensor::LoopEmitter::getLoopIV().
Referenced by endLoopSeq(), genIf(), genIndex(), and startLoopSeq().
|
inline |
Definition at line 154 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), genIf(), and genStmt().
|
inline |
Definition at line 158 of file CodegenEnv.h.
Referenced by endIf(), endLoop(), finalizeWhileOp(), genIf(), and genStmt().
|
inline |
Definition at line 130 of file CodegenEnv.h.
Referenced by isParallelFor().
LogicalResult CodegenEnv::initTensorExp | ( | ) |
Definition at line 52 of file CodegenEnv.cpp.
References mlir::sparse_tensor::Merger::buildTensorExpFromLinalg(), mlir::failure(), isAdmissibleTensorExp(), op(), and mlir::success().
bool CodegenEnv::isAdmissibleTensorExp | ( | ExprId | e | ) |
Whether the tensor expression is admissible for codegen.
It also sets the sparseOut if the output tensor is sparse.
Definition at line 145 of file CodegenEnv.cpp.
References exp(), mlir::IROperand< DerivedT, IRValueT >::get(), getLoopNum(), mlir::OpOperand::getOperandNumber(), mlir::sparse_tensor::getSparseTensorType(), mlir::sparse_tensor::Merger::hasNegateOnOut(), mlir::sparse_tensor::SparseTensorType::isAllDense(), isMaterializing(), mlir::linalg::isReductionIterator(), mlir::sparse_tensor::Merger::isSingleCondition(), and makeTensorId().
Referenced by initTensorExp().
|
inline |
Definition at line 161 of file CodegenEnv.h.
References mlir::sparse_tensor::detail::kInvalidId.
Referenced by endCustomReduc(), getCustomRedId(), and startCustomReduc().
|
inline |
Definition at line 139 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), genIf(), genLoopBoundary(), and isParallelFor().
|
inline |
Definition at line 152 of file CodegenEnv.h.
References mlir::sparse_tensor::detail::kInvalidId.
Referenced by clearValidLexInsert(), endIf(), endLoop(), endReduc(), finalizeWhileOp(), genIf(), genLoopBoundary(), genTensorStore(), setValidLexInsert(), startReduc(), and updateReduc().
|
inline |
Definition at line 131 of file CodegenEnv.h.
|
inline |
Definition at line 78 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::lat().
Referenced by genStmt(), startLoopSeq(), and translateBitsToTidLvlPairs().
Definition at line 80 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::getLvlType().
|
inline |
Definition at line 83 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::getLvlType().
|
inlineconstexpr |
Definition at line 71 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::makeLoopId().
Referenced by genIndex().
|
inlineconstexpr |
Definition at line 68 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::makeTensorId().
Referenced by findSparseAnnotations(), genSubscript(), isAdmissibleTensorExp(), and startEmit().
|
inline |
Definition at line 100 of file CodegenEnv.h.
References makeTensorLevel().
|
inline |
Definition at line 91 of file CodegenEnv.h.
References mlir::sparse_tensor::LoopEmitter::getNumManifestTensors(), mlir::sparse_tensor::Merger::getNumTensors(), mlir::sparse_tensor::LoopEmitter::getNumTensors(), mlir::sparse_tensor::Merger::getOutTensorID(), mlir::sparse_tensor::LoopEmitter::getOutTensorId(), mlir::sparse_tensor::Merger::getSynTensorID(), mlir::sparse_tensor::LoopEmitter::getSynTensorId(), and mlir::sparse_tensor::LoopEmitter::makeTensorLevel().
Referenced by makeTensorLevel(), startEmit(), startLoopSeq(), and translateBitsToTidLvlPairs().
|
inlineconstexpr |
Definition at line 74 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::makeTensorLoopId().
|
inline |
Definition at line 52 of file CodegenEnv.h.
Referenced by findSparseAnnotations(), genIf(), genStmt(), startEmit(), startLoop(), startLoopSeq(), and translateBitsToTidLvlPairs().
|
inline |
Definition at line 50 of file CodegenEnv.h.
Referenced by endIf(), endLoop(), endLoopSeq(), finalizeWhileOp(), findSparseAnnotations(), genCoIteration(), genIf(), genIndex(), genInitConstantDenseAddress(), genSubscript(), getCustomRedId(), initTensorExp(), startLoop(), and startLoopSeq().
|
inline |
Definition at line 51 of file CodegenEnv.h.
Referenced by isParallelFor().
|
inline |
Definition at line 79 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::set().
Referenced by genStmt(), and startLoopSeq().
void CodegenEnv::setValidLexInsert | ( | Value | val | ) |
Definition at line 261 of file CodegenEnv.cpp.
References isReduc().
Referenced by endIf(), endLoop(), finalizeWhileOp(), and genLoopBoundary().
void CodegenEnv::startCustomReduc | ( | ExprId | exp | ) |
Definition at line 271 of file CodegenEnv.cpp.
References exp(), isCustomReduc(), and mlir::sparse_tensor::detail::kInvalidId.
void CodegenEnv::startEmit | ( | ) |
Definition at line 62 of file CodegenEnv.cpp.
References mlir::IROperand< DerivedT, IRValueT >::get(), mlir::get(), mlir::sparse_tensor::Merger::getDependentLoops(), getLoopNum(), mlir::sparse_tensor::getSparseTensorEncoding(), mlir::sparse_tensor::LoopEmitter::initialize(), makeTensorId(), makeTensorLevel(), merger(), mlir::sparse_tensor::Merger::setHasSparseOut(), and sortDependentLoops().
Definition at line 215 of file CodegenEnv.cpp.
Definition at line 238 of file CodegenEnv.cpp.
References exp(), isReduc(), mlir::sparse_tensor::detail::kInvalidId, and mlir::sparse_tensor::Merger::setExprValue().
|
inline |
Definition at line 103 of file CodegenEnv.h.
References mlir::sparse_tensor::LoopEmitter::unpackTensorLevel().
|
inline |
Definition at line 107 of file CodegenEnv.h.
References mlir::sparse_tensor::LoopEmitter::unpackTensorLevelRange().
Referenced by startLoop().
void CodegenEnv::updateExpandCount | ( | Value | count | ) |
Definition at line 224 of file CodegenEnv.cpp.
Referenced by endIf(), finalizeWhileOp(), and genLoopBoundary().
void CodegenEnv::updateInsertionChain | ( | Value | chain | ) |
Definition at line 204 of file CodegenEnv.cpp.
Referenced by endIf(), finalizeWhileOp(), and genLoopBoundary().
void CodegenEnv::updateReduc | ( | Value | val | ) |
Definition at line 245 of file CodegenEnv.cpp.
References mlir::sparse_tensor::Merger::clearExprValue(), isReduc(), and mlir::sparse_tensor::Merger::setExprValue().
Referenced by endIf(), finalizeWhileOp(), genLoopBoundary(), and genTensorStore().