-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathoptions.h
More file actions
357 lines (304 loc) · 14.2 KB
/
Copy pathoptions.h
File metadata and controls
357 lines (304 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// clang-format off
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-present NVIDIA CORPORATION & AFFILIATES.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*/
// clang-format on
#pragma once
#include <exceptions.h>
#include <visibility.h>
#include <algorithm>
#include <cstdint>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
namespace nvfuser {
//! Types of debug print-outs
//!
//! These can be set through the `NVFUSER_DUMP` environment variable
//!
enum class DebugDumpOption : std::uint8_t {
CutlassCompile, //!< Dump compile commands and compile times for
//!< CutlassExecutor
FunctionTrace, //!< Dump the function trace of selected internal function. The
//!< function of interest needs to be instrumented with
//!< DEBUG_PRINT_SCOPE and optionally RECORD_AND_RETURN before
//!< it can be traced. If RECORD_AND_RETURN is not used,
//!< function tracing will still work, but it will not be able
//!< to print the return value and the line of the return
//!< statement. If you are interested in tracing a specific
//!< function while developing a PR, you are recommended to
//!< keep the instrumentation code in your PR and so later
//!< people can use it after committed to the main branch.
FusionIrOriginal, //!< Dump the original fusion IR built by the Python API
FusionIrConcretized, //!< Dump the Fusion IR after concretization
FusionIrPreseg, //!< Dump the Fusion IR after pre-segmenter optimization and
//!< before segmentation
FusionIrPresched, //!< Dump the segmented Fusion IR before it is scheduled
// TODO(wujingyue): name the following FusionIrSched
FusionIr, //!< Dump the Fusion IR before lowering. This is the Fusion IR fed
//!< to `KernelExecutor::compile`.
FusionIrGraph, //!< Dump a GraphViz graph of the Fusion IR
FusionIrMath, //!< Dump just the compute (math) part of the above `FusionIr`
//!< for conciseness
KernelIr, //!< Dump the compiler Kernel IR
ComputeAtMap, //!< Dump the computeAt map
CudaKernel, //!< Dump the generated CUDA C++ kernel code
CudaFull, //!< Dump the complete CUDA C++ code
CudaToFile, //!< Dump CUDA Strings to File
LaunchParam, //!< Dump the Launch parameters of kernel
DynamicSharedMemory, //!< Dump the dynamic shared memory allocation
FusionSegments, //!< Dump Segmented Fusion Graph
FusionSegmenterLog, //!< Dump Detailed Segmenter Logging
FusionArgs, //!< Print the runtime fusion arguments
GlobalZeroedMemory, //!< Print the log for zeroed global memory allocator
HostIr, //!< Dump the Host IR program
HostIrJit, //!< Dump the LLVM IR lowered from Host IR
Inlining, //! Verbose information about tensor inlining
KernelArgs, //!< Print the runtime kernel arguments when launching kernels
FusionSegmentsDrawing, //!< Dump Segmented Fusion Graph
PrintPtxasLog, //!< Print the ptxas verbose log including register usage
BufferReuseInfo, //!< Dump the analysis details of local/shared buffer re-use
SchedulerDebug, //! Dump scheduler heuristic parameters
SchedulerVerbose, //! Dump detailed scheduler logging
ParallelDimensions, //!< Dump known parallel dimensions
PerfDebugVerbose, //! When running kernels, print verbose information
//! associated with what's running
PreSegmenterLogging,
HostIrLowering, //! Dump the Host IR after each lowering pass
PythonDefinition, //! Python Frontend Fusion Definition.
TransformPropagator, //! When running TransformPropagator, print propagation
//! path and replay result
Cubin, //! Dump compiled CUBIN
Sass, //! Dump disassembled SASS
SassToFile, //!< Dump disassembled SASS to File
Ptx, //! Dump compiled PTX
BankConflictInfo, //! Dump bank confliction info
SyncMap, //! RAW dependency info
LowerVerbose, //! Print all passes' transform in GpuLower::lower
ExprSimplification, //! Print all passes' transform in simplifyExpr
ExprSort, //! Print merging decisions on expression sorting
ExprSortVerbose, //! Print verbose debug info on expression sorting
Occupancy, //! Dump occupancy
IndexType, //! Print the index type of the launched kernel
PredicateElimination, //! Print the predicate elimination information
IndexingVerbose, //! Print verbose debug info on indexing
Communication, //! Print multi-GPU communications posted
CompileParams, //! Print NVRTC compile parameters
EndOfOption //! Placeholder for counting the number of elements
};
//! Types of features to enable
//!
//! These can be set through the `NVFUSER_ENABLE` environment variable
//!
enum class EnableOption : std::uint8_t {
CutlassScheduler, //! Enable the CUTLASS scheduler and executor
FuseMatmul, //! Enable automatic fusion of matmul and linear ops
FuseMultipleMatmuls, //! Allow fusing more than one matmul in a single kernel
IdModelExtraValidation, //! Enable extra error checking when building IdModel
IoToLowerPrecision, //! Enable castInputOutputToLowerPrecision. #1889 explains
//! why we disabled it by default.
KernelDb, //! Enable Kernel Database
KernelDebug, //! Enable debug mode in nvrtc
KernelLineInfo, //! Embed line info to compiled kernel, and dump the full CUDA
//! C++ code
KernelProfile, //! Enable intra-kernel performance profiling
MemoryPromotion, //! Enable promotion of memory types for non-pointwise ops
ReuseZeroedMemory, //! Re-use zeroed memory used for grid synchronization
StaticFusionCount, //! Enable using single static count in kernel name
WaitDebugger, // Used for debugging multi-GPU. The rank given in the argument
// will wait for `gdb attach` at the start.
WarnRegisterSpill, //! Enable warnings of register spill
TmaPointwise, //! Enable TMA pointwise kernel
TmaInnerPersistent, //! Enable TMA inner persistent kernel
TmaReduction, //! Enable TMA reduction kernel
TmaTranspose, //! Enable TMA transpose kernel
WarpSpecializedNormalization, //! Enable warp specialized persistent kernel
HostIrLowering, //! Enable FusionKernelRuntime lowering to host IR
HostIrJit, //! Enable Host IR JIT compilation with LLVM
InsertReshardingAfter, //! Insert resharding set after the expression
FastMath, //! Enable fast math optimizations (--use_fast_math)
P2pProtocol, //! Prescribe P2P protocol: put|get
MulticastProtocol, //! Prescribe multicast protocol:
//! memcpy|multimem|batch_memcpy
ParallelSerde, //! Enable deserializing FusionExecutorCache in parallel
EndOfOption //! Placeholder for counting the number of elements
};
//! Types of features to disable
//!
//! These can be set through the `NVFUSER_DISABLE` environment variable
//!
enum class DisableOption : std::uint8_t {
CompileToSass, //! Disable direct compilation to sass so the ptx can be
//! examined
ContigIndexing, //! Disable contiguous indexing
ExprSimplify, //! Disable expression simplifier
Fallback, //! Disable fallback
Fma, //! Disable FMA instructions
GreedyScheduler, //! Disable the greedy scheduler
GroupedGridWelfordOuterOpt, //! Disable use of outer-optimized
//! grouped grid welford kernel
IndexHoist, //! Disable index hoisting
MagicZero, //! Disable nvfuser_zero
MatmulExprEval, //! Disable ATen evaluation for the entire fusion containing
//! matmul
NvrtcCaching, // Disable compilation caching by nvrtc
Nvtx, //! Disable NVTX instrumentation
ParallelCompile, //! Disable compiling Fusion segments in parallel
PredicateElimination, //! Disable predicate elimination
PythonInlineDefinitions, //! Disable printing of inline definitions
KernelReuse, //! Disable re-using cached FusionKernelRuntimes with different
//! input shapes
VarNameRemapping, //! Disable variable name remapping
WelfordVectorization, //! Disable vectorizaton of Welford ops
ReuseMismatchedTypeRegisters, //! Disable explicitly re-using registers unless
//! types match
Multidevice, //! Disable creation of multidevice communicator. Mainly for
//! debugging. This option quickly disables the multidevice
//! module even when Fuser is built with multidevice support. We
//! need this in particular to investigate possible conflicts
//! between nvFuser communicator and the framework also setting
//! up `c10d::ProcessGroup`
ResizeScheduler, //! Disable the resize scheduler
InferContiguity, //! Disable contiguity inference
EndOfOption //! Placeholder for counting the number of elements
};
//! Options to set for Fusion Profiling. Whenever the profiler
//! is enabled, its output can be queried from the FusionProfile object.
//! All options enable the profiler.
//!
//! These can be set through the `NVFUSER_PROF` environment variable
//!
enum class ProfilerOption : std::uint8_t {
Enable, //! Enables the profiler.
EnableNocupti, //! Enables the profiler, but disables CUPTI specific
//! profiling inorder to measure true host time without
//! overhead.
Print, //! Enables the profiler and prints the output to the console.
PrintNocupti, //! Enables the profiler, disables CUPTI specific
//! profiling inorder to measure true host time without
//! overhead, and prints the output to the console.
PrintVerbose, //! Enables the profiler and prints a complete set of columns
//! to the console. WARNING: The output is will wrap on small
//! screens!
EndOfOption //! Placeholder for counting the number of elements
};
//! The base template class for the options such as EnableOption
template <typename OptionEnum>
class Options {
public:
Options() : options_(getOptionsFromEnv()) {}
Options(const Options& other)
: options_([&other]() {
std::lock_guard<std::mutex> lock_other(other.mutex_);
return other.options_;
}()) {}
Options& operator=(const Options& other) {
std::lock_guard<std::mutex> lock_other(other.mutex_);
std::lock_guard<std::mutex> lock(mutex_);
options_ = other.options_;
return *this;
}
bool has(OptionEnum option) const {
std::lock_guard<std::mutex> lock(mutex_);
return options_.count(option);
}
bool hasAny() const {
std::lock_guard<std::mutex> lock(mutex_);
return !options_.empty();
}
const std::vector<std::string>& getArgs(OptionEnum option) const {
NVF_ERROR(has(option), "Option not set");
std::lock_guard<std::mutex> lock(mutex_);
return options_.at(option);
}
bool hasArg(OptionEnum option, const std::string& arg) const {
if (!has(option)) {
return false;
}
const auto& args = getArgs(option);
return std::find(args.begin(), args.end(), arg) != args.end();
}
void set(OptionEnum option_type, std::vector<std::string> option = {}) {
std::lock_guard<std::mutex> lock(mutex_);
options_[option_type] = option;
}
void unset(OptionEnum option_type) {
std::lock_guard<std::mutex> lock(mutex_);
options_.erase(option_type);
}
NVF_API static std::unordered_map<OptionEnum, std::vector<std::string>>
getOptionsFromEnv();
protected:
std::unordered_map<OptionEnum, std::vector<std::string>> options_;
mutable std::mutex mutex_;
};
//! Utility class to temporarily overrride the Enable options,
//! including those provided by the environment variable
template <typename OptionEnum>
class NVF_API OptionsGuard {
public:
OptionsGuard() : prev_options_(getCurOptions()) {}
~OptionsGuard() {
getCurOptions() = prev_options_;
}
NVF_API static Options<OptionEnum>& getCurOptions();
private:
Options<OptionEnum> prev_options_;
};
// DebugDump options
template <>
NVF_API std::unordered_map<DebugDumpOption, std::vector<std::string>> Options<
DebugDumpOption>::getOptionsFromEnv();
using DebugDumpOptions = Options<DebugDumpOption>;
template <>
NVF_API Options<DebugDumpOption>& OptionsGuard<
DebugDumpOption>::getCurOptions();
using DebugDumpOptionsGuard = OptionsGuard<DebugDumpOption>;
NVF_API bool isDebugDumpEnabled(DebugDumpOption option);
const std::vector<std::string>& getDebugDumpArguments(DebugDumpOption option);
bool hasDebugDumpArgument(DebugDumpOption option, const std::string& arg);
// Enable options
template <>
NVF_API std::unordered_map<EnableOption, std::vector<std::string>> Options<
EnableOption>::getOptionsFromEnv();
using EnableOptions = Options<EnableOption>;
NVF_API std::optional<EnableOption> stringToEnableOption(
const std::string& enable_option);
bool isOptionEnabled(EnableOption option);
const std::vector<std::string>& getEnableOptionArguments(EnableOption option);
bool hasEnableOptionArgument(EnableOption option, const std::string& arg);
template <>
NVF_API Options<EnableOption>& OptionsGuard<EnableOption>::getCurOptions();
using EnableOptionsGuard = OptionsGuard<EnableOption>;
// Disable options
template <>
NVF_API std::unordered_map<DisableOption, std::vector<std::string>> Options<
DisableOption>::getOptionsFromEnv();
using DisableOptions = Options<DisableOption>;
NVF_API std::optional<DisableOption> stringToDisableOption(
const std::string& disable_option);
NVF_API bool isOptionDisabled(DisableOption option);
const std::vector<std::string>& getDisableOptionArguments(DisableOption option);
bool hasDisableOptionArgument(DisableOption option, const std::string& arg);
template <>
NVF_API Options<DisableOption>& OptionsGuard<DisableOption>::getCurOptions();
using DisableOptionsGuard = OptionsGuard<DisableOption>;
// Profiler Options
template <>
NVF_API std::unordered_map<ProfilerOption, std::vector<std::string>> Options<
ProfilerOption>::getOptionsFromEnv();
using ProfilerOptions = Options<ProfilerOption>;
// Specific queries for the Profiler Options
bool isProfilerEnabled();
bool isProfilerEnabledWithCupti();
bool isProfilerPrintingEnabled();
bool isProfilerPrintingVerbose();
const std::vector<std::string>& getProfilerOptionArguments(
ProfilerOption option);
template <>
NVF_API Options<ProfilerOption>& OptionsGuard<ProfilerOption>::getCurOptions();
using ProfilerOptionsGuard = OptionsGuard<ProfilerOption>;
} // namespace nvfuser