Skip to content

Commit 7356404

Browse files
stellaraccidentStella Laurenzo
authored and
Stella Laurenzo
committed
[mlir] Delete most of the ops from the quant dialect.
* https://discourse.llvm.org/t/rfc-removing-the-quant-dialect/3643/8 * Removes most ops. Leaves casts given final comment (can remove more in a followup). * There are a few uses in Tosa keeping some of the utilities alive. In a followup, I will probably elect to just move simplified versions of them into Tosa itself vs having this quasi-library dependency. Differential Revision: https://reviews.llvm.org/D120204
1 parent 4bb192b commit 7356404

24 files changed

+0
-1766
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
add_mlir_dialect(QuantOps quant)
22
add_mlir_doc(QuantOps QuantDialect Dialects/ -gen-dialect-doc)
3-
4-
set(LLVM_TARGET_DEFINITIONS Passes.td)
5-
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Quant)
6-
add_public_tablegen_target(MLIRQuantPassIncGen)
7-
8-
add_mlir_doc(Passes QuantPasses ./ -gen-pass-doc)

mlir/include/mlir/Dialect/Quant/Passes.h

-50
This file was deleted.

mlir/include/mlir/Dialect/Quant/Passes.td

-27
This file was deleted.

mlir/include/mlir/Dialect/Quant/QuantOps.td

-166
Original file line numberDiff line numberDiff line change
@@ -84,170 +84,4 @@ def quant_StorageCastOp : quant_Op<"scast", [NoSideEffect]> {
8484
let hasFolder = 1;
8585
}
8686

87-
// A QuantizeRegion (region) represents a quantization unit which wraps
88-
// high-precision ops with quantization specifications for all the inputs
89-
// and outputs. Some quantization specifications can be undetermined and
90-
// derived from other ports by the target specification of the kernel.
91-
def quant_QuantizeRegionOp : quant_Op<"region", [
92-
NoSideEffect,
93-
IsolatedFromAbove,
94-
SingleBlockImplicitTerminator<"ReturnOp">]> {
95-
let summary = [{
96-
The `region` operation wraps high-precision ops as a logical low-precision
97-
quantized kernel.
98-
}];
99-
100-
let arguments = (ins Variadic<AnyType>:$inputs,
101-
TypeArrayAttr:$input_specs,
102-
TypeArrayAttr:$output_specs,
103-
StrAttr:$logical_kernel);
104-
let results = (outs Variadic<AnyType>:$outputs);
105-
let regions = (region SizedRegion<1>:$body);
106-
let hasVerifier = 1;
107-
}
108-
109-
def quant_ReturnOp : quant_Op<"return", [Terminator]> {
110-
let summary = [{
111-
The `return` operation terminates a quantize region and returns values.
112-
}];
113-
114-
let arguments = (ins Variadic<AnyTensor>:$results);
115-
}
116-
117-
//===----------------------------------------------------------------------===//
118-
// Training integration and instrumentation ops
119-
//===----------------------------------------------------------------------===//
120-
121-
def quant_ConstFakeQuant : quant_Op<"const_fake_quant",
122-
[SameOperandsAndResultType, NoSideEffect]> {
123-
let summary = [{
124-
Simulates the effect of uniform quantization with const range.
125-
}];
126-
127-
let description = [{
128-
Given a const min, max, num_bits and narrow_range attribute, applies the
129-
same uniform quantization simulation as is done by the TensorFlow
130-
fake_quant_with_min_max_args op. See the fakeQuantAttrsToType() utility
131-
method and the quant-convert-simulated-quantization pass for further details.
132-
}];
133-
134-
let arguments = (ins
135-
F32Tensor:$inputs,
136-
F32Attr:$min,
137-
F32Attr:$max,
138-
// The bitwidth of the quantization; between 2 and 16, inclusive.
139-
I64Attr:$num_bits,
140-
// Quantization range starts from 0 or 1; starts from 1 if true.
141-
DefaultValuedAttr<BoolAttr, "false">:$narrow_range,
142-
// The sign of the quantization.
143-
DefaultValuedAttr<BoolAttr, "false">:$is_signed
144-
);
145-
146-
let results = (outs
147-
F32Tensor:$outputs
148-
);
149-
}
150-
151-
def quant_ConstFakeQuantPerAxis : quant_Op<"const_fake_quant_per_axis",
152-
[SameOperandsAndResultType, NoSideEffect]> {
153-
let summary = [{
154-
Simulates the effect of per axis uniform quantization with const range.
155-
}];
156-
157-
let description = [{
158-
Given a const min, max, num_bits and narrow_range attribute, applies the
159-
same per axis uniform quantization simulation as is done by the TensorFlow
160-
fake_quant_with_min_max_vars_per_channel op. See the fakeQuantAttrsToType()
161-
utility method and the quant-convert-simulated-quantization pass for further
162-
details.
163-
}];
164-
165-
let arguments = (ins
166-
F32Tensor:$inputs,
167-
F32ArrayAttr:$min,
168-
F32ArrayAttr:$max,
169-
// The quantized dimension of the inputs tensor.
170-
I64Attr:$axis,
171-
// The bitwidth of the quantization; between 2 and 16, inclusive.
172-
I64Attr:$num_bits,
173-
// Quantization range starts from 0 or 1; starts from 1 if true.
174-
DefaultValuedAttr<BoolAttr, "false">:$narrow_range,
175-
// The sign of the quantization.
176-
DefaultValuedAttr<BoolAttr, "false">:$is_signed
177-
);
178-
179-
let results = (outs
180-
F32Tensor:$outputs
181-
);
182-
}
183-
184-
def quant_StatisticsRefOp : quant_Op<"stats_ref", [SameOperandsAndResultType]> {
185-
let summary = "Indicates that statistics are resolved by reference.";
186-
187-
let description = [{
188-
This op acts as an identity that, when encountered at runtime, should result
189-
in statistics being collected about about the value of its operand/result.
190-
Such statistics will be stored with the provided key, allowing this node
191-
to later be converted to a 'stats' op if statistics with that key have been
192-
encountered.
193-
}];
194-
195-
let arguments = (ins
196-
quant_RealValueType:$arg,
197-
StrAttr:$statsKey
198-
);
199-
let results = (outs quant_RealValueType);
200-
}
201-
202-
def quant_StatisticsOp : quant_Op<"stats", [SameOperandsAndResultType]> {
203-
let summary = "Identity op which associates statistics with the value.";
204-
205-
let description = [{
206-
Associates statistics about the runtime ranges of values observed for
207-
evaluations of this node.
208-
209-
Statistics about the entire type are reported in the 'layerStats' attribute
210-
and those for each axis, in the (optional) `axisStats` attribute. The
211-
interpretation of each is determined by the last dimension of its shape.
212-
Currently, only dim=2 is supported, which is interpreted as [min, max].
213-
214-
`layerStats` must be a rank 1 tensor: [2]
215-
`axisStats` must be a rank 2 tensor: [N, 2], where N=the slice size
216-
splitted by the `axis` dimension. For example:
217-
218-
```
219-
<?x?x3x2>, axis=3 => N=2
220-
<?x?x3x2>, axis=2 => N=6
221-
```
222-
}];
223-
224-
let arguments = (ins
225-
quant_RealValueType:$arg,
226-
ElementsAttr:$layerStats,
227-
OptionalAttr<ElementsAttr>:$axisStats,
228-
OptionalAttr<I64Attr>:$axis);
229-
let results = (outs quant_RealValueType);
230-
let hasVerifier = 1;
231-
}
232-
233-
def quant_CoupledRefOp : quant_Op<"coupled_ref", [SameOperandsAndResultType]> {
234-
let summary = [{
235-
Indicates that one point of the computation is coupled to another.
236-
}];
237-
238-
let description = [{
239-
Ordinarily, relationships between ops for the purposes of determining
240-
compatible quantized types is explicit based on the use-def chain. However,
241-
in some situations, a use may be separated from its def by arbitrary
242-
external connections. In such a case, during analysis, all coupled_ref
243-
nodes in a module which share a coupledKey will be considered to be
244-
directly connected as via an identity op for the purpose of type inference.
245-
}];
246-
247-
let arguments = (ins
248-
quant_RealValueType:$arg,
249-
StrAttr:$coupledKey);
250-
let results = (outs quant_RealValueType);
251-
}
252-
25387
#endif // DIALECT_QUANT_QUANT_OPS_

mlir/include/mlir/Dialect/Quant/QuantizeUtils.h

-61
This file was deleted.

mlir/include/mlir/InitAllPasses.h

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "mlir/Dialect/Linalg/Passes.h"
2626
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
2727
#include "mlir/Dialect/NVGPU/Passes.h"
28-
#include "mlir/Dialect/Quant/Passes.h"
2928
#include "mlir/Dialect/SCF/Transforms/Passes.h"
3029
#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
3130
#include "mlir/Dialect/Shape/Transforms/Passes.h"
@@ -69,7 +68,6 @@ inline void registerAllPasses() {
6968
registerSparseTensorPasses();
7069
LLVM::registerLLVMPasses();
7170
memref::registerMemRefPasses();
72-
quant::registerQuantPasses();
7371
registerSCFPasses();
7472
registerShapePasses();
7573
spirv::registerSPIRVPasses();

mlir/lib/Dialect/Quant/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
add_subdirectory(IR)
2-
add_subdirectory(Transforms)
32
add_subdirectory(Utils)

0 commit comments

Comments
 (0)