1/**
2 * Copyright (c) Glow Contributors. See CONTRIBUTORS file.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef GLOW_FLAGS_FLAGS_H
17#define GLOW_FLAGS_FLAGS_H
18
19#include "llvm/ADT/StringRef.h"
20#include <gflags/gflags.h>
21#include <map>
22
23namespace glow {
24namespace flags {
25
26// Generic Constants
27extern int32_t NumDevices;
28extern bool ScanDevices;
29extern bool SaturateHost;
30extern bool EnableQuantParamChanges;
31extern size_t MaxActiveRequests;
32extern size_t MaxActiveRequestsPerInstance;
33extern size_t MaxQueueSize;
34extern size_t ExecutorThreads;
35extern bool DelayAndRecordConstantModification;
36extern bool UseTrackedDummyQuantParams;
37extern bool EnablePartialTensors;
38extern bool UseCustomOpsForExport;
39extern std::string BackendSpecificOpts;
40extern bool EnableLoadBalancedPartitioning;
41extern bool SkipProvisioning;
42extern bool DisableLayoutVerifying;
43extern bool DisableFreeCompilationResource;
44extern bool SinkTanhBelowConcat;
45
46// FP16 Constants
47extern bool ConvertToFP16;
48extern bool SkipBiasFp32tofp16Convert;
49extern bool ConvertPlaceholdersToFP16;
50extern bool ConvertConstantsToFP16;
51extern bool ConvertFusedScaleOffsetToFP16;
52extern bool ClipToFP16;
53extern bool SkipInputsOnClipToFP16;
54extern bool ForceSLSToFP16Accum;
55extern bool ClipZeroScaleFP16;
56extern bool ClipQuantRangeToFP16;
57
58// FP32 constants
59extern bool ConvertFusedScaleOffsetToFP32;
60
61// Debug Constants
62extern int32_t NumDebugTracesPerDump;
63extern bool DumpDebugTraces;
64extern bool LogPartition;
65extern bool DumpPartition;
66extern bool DumpCompilationLog;
67extern bool DumpBackendSpecificIRJSON;
68extern bool DumpGraph;
69extern std::string DumpGraphPath;
70extern bool DumpInitialLoadedGraph;
71
72// Sparse NN Partitioning Scheme Constants
73extern int32_t SparseNNPartitioningSchemeNumCards;
74extern int64_t SparseNNPartitioningSchemeSLSTableKBytesPerCard;
75extern int32_t SparseNNPartitioningSchemeNumCoresSLS;
76extern int32_t SparseNNPartitioningSchemeNumCoresOther;
77extern bool UseSparseNNPartitioningScheme;
78extern bool SparseNNPartitioningAddSLSConcats;
79extern bool SparseNNPartitioningBalancePerfModel;
80extern bool SparseNNPartitioningPairLNWithSLS;
81extern bool SparseNNPartitioningPairTileWithSLS;
82extern std::string SparseNNPartitioningPairSLSWith;
83extern int32_t SparseNNPartitioningConcatSplitSize;
84extern bool SparseNNParallelizeReshapeOnBatchDim;
85
86// Dag Optimizer Constants
87extern bool UseDAGOptimizer;
88extern int32_t DAGOptimizerNumParallelChunks;
89extern std::string DAGOptimizerPlacementTaggingAlgorithm;
90extern std::string DAGOptimizerParallelizationTaggingAlgorithm;
91
92/// Helper for processing opts in \p optsStr into \p opts. \returns if there is
93/// any error encountered when processing \p optsStr.
94bool processBackendSpecificOpts(std::map<std::string, std::string> &optsMap,
95 llvm::StringRef optsStr);
96} // namespace flags
97} // namespace glow
98
99namespace glow {
100namespace nnpi {
101namespace flags {
102extern int32_t ModelParallelSplitAlignment;
103extern int32_t NumParallelChunks;
104extern bool LowerAllBatchMatMul;
105extern bool AcceptUnarySLS;
106extern bool SpecializeAllOneSLS;
107extern bool DisableTransforms;
108extern bool EnableCustomIAKernels;
109extern bool EnableCustomDSPKernels;
110extern bool DumpCompilerData;
111extern bool UsePerPartitionIcetConfig;
112extern std::string InjectedIAOpKernelPath;
113extern bool DumpCustomKernelFiles;
114} // namespace flags
115} // namespace nnpi
116} // namespace glow
117
118namespace glow {
119namespace interpreter {
120namespace flags {
121extern bool LowerBatchMatMul;
122extern bool LowerLayerNormalization;
123} // namespace flags
124} // namespace interpreter
125} // namespace glow
126
127namespace glow {
128namespace torch_glow {
129namespace flags {
130extern bool ImaginaryFlag; // Placeholder Flag
131}
132} // namespace torch_glow
133} // namespace glow
134
135namespace glow {
136namespace onnxifi {
137namespace flags {
138extern std::string BackendName;
139extern bool SaveModel;
140extern bool SaveIO;
141extern bool SaveDAG;
142extern bool SaveDAGWithConstants;
143extern bool SaveDAGInZipMode;
144} // namespace flags
145} // namespace onnxifi
146} // namespace glow
147
148namespace glow {
149namespace runtime {
150namespace flags {
151extern unsigned CPUMemory;
152
153extern unsigned HabanaMemory;
154
155extern unsigned NNPIMemory;
156extern unsigned NNPITimeoutMs;
157
158extern std::string AvailableDevices;
159extern unsigned InterpreterMemory;
160extern bool EnableP2P;
161extern bool EnableDRT;
162extern unsigned DeviceInitTimeoutMs;
163extern uint64_t BigTableThresholdBytes;
164extern unsigned SanitizeInputsPercent;
165extern unsigned NumCompilationThreads;
166} // namespace flags
167} // namespace runtime
168} // namespace glow
169
170/// Flags which may have their default values overridden:
171DECLARE_bool(glow_global_fp16);
172DECLARE_bool(glow_skip_bias_fp32tofp16_convert);
173DECLARE_bool(glow_clip_fp16);
174DECLARE_bool(glow_global_fused_scale_offset_fp16);
175DECLARE_bool(glow_global_fused_scale_offset_fp32);
176DECLARE_int32(glow_snn_partitioning_kbytes_per_card);
177DECLARE_int32(glow_snn_partitioning_num_cores_sls);
178DECLARE_int32(glow_snn_partitioning_num_cores_other);
179
180/// Signifiers for flags which we may load from e.g. a proto.
181constexpr char clipQuantRangeToFP16Key[] = "GlowLoader_clipQuantRangeToFP16";
182
183#endif /* GLOW_FLAGS_FLAGS_H */
184