MLIR
20.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/Utils/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 |
bool | generatingSparseIterator () const |
Merger & | merger () |
LoopEmitter & | emitter () |
void | startEmit (SparseEmitStrategy emitStrategy) |
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 | getCurrentDepth () 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 given loop. More... | |
bool | hasSparseOutput () const |
bool | isSparseOutput (OpOperand *o) const |
Value | getInsertionChain () const |
void | updateInsertionChain (Value chain) |
bool | atExpandLevel (OpOperand *o, unsigned rank, LoopId 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 | startValidLexInsert (Value val) |
bool | isValidLexInsert () const |
void | updateValidLexInsert (Value val) |
Value | getValidLexInsert () const |
void | endValidLexInsert () |
void | startCustomReduc (ExprId exp) |
bool | isCustomReduc () const |
Value | getCustomRedId () const |
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 200 of file CodegenEnv.cpp.
Referenced by genExpand().
|
inline |
Definition at line 57 of file CodegenEnv.h.
Referenced by endLoop(), endLoopSeq(), genBuffers(), genCoIteration(), genCoIterationCase(), genConstantDenseAddressFromLevel(), genIf(), genInsertionStore(), genResult(), genSubscript(), startLoop(), and startLoopSeq().
void CodegenEnv::endCustomReduc | ( | ) |
Definition at line 276 of file CodegenEnv.cpp.
References isCustomReduc(), and mlir::sparse_tensor::detail::kInvalidId.
Referenced by genExp(), and genInvariants().
void CodegenEnv::endExpand | ( | ) |
Definition at line 219 of file CodegenEnv.cpp.
Value CodegenEnv::endReduc | ( | ) |
Definition at line 242 of file CodegenEnv.cpp.
References mlir::sparse_tensor::Merger::clearExprValue(), isReduc(), and mlir::sparse_tensor::detail::kInvalidId.
Referenced by genInvariants().
void CodegenEnv::endValidLexInsert | ( | ) |
Definition at line 261 of file CodegenEnv.cpp.
References isReduc(), and isValidLexInsert().
Referenced by genInvariants().
Definition at line 81 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::exp().
Referenced by genExp(), genInvariants(), genInvariantValue(), genTensorLoad(), genTensorStore(), getCustomRedId(), isAdmissibleTensorExp(), startCustomReduc(), and startReduc().
|
inline |
Definition at line 52 of file CodegenEnv.h.
References mlir::kSparseIterator, and mlir::SparsificationOptions::sparseEmitStrategy.
Referenced by genStmt().
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 103 of file CodegenEnv.cpp.
References isExpand(), isReduc(), and isValidLexInsert().
Referenced by endLoop(), genCoIteration(), and genStmt().
|
inline |
Definition at line 115 of file CodegenEnv.h.
References mlir::sparse_tensor::LoopEmitter::getCurrentDepth().
Referenced by genInsertionStore(), genStmt(), and getAllTidLvlsInLatPoints().
Value CodegenEnv::getCustomRedId | ( | ) | const |
Definition at line 271 of file CodegenEnv.cpp.
References exp(), isCustomReduc(), and op().
Referenced by genInsertionLoadReduce(), and genInvariants().
|
inline |
Definition at line 144 of file CodegenEnv.h.
Referenced by genInsertionStore().
|
inline |
Definition at line 145 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), genInsertionStore(), and genStmt().
|
inline |
Definition at line 143 of file CodegenEnv.h.
Referenced by genInsertionLoadReduce(), and genInsertionStore().
|
inline |
Definition at line 142 of file CodegenEnv.h.
Referenced by genInsertionLoad(), genInsertionLoadReduce(), and genInsertionStore().
|
inline |
Definition at line 48 of file CodegenEnv.h.
|
inline |
Definition at line 135 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), genIf(), genInsertionStore(), genResult(), genStmt(), and genTensorStore().
|
inline |
Definition at line 89 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::getNumLoops().
Referenced by genStmt(), isAdmissibleTensorExp(), and startEmit().
Returns the induction-variable for the given loop.
Definition at line 187 of file CodegenEnv.cpp.
References mlir::sparse_tensor::LoopEmitter::getLoopIV().
Referenced by endLoopSeq(), genExp(), genIf(), genIndex(), relinkBranch(), and startLoopSeq().
|
inline |
Definition at line 155 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), genIf(), and genStmt().
|
inline |
Definition at line 161 of file CodegenEnv.h.
Referenced by finalizeWhileOp(), genIf(), genInsertionStore(), and genStmt().
|
inline |
Definition at line 132 of file CodegenEnv.h.
Referenced by genInvariants(), and isParallelFor().
LogicalResult CodegenEnv::initTensorExp | ( | ) |
Definition at line 52 of file CodegenEnv.cpp.
References mlir::sparse_tensor::Merger::buildTensorExpFromLinalg(), isAdmissibleTensorExp(), and op().
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 136 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 165 of file CodegenEnv.h.
References mlir::sparse_tensor::detail::kInvalidId.
Referenced by endCustomReduc(), genInvariants(), genTensorLoad(), getCustomRedId(), and startCustomReduc().
|
inline |
Definition at line 140 of file CodegenEnv.h.
Referenced by endIf(), finalizeWhileOp(), genIf(), genInsertionLoad(), genInsertionLoadReduce(), genInsertionStore(), genLoopBoundary(), and isParallelFor().
|
inline |
Definition at line 153 of file CodegenEnv.h.
References mlir::sparse_tensor::detail::kInvalidId.
Referenced by endIf(), endLoop(), endReduc(), endValidLexInsert(), finalizeWhileOp(), genExpand(), genIf(), genInvariants(), genLoopBoundary(), genTensorStore(), startReduc(), startValidLexInsert(), updateReduc(), and updateValidLexInsert().
|
inline |
Definition at line 133 of file CodegenEnv.h.
Referenced by genTensorLoad(), and genTensorStore().
|
inline |
Definition at line 159 of file CodegenEnv.h.
Referenced by endIf(), endLoop(), endValidLexInsert(), finalizeWhileOp(), genIf(), genInsertionStore(), genLoopBoundary(), and startValidLexInsert().
|
inline |
Definition at line 82 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::lat().
Referenced by genStmt(), getAllTidLvlsInLatPoints(), and startLoopSeq().
Definition at line 84 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::getLvlType().
Referenced by getAllTidLvlsInLatPoints(), and shouldTryParallize().
|
inline |
Definition at line 87 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::getLvlType().
|
inlineconstexpr |
Definition at line 75 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::makeLoopId().
Referenced by genIndex(), and relinkBranch().
|
inlineconstexpr |
Definition at line 72 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::makeTensorId().
Referenced by findSparseAnnotations(), genConstantDenseAddressFromLevel(), genSubscript(), isAdmissibleTensorExp(), relinkBranch(), and startEmit().
|
inline |
Definition at line 104 of file CodegenEnv.h.
References makeTensorLevel().
|
inline |
Definition at line 95 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 genConstantDenseAddressFromLevel(), getAllTidLvlsInLatPoints(), and makeTensorLevel().
|
inlineconstexpr |
Definition at line 78 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::makeTensorLoopId().
|
inline |
Definition at line 56 of file CodegenEnv.h.
Referenced by findSparseAnnotations(), genCoIterationCase(), genExp(), genIf(), genInvariants(), genResult(), genStmt(), genTensorStore(), getAllTidLvlsInLatPoints(), startEmit(), startLoop(), and startLoopSeq().
|
inline |
Definition at line 50 of file CodegenEnv.h.
Referenced by endIf(), endLoop(), endLoopSeq(), finalizeWhileOp(), findSparseAnnotations(), genBuffers(), genCoIteration(), genCoIterationCase(), genConstantDenseAddressFromLevel(), genExp(), genExpand(), genIf(), genIndex(), genInitConstantDenseAddress(), genInsertionLoad(), genInsertionLoadReduce(), genInsertionStore(), genInvariants(), genResult(), genStmt(), genSubscript(), genTensorLoad(), genTensorStore(), getAllTidLvlsInLatPoints(), getCustomRedId(), initTensorExp(), relinkBranch(), shouldTryParallize(), startLoop(), and startLoopSeq().
|
inline |
Definition at line 51 of file CodegenEnv.h.
Referenced by genSubscript(), genTensorLoad(), getAllTidLvlsInLatPoints(), and isParallelFor().
|
inline |
Definition at line 83 of file CodegenEnv.h.
References mlir::sparse_tensor::Merger::set().
Referenced by genStmt(), and startLoopSeq().
void CodegenEnv::startCustomReduc | ( | ExprId | exp | ) |
Definition at line 266 of file CodegenEnv.cpp.
References exp(), isCustomReduc(), and mlir::sparse_tensor::detail::kInvalidId.
Referenced by genExp(), and genInvariants().
void CodegenEnv::startEmit | ( | SparseEmitStrategy | emitStrategy | ) |
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(), merger(), mlir::sparse_tensor::Merger::setHasSparseOut(), and sortDependentLoops().
Definition at line 205 of file CodegenEnv.cpp.
Definition at line 228 of file CodegenEnv.cpp.
References exp(), isReduc(), mlir::sparse_tensor::detail::kInvalidId, and mlir::sparse_tensor::Merger::setExprValue().
Referenced by genInvariants().
void CodegenEnv::startValidLexInsert | ( | Value | val | ) |
Definition at line 251 of file CodegenEnv.cpp.
References isReduc(), and isValidLexInsert().
Referenced by genInvariants().
|
inline |
Definition at line 107 of file CodegenEnv.h.
References mlir::sparse_tensor::LoopEmitter::unpackTensorLevel().
Referenced by shouldTryParallize().
|
inline |
Definition at line 111 of file CodegenEnv.h.
References mlir::sparse_tensor::LoopEmitter::unpackTensorLevelRange().
Referenced by startLoop().
void CodegenEnv::updateExpandCount | ( | Value | count | ) |
Definition at line 214 of file CodegenEnv.cpp.
Referenced by endIf(), finalizeWhileOp(), and genInsertionStore().
void CodegenEnv::updateInsertionChain | ( | Value | chain | ) |
Definition at line 195 of file CodegenEnv.cpp.
Referenced by endIf(), finalizeWhileOp(), genInsertionStore(), and genTensorStore().
void CodegenEnv::updateReduc | ( | Value | val | ) |
Definition at line 235 of file CodegenEnv.cpp.
References mlir::sparse_tensor::Merger::clearExprValue(), isReduc(), and mlir::sparse_tensor::Merger::setExprValue().
Referenced by endIf(), finalizeWhileOp(), and genTensorStore().
void CodegenEnv::updateValidLexInsert | ( | Value | val | ) |
Definition at line 256 of file CodegenEnv.cpp.
References isReduc().
Referenced by endIf(), endLoop(), and finalizeWhileOp().