MLIR 24.0.0git
Passes.h
Go to the documentation of this file.
1//===- Passes.h - GPU pipeline entry points--------------------------------===//
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#ifndef MLIR_DIALECT_GPU_PIPELINES_PASSES_H_
10#define MLIR_DIALECT_GPU_PIPELINES_PASSES_H_
11
13
14namespace mlir {
15namespace gpu {
16
17/// Options for the gpu to nvvm pipeline.
19 : public PassPipelineOptions<GPUToNVVMPipelineOptions> {
20 PassOptions::Option<int64_t> indexBitWidth{
21 *this, "index-bitwidth",
22 llvm::cl::desc("Bitwidth of the index type for the host (warning this "
23 "should be 64 until the GPU layering is fixed)"),
24 llvm::cl::init(64)};
25 PassOptions::Option<std::string> cubinTriple{
26 *this, "cubin-triple",
27 llvm::cl::desc("Triple to use to serialize to cubin."),
28 llvm::cl::init("nvptx64-nvidia-cuda")};
29 PassOptions::Option<std::string> cubinChip{
30 *this, "cubin-chip", llvm::cl::desc("Chip to use to serialize to cubin."),
31 llvm::cl::init("sm_75")};
32 PassOptions::Option<std::string> cubinFeatures{
33 *this, "cubin-features",
34 llvm::cl::desc("Features to use to serialize to cubin."),
35 llvm::cl::init("")};
36 PassOptions::Option<std::string> cubinFormat{
37 *this, "cubin-format",
38 llvm::cl::desc("Compilation format to use to serialize to cubin."),
39 llvm::cl::init("fatbin")};
40 PassOptions::Option<std::string> cmdOptions{
41 *this, "ptxas-cmd-options",
42 llvm::cl::desc(
43 "Command line options to pass to the downstream compiler."),
44 llvm::cl::init("")};
45 PassOptions::Option<int> optLevel{
46 *this, "opt-level",
47 llvm::cl::desc("Optimization level for NVVM compilation"),
48 llvm::cl::init(2)};
49 PassOptions::Option<bool> kernelUseBarePtrCallConv{
50 *this, "kernel-bare-ptr-calling-convention",
51 llvm::cl::desc(
52 "Whether to use the bareptr calling convention on the kernel "
53 "(warning this should be false until the GPU layering is fixed)"),
54 llvm::cl::init(false)};
55 PassOptions::Option<bool> hostUseBarePtrCallConv{
56 *this, "host-bare-ptr-calling-convention",
57 llvm::cl::desc(
58 "Whether to use the bareptr calling convention on the host (warning "
59 "this should be false until the GPU layering is fixed)"),
60 llvm::cl::init(false)};
61 PassOptions::Option<bool> allowPatternRollback{
62 *this, "allow-pattern-rollback",
63 llvm::cl::desc("Allow pattern rollback during dialect conversion"),
64 llvm::cl::init(true)};
65 PassOptions::Option<unsigned> defaultCtorPriority{
66 *this, "default-ctor-priority",
67 llvm::cl::desc("Priority of the global constructor and destructor that "
68 "load and unload the GPU binary, for GPU modules that do "
69 "not specify one."),
70 llvm::cl::init(123)};
71};
72
73/// Options for the gpu to rocdl pipeline.
75 : public PassPipelineOptions<GPUToROCDLPipelineOptions> {
76 PassOptions::Option<int64_t> indexBitWidth{
77 *this, "index-bitwidth",
78 llvm::cl::desc("Bitwidth of the index type for the host (warning this "
79 "should be 64 until the GPU layering is fixed)"),
80 llvm::cl::init(64)};
81 PassOptions::Option<std::string> arch{
82 *this, "arch",
83 llvm::cl::desc(
84 "AMDGPU target architecture, as in Clang, with optional target-ID "
85 "modifiers (e.g. gfx942, gfx90a:xnack+, amdgpu9.42-amd-amdhsa, "
86 "amdgpu9.0a-amd-amdhsa--gfx90a:xnack-). Supersedes the separate "
87 "triple option this pipeline used to take. Required: AMDGCN "
88 "binaries are not forward-compatible across chip families.")};
89 PassOptions::Option<std::string> chip{
90 *this, "chip", llvm::cl::desc("Deprecated alias for 'arch'."),
91 llvm::cl::init("")};
92 PassOptions::Option<std::string> binaryFormat{
93 *this, "binary-format",
94 llvm::cl::desc("Final GPU binary emission format (e.g. fatbin, binary, "
95 "isa, llvm, offloading)."),
96 llvm::cl::init("fatbin")};
97 PassOptions::Option<std::string> abiVersion{
98 *this, "abi",
99 llvm::cl::desc("AMDHSA ABI version (e.g. \"500\", \"600\")."),
100 llvm::cl::init("600")};
101 PassOptions::Option<unsigned> waveSize{
102 *this, "wavesize",
103 llvm::cl::desc("Wavefront size (32 or 64) for targets that run at "
104 "either, or 0 to use the architecture's default."),
105 llvm::cl::init(0)};
106 PassOptions::Option<int> optLevel{
107 *this, "opt-level",
108 llvm::cl::desc("Optimization level for ROCDL/AMDGPU compilation."),
109 llvm::cl::init(2)};
110 PassOptions::Option<std::string> cmdOptions{
111 *this, "rocdl-cmd-options",
112 llvm::cl::desc(
113 "Command line options to pass to the downstream AMDGPU compiler."),
114 llvm::cl::init("")};
115 PassOptions::Option<bool> kernelUseBarePtrCallConv{
116 *this, "kernel-bare-ptr-calling-convention",
117 llvm::cl::desc("Use bareptr calling convention for device kernels."),
118 llvm::cl::init(false)};
119 PassOptions::Option<bool> hostUseBarePtrCallConv{
120 *this, "host-bare-ptr-calling-convention",
121 llvm::cl::desc("Use bareptr calling convention for the host."),
122 llvm::cl::init(false)};
123};
124
125// Options for the gpu to xevm pipeline.
127 : public PassPipelineOptions<GPUToXeVMPipelineOptions> {
128 PassOptions::Option<std::string> xegpuOpLevel{
129 *this, "xegpu-op-level",
130 llvm::cl::desc("Granularity of XeGPU operations to target: workgroup | "
131 "subgroup | lane"),
132 llvm::cl::init("workgroup")};
133 PassOptions::Option<bool> enableVectorToXeGPU{
134 *this, "enable-vector-to-xegpu",
135 llvm::cl::desc("Run convert-vector-to-xegpu so the pipeline can accept "
136 "vector dialect (one level above XeGPU) as entry IR"),
137 llvm::cl::init(false)};
138 // General lowering controls.
139 PassOptions::Option<bool> use64bitIndex{
140 *this, "use-64bit-index",
141 llvm::cl::desc("Bitwidth of the index type (host & device)"),
142 llvm::cl::init(true)};
143 PassOptions::Option<bool> kernelBarePtrCallConv{
144 *this, "kernel-bare-ptr-calling-convention",
145 llvm::cl::desc("Use bare pointer calling convention for device kernels"),
146 llvm::cl::init(false)};
147 PassOptions::Option<bool> hostBarePtrCallConv{
148 *this, "host-bare-ptr-calling-convention",
149 llvm::cl::desc("Use bare pointer calling convention for host launches"),
150 llvm::cl::init(false)};
151 PassOptions::Option<std::string> binaryFormat{
152 *this, "binary-format",
153 llvm::cl::desc("Final GPU binary emission format (e.g. fatbin). Valid "
154 "values are the set of values for the format argument of "
155 "-gpu-module-to-binary pass plus a special value: skip, "
156 "which skips invoking -gpu-module-to-binary pass."),
157 llvm::cl::init("fatbin")};
158 // Options mirroring xevm-attach-target (GpuXeVMAttachTarget).
159 PassOptions::Option<std::string> xevmModuleMatcher{
160 *this, "xevm-module-matcher",
161 llvm::cl::desc("Regex to match gpu.module names for XeVM target attach"),
162 llvm::cl::init("")};
163 PassOptions::Option<std::string> zebinTriple{
164 *this, "zebin-triple", llvm::cl::desc("Target triple for XeVM codegen"),
165 llvm::cl::init("spirv64-unknown-unknown")};
166 PassOptions::Option<std::string> zebinChip{
167 *this, "zebin-chip", llvm::cl::desc("Target chip (e.g. pvc, bmg)"),
168 llvm::cl::init("bmg")};
169 PassOptions::Option<unsigned> optLevel{
170 *this, "opt-level",
171 llvm::cl::desc("Optimization level for attached target/codegen"),
172 llvm::cl::init(2)};
173 PassOptions::Option<std::string> cmdOptions{
174 *this, "igc-cmd-options",
175 llvm::cl::desc("Additional downstream compiler command line options"),
176 llvm::cl::init("")};
177 // Options for MathExtendToSupportedTypes and ArithEmulateUnsupportedFloats,
178 // run on the host/device module before conversion to LLVM to legalize math
179 // and arith ops operating on floating-point types that the XeVM target
180 // cannot handle natively (e.g. bf16).
181 PassOptions::ListOption<std::string> unsupportedSourceTypes{
182 *this, "unsupported-source-types",
183 llvm::cl::desc("Floating-point source types without arithmetic/math "
184 "support on the target (e.g. bf16)"),
185 llvm::cl::list_init<std::string>(ArrayRef<std::string>{"bf16"})};
186 PassOptions::Option<std::string> supportedTargetTypes{
187 *this, "supported-target-types",
188 llvm::cl::desc(
189 "Floating-point target type used to emulate the unsupported "
190 "source types via extf/truncf pairs"),
191 llvm::cl::init("f32")};
192 // Additional types (beyond the implicit f32/f64) that math ops are allowed
193 // to run on directly. Maps to the `extra-types` option of
194 // math-extend-to-supported-types. Leave empty to extend every non-f32/f64
195 // math op to `supported-target-types`.
196 PassOptions::ListOption<std::string> mathExtendExtraTypes{
197 *this, "math-extend-extra-types",
198 llvm::cl::desc(
199 "Extra floating-point types with math op support on the target, "
200 "in addition to f32 and f64 (maps to math-extend-to-supported-"
201 "types `extra-types`)"),
202 llvm::cl::list_init<std::string>(ArrayRef<std::string>{"f16"})};
203};
204
205//===----------------------------------------------------------------------===//
206// Building and Registering.
207//===----------------------------------------------------------------------===//
208
209/// Adds the GPU to NVVM pipeline to the given pass manager. Transforms main
210/// dialects into NVVM targets. Begins with GPU code regions, then handles host
211/// code.
213 const GPUToNVVMPipelineOptions &options);
214
215/// Adds the GPU to ROCDL pipeline to the given pass manager. Transforms main
216/// dialects (arith, memref, scf, vector, gpu) into ROCDL/AMDGPU. Begins with
217/// GPU code regions, then handles host code.
219 const GPUToROCDLPipelineOptions &options);
220
221/// Adds the GPU to XeVM pipeline to the given pass manager. Transforms main
222/// dialects into XeVM targets. Begins with GPU code regions, then handles host
223/// code.
225 const GPUToXeVMPipelineOptions &options);
226
227/// Register all pipelines for the `gpu` dialect.
231
232} // namespace gpu
233} // namespace mlir
234
235#endif
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 registerGPUToNVVMPipeline()
Register all pipelines for the gpu dialect.
void registerGPUToXeVMPipeline()
void buildLowerToXeVMPassPipeline(OpPassManager &pm, const GPUToXeVMPipelineOptions &options)
Adds the GPU to XeVM pipeline to the given pass manager.
void registerGPUToROCDLPipeline()
void buildLowerToROCDLPassPipeline(OpPassManager &pm, const GPUToROCDLPipelineOptions &options)
Adds the GPU to ROCDL pipeline to the given pass manager.
void buildLowerToNVVMPassPipeline(OpPassManager &pm, const GPUToNVVMPipelineOptions &options)
Adds the GPU to NVVM pipeline to the given pass manager.
Include the generated interface declarations.
Options for the gpu to nvvm pipeline.
Definition Passes.h:19
PassOptions::Option< std::string > cubinChip
Definition Passes.h:29
PassOptions::Option< int > optLevel
Definition Passes.h:45
PassOptions::Option< bool > allowPatternRollback
Definition Passes.h:61
PassOptions::Option< bool > hostUseBarePtrCallConv
Definition Passes.h:55
PassOptions::Option< std::string > cmdOptions
Definition Passes.h:40
PassOptions::Option< std::string > cubinFeatures
Definition Passes.h:32
PassOptions::Option< std::string > cubinFormat
Definition Passes.h:36
PassOptions::Option< int64_t > indexBitWidth
Definition Passes.h:20
PassOptions::Option< std::string > cubinTriple
Definition Passes.h:25
PassOptions::Option< bool > kernelUseBarePtrCallConv
Definition Passes.h:49
PassOptions::Option< unsigned > defaultCtorPriority
Definition Passes.h:65
Options for the gpu to rocdl pipeline.
Definition Passes.h:75
PassOptions::Option< std::string > chip
Definition Passes.h:89
PassOptions::Option< unsigned > waveSize
Definition Passes.h:101
PassOptions::Option< std::string > cmdOptions
Definition Passes.h:110
PassOptions::Option< int64_t > indexBitWidth
Definition Passes.h:76
PassOptions::Option< std::string > abiVersion
Definition Passes.h:97
PassOptions::Option< bool > hostUseBarePtrCallConv
Definition Passes.h:119
PassOptions::Option< bool > kernelUseBarePtrCallConv
Definition Passes.h:115
PassOptions::Option< std::string > arch
Definition Passes.h:81
PassOptions::Option< std::string > binaryFormat
Definition Passes.h:92
PassOptions::Option< int > optLevel
Definition Passes.h:106
PassOptions::Option< bool > hostBarePtrCallConv
Definition Passes.h:147
PassOptions::ListOption< std::string > unsupportedSourceTypes
Definition Passes.h:181
PassOptions::Option< unsigned > optLevel
Definition Passes.h:169
PassOptions::ListOption< std::string > mathExtendExtraTypes
Definition Passes.h:196
PassOptions::Option< std::string > xegpuOpLevel
Definition Passes.h:128
PassOptions::Option< std::string > xevmModuleMatcher
Definition Passes.h:159
PassOptions::Option< std::string > zebinTriple
Definition Passes.h:163
PassOptions::Option< bool > kernelBarePtrCallConv
Definition Passes.h:143
PassOptions::Option< std::string > binaryFormat
Definition Passes.h:151
PassOptions::Option< std::string > supportedTargetTypes
Definition Passes.h:186
PassOptions::Option< bool > enableVectorToXeGPU
Definition Passes.h:133
PassOptions::Option< std::string > cmdOptions
Definition Passes.h:173
PassOptions::Option< bool > use64bitIndex
Definition Passes.h:139
PassOptions::Option< std::string > zebinChip
Definition Passes.h:166