MLIR  18.0.0git
Passes.h
Go to the documentation of this file.
1 //===- Passes.h - Sparse tensor pipeline entry points -----------*- C++ -*-===//
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 //
9 // This header file defines prototypes of all sparse tensor pipelines.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_SPARSETENSOR_PIPELINES_PASSES_H_
14 #define MLIR_DIALECT_SPARSETENSOR_PIPELINES_PASSES_H_
15 
18 #include "mlir/Pass/PassOptions.h"
19 
20 using namespace mlir::detail;
21 using namespace llvm::cl;
22 
23 namespace mlir {
24 namespace sparse_tensor {
25 
26 /// Options for the "sparse-compiler" pipeline. So far this only contains
27 /// a subset of the options that can be set for the underlying passes,
28 /// because it must be manually kept in sync with the tablegen files
29 /// for those passes.
31  : public PassPipelineOptions<SparseCompilerOptions> {
32  // These options must be kept in sync with `SparsificationBase`.
33  // TODO(57514): These options are duplicated in Passes.td.
35  *this, "parallelization-strategy",
36  ::llvm::cl::desc("Set the parallelization strategy"),
38  llvm::cl::values(
40  "Turn off sparse parallelization."),
42  "dense-outer-loop",
43  "Enable dense outer loop sparse parallelization."),
45  "any-storage-outer-loop",
46  "Enable sparse parallelization regardless of storage for "
47  "the outer loop."),
49  "dense-any-loop",
50  "Enable dense parallelization for any loop."),
51  clEnumValN(
53  "any-storage-any-loop",
54  "Enable sparse parallelization for any storage and loop."))};
56  *this, "gpu-data-transfer-strategy",
57  ::llvm::cl::desc(
58  "Set the data transfer strategy between the host and the GPUs"),
60  llvm::cl::values(
61  clEnumValN(mlir::GPUDataTransferStrategy::kRegularDMA, "regular-dma",
62  "Default option: malloc on host without additional "
63  "options or care and then use DMA to copy the data"),
64  clEnumValN(mlir::GPUDataTransferStrategy::kPinnedDMA, "pinned-dma",
65  "Based on the default option, pin the host memory to "
66  "accelerate the data transfer"),
67  clEnumValN(mlir::GPUDataTransferStrategy::kZeroCopy, "zero-copy",
68  "Use zero-copy to perform the data transfer from the host "
69  "to the GPU"))};
70 
71  PassOptions::Option<bool> enableIndexReduction{
72  *this, "enable-index-reduction",
73  desc("Enable dependent index reduction based algorithm to handle "
74  "non-trivial index expressions on sparse inputs (experimental "
75  "features)"),
76  init(false)};
77 
78  PassOptions::Option<bool> enableRuntimeLibrary{
79  *this, "enable-runtime-library",
80  desc("Enable runtime library for manipulating sparse tensors"),
81  init(true)};
82 
83  PassOptions::Option<bool> testBufferizationAnalysisOnly{
84  *this, "test-bufferization-analysis-only",
85  desc("Run only the inplacability analysis"), init(false)};
86 
87  PassOptions::Option<bool> enableBufferInitialization{
88  *this, "enable-buffer-initialization",
89  desc("Enable zero-initialization of memory buffers"), init(false)};
90 
91  PassOptions::Option<bool> createSparseDeallocs{
92  *this, "create-sparse-deallocs",
93  desc("Specify if the temporary buffers created by the sparse "
94  "compiler should be deallocated. For compatibility with core "
95  "bufferization passes. "
96  "This option is only used when enable-runtime-library=false."),
97  init(true)};
98 
100  *this, "vl", desc("Set the vector length (0 disables vectorization)"),
101  init(0)};
102 
103  // These options must be kept in sync with `SparseTensorConversionBase`.
105  *this, "s2s-strategy",
106  desc("Set the strategy for sparse-to-sparse conversion"), init(0)};
107 
108  // These options must be kept in sync with the `ConvertVectorToLLVM`
109  // (defined in include/mlir/Dialect/SparseTensor/Pipelines/Passes.h).
110  PassOptions::Option<bool> reassociateFPReductions{
111  *this, "reassociate-fp-reductions",
112  desc("Allows llvm to reassociate floating-point reductions for speed"),
113  init(false)};
114  PassOptions::Option<bool> force32BitVectorIndices{
115  *this, "enable-index-optimizations",
116  desc("Allows compiler to assume indices fit in 32-bit if that yields "
117  "faster code"),
118  init(true)};
120  *this, "enable-amx",
121  desc("Enables the use of AMX dialect while lowering the vector dialect"),
122  init(false)};
124  *this, "enable-arm-neon",
125  desc("Enables the use of ArmNeon dialect while lowering the vector "
126  "dialect"),
127  init(false)};
129  *this, "enable-arm-sve",
130  desc("Enables the use of ArmSVE dialect while lowering the vector "
131  "dialect"),
132  init(false)};
134  *this, "enable-x86vector",
135  desc("Enables the use of X86Vector dialect while lowering the vector "
136  "dialect"),
137  init(false)};
138 
139  /// These options are used to enable GPU code generation.
140  PassOptions::Option<std::string> gpuTriple{*this, "gpu-triple",
141  desc("GPU target triple")};
142  PassOptions::Option<std::string> gpuChip{*this, "gpu-chip",
143  desc("GPU target architecture")};
144  PassOptions::Option<std::string> gpuFeatures{*this, "gpu-features",
145  desc("GPU target features")};
146  /// For NVIDIA GPUs there are 3 compilation format options:
147  /// 1. `isa`: the compiler generates PTX and the driver JITs the PTX.
148  /// 2. `bin`: generates a CUBIN object for `chip=gpuChip`.
149  /// 3. `fatbin`: generates a fat binary with a CUBIN object for `gpuChip` and
150  /// also embeds the PTX in the fat binary.
151  /// Notes:
152  /// Option 1 adds a significant runtime performance hit, however, tests are
153  /// more likely to pass with this option.
154  /// Option 2 is better for execution time as there is no JIT; however, the
155  /// program will fail if there's an architecture mismatch between `gpuChip`
156  /// and the GPU running the program.
157  /// Option 3 is the best compromise between options 1 and 2 as it can JIT in
158  /// case of an architecture mismatch between `gpuChip` and the running
159  /// architecture. However, it's only possible to JIT to a higher CC than
160  /// `gpuChip`.
162  *this, "gpu-format", desc("GPU compilation format"), init("fatbin")};
163 
164  /// This option is used to enable GPU library generation.
165  PassOptions::Option<bool> enableGPULibgen{
166  *this, "enable-gpu-libgen",
167  desc("Enables GPU acceleration by means of direct library calls (like "
168  "cuSPARSE)")};
169 
170  /// Projects out the options for `createSparsificationPass`.
172  return SparsificationOptions(parallelization, gpuDataTransfer,
173  enableIndexReduction, enableGPULibgen,
174  enableRuntimeLibrary);
175  }
176 
177  /// Projects out the options for `createSparseTensorConversionPass`.
180  sparseToSparseConversionStrategy(sparseToSparse));
181  }
182 
183  /// Projects out the options for `createConvertVectorToLLVMPass`.
184  ConvertVectorToLLVMPassOptions lowerVectorToLLVMOptions() const {
185  ConvertVectorToLLVMPassOptions opts{};
186  opts.reassociateFPReductions = reassociateFPReductions;
187  opts.force32BitVectorIndices = force32BitVectorIndices;
188  opts.armNeon = armNeon;
189  opts.armSVE = armSVE;
190  opts.amx = amx;
191  opts.x86Vector = x86Vector;
192  return opts;
193  }
194 };
195 
196 //===----------------------------------------------------------------------===//
197 // Building and Registering.
198 //===----------------------------------------------------------------------===//
199 
200 /// Adds the "sparse-compiler" pipeline to the `OpPassManager`. This
201 /// is the standard pipeline for taking sparsity-agnostic IR using
202 /// the sparse-tensor type and lowering it to LLVM IR with concrete
203 /// representations and algorithms for sparse tensors.
205  const SparseCompilerOptions &options);
206 
207 /// Registers all pipelines for the `sparse_tensor` dialect. At present,
208 /// this includes only "sparse-compiler".
210 
211 } // namespace sparse_tensor
212 } // namespace mlir
213 
214 #endif // MLIR_DIALECT_SPARSETENSOR_PIPELINES_PASSES_H_
static llvm::ManagedStatic< PassManagerOptions > options
This class represents a pass manager that runs passes on either a specific operation type,...
Definition: PassManager.h:48
Subclasses of PassPipelineOptions provide a set of options that can be used to initialize a pass pipe...
Definition: PassOptions.h:329
Detect if any of the given parameter types has a sub-element handler.
void registerSparseTensorPipelines()
Registers all pipelines for the sparse_tensor dialect.
void buildSparseCompiler(OpPassManager &pm, const SparseCompilerOptions &options)
Adds the "sparse-compiler" pipeline to the OpPassManager.
This header declares functions that assist transformations in the MemRef dialect.
SparseToSparseConversionStrategy sparseToSparseConversionStrategy(int32_t flag)
Converts command-line sparse2sparse flag to the strategy enum.
SparseTensorConversion options.
Definition: Passes.h:126
Options for the Sparsification pass.
Definition: Passes.h:63
Options for the "sparse-compiler" pipeline.
Definition: Passes.h:31
ConvertVectorToLLVMPassOptions lowerVectorToLLVMOptions() const
Projects out the options for createConvertVectorToLLVMPass.
Definition: Passes.h:184
SparseTensorConversionOptions sparseTensorConversionOptions() const
Projects out the options for createSparseTensorConversionPass.
Definition: Passes.h:178
SparsificationOptions sparsificationOptions() const
Projects out the options for createSparsificationPass.
Definition: Passes.h:171