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
32
33//===----------------------------------------------------------------------===//
34// Pipeline implementation.
35//===----------------------------------------------------------------------===//
36
39 // Rewrite named linalg ops into generic ops and apply fusion.
40 pm.addNestedPass<func::FuncOp>(createLinalgGeneralizeNamedOpsPass());
41 pm.addNestedPass<func::FuncOp>(createLinalgElementwiseOpFusionPass());
42
43 // Sparsification and bufferization mini-pipeline.
46 options.testBufferizationAnalysisOnly),
47 options.sparsificationOptions(), options.createSparseDeallocs,
48 options.enableRuntimeLibrary, options.enableBufferInitialization,
49 options.vectorLength,
50 /*enableVLAVectorization=*/options.armSVE,
51 /*enableSIMDIndex32=*/options.force32BitVectorIndices,
52 options.enableGPULibgen,
53 options.sparsificationOptions().sparseEmitStrategy,
54 options.sparsificationOptions().parallelizationStrategy));
55
56 // Bail-early for test setup.
57 if (options.testBufferizationAnalysisOnly)
58 return;
59
60 // Storage specifier lowering and bufferization wrap-up.
62 pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
63
64 // GPU code generation.
65 const bool gpuCodegen = options.gpuTriple.hasValue();
66 if (gpuCodegen) {
68 options.enableRuntimeLibrary));
69 pm.addNestedPass<gpu::GPUModuleOp>(createStripDebugInfoPass());
70 pm.addNestedPass<gpu::GPUModuleOp>(createSCFToControlFlowPass());
71 pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps());
72 }
73
74 // Progressively lower to LLVM. Note that the convert-vector-to-llvm
75 // pass is repeated on purpose.
76 // TODO(springerm): Add sparse support to the BufferDeallocation pass and add
77 // it to this pipeline.
78 pm.addNestedPass<func::FuncOp>(createConvertLinalgToLoopsPass());
80 pm.addNestedPass<func::FuncOp>(memref::createExpandReallocPass());
81 pm.addNestedPass<func::FuncOp>(createSCFToControlFlowPass());
82 pm.addPass(memref::createExpandStridedMetadataPass());
83 pm.addPass(createLowerAffinePass());
84 pm.addPass(
85 createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
86 pm.addNestedPass<func::FuncOp>(createConvertComplexToStandardPass());
87 pm.addNestedPass<func::FuncOp>(arith::createArithExpandOpsPass());
88 pm.addNestedPass<func::FuncOp>(createConvertMathToLLVMPass());
89 pm.addPass(createConvertMathToLibmPass());
90 pm.addPass(createConvertComplexToLibm());
91 pm.addPass(
92 createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
93
94 // Finalize GPU code generation.
95 if (gpuCodegen) {
96 GpuNVVMAttachTargetOptions nvvmTargetOptions;
97 nvvmTargetOptions.triple = options.gpuTriple;
98 nvvmTargetOptions.chip = options.gpuChip;
99 nvvmTargetOptions.features = options.gpuFeatures;
100 pm.addPass(createGpuNVVMAttachTarget(nvvmTargetOptions));
101 pm.addPass(createGpuToLLVMConversionPass());
102 GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
103 gpuModuleToBinaryPassOptions.compilationTarget = options.gpuFormat;
104 pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
105 }
106
107 // Convert to LLVM.
108 pm.addPass(createConvertToLLVMPass());
109
110 // Ensure all casts are realized.
111 pm.addPass(createReconcileUnrealizedCastsPass());
112}
113
114//===----------------------------------------------------------------------===//
115// Pipeline registration.
116//===----------------------------------------------------------------------===//
117
120 "sparsifier",
121 "The standard pipeline for taking sparsity-agnostic IR using the"
122 " sparse-tensor type, and lowering it to LLVM IR with concrete"
123 " representations and algorithms for sparse tensors.",
125}
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:392
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
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< Pass > createCanonicalizerPass(const GreedyRewriteConfig &config, ArrayRef< std::string > disabledPatterns={}, ArrayRef< std::string > enabledPatterns={})
Creates an instance of the Canonicalizer pass with the specified config.
std::unique_ptr< Pass > createSparseGPUCodegenPass()
bufferization::OneShotBufferizationOptions getBufferizationOptionsForSparsification(bool analysisOnly)
std::unique_ptr< Pass > createSparsificationAndBufferizationPass()
std::unique_ptr< Pass > createStorageSpecifierToLLVMPass()
std::unique_ptr< Pass > createConvertVectorToSCFPass(const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Create a pass to convert a subset of vector ops to SCF.
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...
Options for the "sparsifier" pipeline.
Definition Passes.h:30