MLIR: lib/Dialect/SparseTensor/Transforms/SparsificationAndBufferizationPass.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
30
31 using namespace mlir;
32
33 namespace mlir {
34
35 #define GEN_PASS_DEF_SPARSIFICATIONANDBUFFERIZATION
36 #include "mlir/Dialect/SparseTensor/Transforms/Passes.h.inc"
37
38 namespace sparse_tensor {
39
40
42 for (Type t : types)
44 return true;
45 return false;
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
61 : public impl::SparsificationAndBufferizationBase<
62 SparsificationAndBufferizationPass> {
63 public:
64
68 bool createSparseDeallocs, bool enableRuntimeLibrary,
69 bool enableBufferInitialization)
70 : bufferizationOptions(bufferizationOptions),
71 sparsificationOptions(sparsificationOptions),
72 createSparseDeallocs(createSparseDeallocs),
73 enableRuntimeLibrary(enableRuntimeLibrary),
74 enableBufferInitialization(enableBufferInitialization) {}
75
79 bool createSparseDeallocs, bool enableRuntimeLibrary,
80 bool enableBufferInitialization, unsigned vl, bool vla, bool index32,
83 : bufferizationOptions(bufferizationOptions),
84 sparsificationOptions(sparsificationOptions),
85 createSparseDeallocs(createSparseDeallocs),
86 enableRuntimeLibrary(enableRuntimeLibrary),
87 enableBufferInitialization(enableBufferInitialization) {
88
89 vectorLength = vl;
90 enableVLAVectorization = vla;
91 enableSIMDIndex32 = index32;
92 enableGPULibgen = gpu;
93 sparseEmitStrategy = emitStrategy;
94 parallelization = parallelizationStrategy;
95 }
96
97
98
99
102 bufferizationOptions;
103
107 return true;
108 if (auto funcOp = dyn_castfunc::FuncOp(op)) {
109 FunctionType funcType = funcOp.getFunctionType();
112 return true;
113 }
114 return false;
115 });
116
118
120 updatedOptions,
121 bufferizationState)))
122 return failure();
123
125 return success();
126 }
127
129
131
132
134
135
136 {
140 bufferization::createEmptyTensorToAllocTensorPass());
141 if (failed(runPipeline(pm, getOperation())))
142 return signalPassFailure();
143 }
144
145
146
147
148
149
150
151
152
153
154
156
158 getOperation(), bufferizationOptions, bufferizationState)))
159 return signalPassFailure();
160
161
162
163
165 return;
166
167
168
169
170 {
172 if (enableGPULibgen)
180 }
181
184 true));
189 if (vectorLength > 0) {
191 vectorLength, enableVLAVectorization, enableSIMDIndex32));
192 }
193 if (enableRuntimeLibrary) {
195 } else {
197 enableBufferInitialization));
199 }
200 if (failed(runPipeline(pm, getOperation())))
201 return signalPassFailure();
202 }
203
204
206 signalPassFailure();
207 }
208
209 private:
212 bool createSparseDeallocs;
213 bool enableRuntimeLibrary;
214 bool enableBufferInitialization;
215 };
216
217 }
218 }
219
224 options.bufferizeFunctionBoundaries = true;
225 options.setFunctionBoundaryTypeConversion(LayoutMapOption::IdentityLayoutMap);
229 cast(value.getType()), memorySpace);
230 };
231 if (analysisOnly) {
232 options.testAnalysisOnly = true;
233 options.printConflicts = true;
234 }
235
236
237
238
239
240 options.allowUnknownOps = true;
242 }
243
246 return std::make_unique<
249 sparseOptions,
250 false,
251 false,
252 false);
253 }
254
258 bool createSparseDeallocs, bool enableRuntimeLibrary,
259 bool enableBufferInitialization, unsigned vectorLength,
260 bool enableVLAVectorization, bool enableSIMDIndex32, bool enableGPULibgen,
263 return std::make_unique<
265 bufferizationOptions, sparsificationOptions, createSparseDeallocs,
266 enableRuntimeLibrary, enableBufferInitialization, vectorLength,
267 enableVLAVectorization, enableSIMDIndex32, enableGPULibgen, emitStrategy,
268 parallelizationStrategy);
269 }
static llvm::ManagedStatic< PassManagerOptions > options
Attributes are known-constant values of operations.
This class represents a pass manager that runs passes on either a specific operation type,...
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
Operation is the basic unit of execution within MLIR.
operand_range getOperands()
Returns an iterator on the underlying Value's.
result_range getResults()
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
BufferizationState provides information about the state of the IR during the bufferization process.
void denyOperation()
Deny the given ops.
A pass that lowers tensor ops to memref ops, regardless of whether they are dense or sparse.
SparsificationAndBufferizationPass(const bufferization::OneShotBufferizationOptions &bufferizationOptions, const SparsificationOptions &sparsificationOptions, bool createSparseDeallocs, bool enableRuntimeLibrary, bool enableBufferInitialization, unsigned vl, bool vla, bool index32, bool gpu, SparseEmitStrategy emitStrategy, SparseParallelizationStrategy parallelizationStrategy)
void runOnOperation() override
LogicalResult runDenseBufferization()
Bufferize all dense ops.
SparsificationAndBufferizationPass(const bufferization::OneShotBufferizationOptions &bufferizationOptions, const SparsificationOptions &sparsificationOptions, bool createSparseDeallocs, bool enableRuntimeLibrary, bool enableBufferInitialization)
BaseMemRefType getMemRefTypeWithStaticIdentityLayout(TensorType tensorType, Attribute memorySpace=nullptr)
Return a MemRef type with a static identity layout (i.e., no layout map).
LogicalResult insertTensorCopies(Operation *op, const OneShotBufferizationOptions &options, const BufferizationState &bufferizationState, BufferizationStatistics *statistics=nullptr)
Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
llvm::LogicalResult bufferizeModuleOp(ModuleOp moduleOp, const OneShotBufferizationOptions &options, BufferizationState &state, BufferizationStatistics *statistics=nullptr)
Bufferize op and its nested ops that implement BufferizableOpInterface.
void removeBufferizationAttributesInModule(ModuleOp moduleOp)
Remove bufferization attributes on every FuncOp arguments in the ModuleOp.
static bool containsSparseTensor(TypeRange types)
Return true if one of the given types is a sparse tensor type.
SparseTensorEncodingAttr getSparseTensorEncoding(Type type)
Convenience method to get a sparse encoding attribute from a type.
Include the generated interface declarations.
std::unique_ptr< Pass > createSparseVectorizationPass()
std::unique_ptr< Pass > createLowerSparseOpsToForeachPass()
std::unique_ptr< Pass > createSparseTensorCodegenPass()
std::unique_ptr< Pass > createSparseGPUCodegenPass()
std::unique_ptr< Pass > createSparseSpaceCollapsePass()
std::unique_ptr< Pass > createLoopInvariantCodeMotionPass()
Creates a loop invariant code motion pass that hoists loop invariant instructions out of the loop.
bufferization::OneShotBufferizationOptions getBufferizationOptionsForSparsification(bool analysisOnly)
std::unique_ptr< Pass > createSparseReinterpretMapPass()
std::unique_ptr< Pass > createSparseTensorConversionPass()
std::unique_ptr< Pass > createSparseBufferRewritePass()
std::unique_ptr< Pass > createSparsificationAndBufferizationPass()
SparseParallelizationStrategy
Defines a parallelization strategy.
SparseEmitStrategy
Defines a scope for reinterpret map pass.
std::unique_ptr< Pass > createPreSparsificationRewritePass()
std::unique_ptr< Pass > createLowerForeachToSCFPass()
std::unique_ptr< Pass > createLowerSparseIterationToSCFPass()
std::unique_ptr< Pass > createStageSparseOperationsPass()
std::unique_ptr< Pass > createSparsificationPass()
Options for the Sparsification pass.
SparseEmitStrategy sparseEmitStrategy
SparseParallelizationStrategy parallelizationStrategy
Options for BufferizableOpInterface-based bufferization.
bool testAnalysisOnly
If set to true, does not modify the IR apart from adding attributes (for checking the results of the ...
OpFilter opFilter
A filter that specifies which ops should be bufferized and which ops should be ignored.
Options for analysis-enabled bufferization.