MLIR 24.0.0git
SparseTensorPipelines.cpp
Go to the documentation of this file.
1//===- SparseTensorPipelines.cpp - Pipelines for sparse tensor code -------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
33
34//===----------------------------------------------------------------------===//
35// Pipeline implementation.
36//===----------------------------------------------------------------------===//
37
40 // Rewrite named linalg ops into generic ops and apply fusion.
43
44 // Sparsification and bufferization mini-pipeline.
47 options.testBufferizationAnalysisOnly),
48 options.sparsificationOptions(), options.createSparseDeallocs,
49 options.enableRuntimeLibrary, options.enableBufferInitialization,
50 options.vectorLength,
51 /*enableVLAVectorization=*/options.armSVE,
52 /*enableSIMDIndex32=*/options.force32BitVectorIndices,
53 options.enableGPULibgen,
54 options.sparsificationOptions().sparseEmitStrategy,
55 options.sparsificationOptions().parallelizationStrategy));
56
57 // Bail-early for test setup.
58 if (options.testBufferizationAnalysisOnly)
59 return;
60
61 // Storage specifier lowering and bufferization wrap-up.
63 pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
64
65 // GPU code generation.
66 const bool gpuCodegen = options.gpuTriple.hasValue();
67 if (gpuCodegen) {
69 options.enableRuntimeLibrary));
70 pm.addNestedPass<gpu::GPUModuleOp>(createStripDebugInfoPass());
71 pm.addNestedPass<gpu::GPUModuleOp>(createSCFToControlFlowPass());
72 pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps());
73 }
74
75 // Progressively lower to LLVM. Note that the convert-vector-to-llvm
76 // pass is repeated on purpose.
77 // TODO(springerm): Add sparse support to the BufferDeallocation pass and add
78 // it to this pipeline.
84 pm.addNestedPass<func::FuncOp>(createSCFToControlFlowPass());
85 pm.addPass(
86 createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
92 pm.addPass(
93 createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
94
95 // Finalize GPU code generation.
96 if (gpuCodegen) {
97 GpuNVVMAttachTargetOptions nvvmTargetOptions;
98 nvvmTargetOptions.triple = options.gpuTriple;
99 nvvmTargetOptions.chip = options.gpuChip;
100 nvvmTargetOptions.features = options.gpuFeatures;
101 pm.addPass(createGpuNVVMAttachTarget(nvvmTargetOptions));
103 GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
104 gpuModuleToBinaryPassOptions.compilationTarget = options.gpuFormat;
105 pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
106 }
107
108 // Convert to LLVM.
110
111 // Ensure all casts are realized.
113}
114
115//===----------------------------------------------------------------------===//
116// Pipeline registration.
117//===----------------------------------------------------------------------===//
118
121 "sparsifier",
122 "The standard pipeline for taking sparsity-agnostic IR using the"
123 " sparse-tensor type, and lowering it to LLVM IR with concrete"
124 " representations and algorithms for sparse tensors.",
126}
static llvm::ManagedStatic< PassManagerOptions > options
This class represents a pass manager that runs passes on either a specific operation type,...
Definition PassManager.h:46
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition Pass.cpp:393
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
std::unique_ptr<::mlir::Pass > createArithExpandOpsPass()
std::unique_ptr<::mlir::Pass > createExpandReallocPass()
std::unique_ptr<::mlir::Pass > createExpandStridedMetadataPass()
void buildSparsifier(OpPassManager &pm, const SparsifierOptions &options)
Adds the "sparsifier" pipeline to the OpPassManager.
void registerSparseTensorPipelines()
Registers all pipelines for the sparse_tensor dialect.
std::unique_ptr<::mlir::Pass > createConvertToLLVMPass()
std::unique_ptr<::mlir::Pass > createSCFToControlFlowPass()
std::unique_ptr<::mlir::Pass > createConvertMathToLLVMPass()
std::unique_ptr< Pass > createSparseGPUCodegenPass()
bufferization::OneShotBufferizationOptions getBufferizationOptionsForSparsification(bool analysisOnly)
std::unique_ptr<::mlir::Pass > createReconcileUnrealizedCastsPass()
std::unique_ptr<::mlir::Pass > createConvertVectorToLLVMPass()
std::unique_ptr< Pass > createSparsificationAndBufferizationPass()
std::unique_ptr<::mlir::Pass > createCanonicalizerPass()
std::unique_ptr<::mlir::Pass > createConvertComplexToLibm()
std::unique_ptr<::mlir::Pass > createGpuNVVMAttachTarget()
std::unique_ptr<::mlir::Pass > createStripDebugInfoPass()
std::unique_ptr<::mlir::Pass > createLinalgElementwiseOpFusionPass()
std::unique_ptr<::mlir::Pass > createConvertGpuOpsToNVVMOps()
std::unique_ptr<::mlir::Pass > createLowerAffinePass()
std::unique_ptr<::mlir::Pass > createConvertMathToLibmPass()
std::unique_ptr<::mlir::Pass > createLinalgGeneralizeNamedOpsPass()
std::unique_ptr< Pass > createStorageSpecifierToLLVMPass()
std::unique_ptr<::mlir::Pass > createGpuToLLVMConversionPass()
std::unique_ptr<::mlir::Pass > createGpuModuleToBinaryPass()
std::unique_ptr< Pass > createConvertVectorToSCFPass(const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Create a pass to convert a subset of vector ops to SCF.
std::unique_ptr<::mlir::Pass > createConvertLinalgToLoopsPass()
Definition Loops.cpp:245
std::unique_ptr<::mlir::Pass > createConvertComplexToStandardPass()
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...
Options for the "sparsifier" pipeline.
Definition Passes.h:30