My Project
Metadata.h
Go to the documentation of this file.
1 //===- Metadata.h - Top level types and metadata ----------------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 file contains top level types needed to construct constraint graphs,
10 // including context/allocator support and concrete metadata structs for
11 // different quantization schemes (which must be attached to anchor nodes).
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef MLIR_QUANTIZER_SUPPORT_METADATA_H
16 #define MLIR_QUANTIZER_SUPPORT_METADATA_H
17 
18 #include <limits>
19 
21 #include "mlir/IR/MLIRContext.h"
23 #include "llvm/ADT/SmallBitVector.h"
24 
25 namespace mlir {
26 namespace quantizer {
27 
29 public:
30  SolverContext(MLIRContext &mlirContext) : mlirContext(mlirContext) {}
31 
32  MLIRContext &getMlirContext() { return mlirContext; }
33 
34  llvm::BumpPtrAllocator &getAllocator() { return allocator; }
35 
36  // Optional path to write a debug DOT file for the CAG.
37  StringRef getDebugCAGDotPath() const { return debugCAGDotPath; }
38  void setDebugCAGDotPath(StringRef p) { debugCAGDotPath = p; }
39 
40 private:
41  MLIRContext &mlirContext;
42  llvm::BumpPtrAllocator allocator;
43  std::string debugCAGDotPath;
44 };
45 
48  // Note that scheme encodes more than just the target type: it also encodes
49  // additional constraints.
50  enum class Scheme {
51  // Uses aggregate range information for all nodes in the cluster to
52  // solve for uniform scale and zero point.
53  UniformPerLayer,
54  // Uses aggregate per-axis range information for all nodes in the cluster
55  // to solve for per-axis uniform scale and zero point.
56  UniformPerAxisFixedPoint,
57  // Uses the |explicitScaleZeroPoint| to set the scale (and zero point = 0)
58  // for the uniform type. This typically overrides all other constraints
59  // and is used for wide accumulator types (i.e. i32 bias vectors).
60  UniformExplicitFixedPointScale,
61  };
62  unsigned ordinal;
65 };
66 
70  static constexpr int SalienceDefault = 0;
71 
74  static constexpr int SalienceForced = 100;
75 
78  static constexpr int SalienceRequired = 200;
79 
83 
85  llvm::SmallBitVector disabledCandidateTypes;
86 
89 
93 
95  void printSummary(raw_ostream &os) const;
96 };
97 
98 } // end namespace quantizer
99 } // end namespace mlir
100 
101 #endif // MLIR_QUANTIZER_SUPPORT_METADATA_H
Definition: InferTypeOpInterface.cpp:20
SolverContext(MLIRContext &mlirContext)
Definition: Metadata.h:30
ExpandingMinMaxFact requiredRange
Definition: Metadata.h:82
Scheme scheme
Definition: Metadata.h:64
unsigned ordinal
Definition: Metadata.h:62
MLIRContext & getMlirContext()
Definition: Metadata.h:32
StringRef getDebugCAGDotPath() const
Definition: Metadata.h:37
DiscreteScaleZeroPointFact explicitScaleZeroPoint
Definition: Metadata.h:92
Definition: Metadata.h:67
Definition: QuantTypes.h:209
llvm::SmallBitVector disabledCandidateTypes
Bool vector of scheme ordinals that are disabled.
Definition: Metadata.h:85
Definition: Metadata.h:28
llvm::BumpPtrAllocator & getAllocator()
Definition: Metadata.h:34
void setDebugCAGDotPath(StringRef p)
Definition: Metadata.h:38
quant::AnyQuantizedType quantizedType
Definition: Metadata.h:63
Definition: QuantTypes.h:60
quant::QuantizedType selectedType
If set, then a solution has converged for the given per-layer scheme.
Definition: Metadata.h:88
Definition: MLIRContext.h:34
Candidate for a quantized type conversion.
Definition: Metadata.h:47