MLIR 23.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
21
22//===----------------------------------------------------------------------===//
23// Pipeline implementation.
24//===----------------------------------------------------------------------===//
25
28 // Rewrite named linalg ops into generic ops and apply fusion.
29 pm.addNestedPass<func::FuncOp>(createLinalgGeneralizeNamedOpsPass());
30 pm.addNestedPass<func::FuncOp>(createLinalgElementwiseOpFusionPass());
31
32 // Sparsification and bufferization mini-pipeline.
35 options.testBufferizationAnalysisOnly),
36 options.sparsificationOptions(), options.createSparseDeallocs,
37 options.enableRuntimeLibrary, options.enableBufferInitialization,
38 options.vectorLength,
39 /*enableVLAVectorization=*/options.armSVE,
40 /*enableSIMDIndex32=*/options.force32BitVectorIndices,
41 options.enableGPULibgen,
42 options.sparsificationOptions().sparseEmitStrategy,
43 options.sparsificationOptions().parallelizationStrategy));
44
45 // Bail-early for test setup.
46 if (options.testBufferizationAnalysisOnly)
47 return;
48
49 // Storage specifier lowering and bufferization wrap-up.
51 pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
52
53 // GPU code generation.
54 const bool gpuCodegen = options.gpuTriple.hasValue();
55 if (gpuCodegen) {
57 options.enableRuntimeLibrary));
58 pm.addNestedPass<gpu::GPUModuleOp>(createStripDebugInfoPass());
59 pm.addNestedPass<gpu::GPUModuleOp>(createSCFToControlFlowPass());
60 pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps());
61 }
62
63 // Progressively lower to LLVM. Note that the convert-vector-to-llvm
64 // pass is repeated on purpose.
65 // TODO(springerm): Add sparse support to the BufferDeallocation pass and add
66 // it to this pipeline.
67 pm.addNestedPass<func::FuncOp>(createConvertLinalgToLoopsPass());
69 pm.addNestedPass<func::FuncOp>(memref::createExpandReallocPass());
70 pm.addNestedPass<func::FuncOp>(createSCFToControlFlowPass());
71 pm.addPass(memref::createExpandStridedMetadataPass());
72 pm.addPass(createLowerAffinePass());
73 pm.addPass(
74 createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
75 pm.addNestedPass<func::FuncOp>(createConvertComplexToStandardPass());
76 pm.addNestedPass<func::FuncOp>(arith::createArithExpandOpsPass());
77 pm.addNestedPass<func::FuncOp>(createConvertMathToLLVMPass());
78 pm.addPass(createConvertMathToLibmPass());
79 pm.addPass(createConvertComplexToLibm());
80 pm.addPass(
81 createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
82
83 // Finalize GPU code generation.
84 if (gpuCodegen) {
85 GpuNVVMAttachTargetOptions nvvmTargetOptions;
86 nvvmTargetOptions.triple = options.gpuTriple;
87 nvvmTargetOptions.chip = options.gpuChip;
88 nvvmTargetOptions.features = options.gpuFeatures;
89 pm.addPass(createGpuNVVMAttachTarget(nvvmTargetOptions));
90 pm.addPass(createGpuToLLVMConversionPass());
91 GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
92 gpuModuleToBinaryPassOptions.compilationTarget = options.gpuFormat;
93 pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
94 }
95
96 // Convert to LLVM.
97 pm.addPass(createConvertToLLVMPass());
98
99 // Ensure all casts are realized.
100 pm.addPass(createReconcileUnrealizedCastsPass());
101}
102
103//===----------------------------------------------------------------------===//
104// Pipeline registration.
105//===----------------------------------------------------------------------===//
106
109 "sparsifier",
110 "The standard pipeline for taking sparsity-agnostic IR using the"
111 " sparse-tensor type, and lowering it to LLVM IR with concrete"
112 " representations and algorithms for sparse tensors.",
114}
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