diff options
author | Feng Liu <fengliuai@google.com> | 2019-07-18 11:25:53 -0700 |
---|---|---|
committer | Mehdi Amini <joker.eph@gmail.com> | 2019-07-19 11:39:54 -0700 |
commit | 701266c47abab7180d36ae174f19d76a113a77a4 (patch) | |
tree | 697c3673664e24484f80ba7a58fdc74c68c1531a /mlir/lib/Dialect | |
parent | 90b5a381ce1ae04c4d67071c1098c946848cb342 (diff) | |
download | bcm5719-llvm-701266c47abab7180d36ae174f19d76a113a77a4.tar.gz bcm5719-llvm-701266c47abab7180d36ae174f19d76a113a77a4.zip |
Add an "is_signed" attribute to the quant_ConstFakeQuant op
Some TensorFlow simulated quantize ops such as QuantizeAndDequantizeV2Op have
attribute for the sign of the quantization, so quant_ConstFakeQuant should be
able to represent it with the new attribute is added.
The method for converting these attributes to an QuantizedType is updated to
handle this new argument.
PiperOrigin-RevId: 258810290
Diffstat (limited to 'mlir/lib/Dialect')
-rw-r--r-- | mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp | 2 | ||||
-rw-r--r-- | mlir/lib/Dialect/QuantOps/Utils/FakeQuantSupport.cpp | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp b/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp index 0c93146a232..32d8c8a81c1 100644 --- a/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp +++ b/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp @@ -70,7 +70,7 @@ public: UniformQuantizedType uniformElementType = fakeQuantAttrsToType( fqOp.getLoc(), fqOp.num_bits().getSExtValue(), fqOp.min().convertToFloat(), fqOp.max().convertToFloat(), - fqOp.narrow_range(), converter.expressedType); + fqOp.narrow_range(), converter.expressedType, fqOp.is_signed()); if (!uniformElementType) { // Note that the fakeQuantAttrsToType will have emitted the error. diff --git a/mlir/lib/Dialect/QuantOps/Utils/FakeQuantSupport.cpp b/mlir/lib/Dialect/QuantOps/Utils/FakeQuantSupport.cpp index 13c622e50d1..2667da98242 100644 --- a/mlir/lib/Dialect/QuantOps/Utils/FakeQuantSupport.cpp +++ b/mlir/lib/Dialect/QuantOps/Utils/FakeQuantSupport.cpp @@ -45,9 +45,15 @@ mlir::quant::fakeQuantAttrsToType(Location loc, unsigned numBits, double rmin, } } else if (numBits <= 16) { storageType = IntegerType::get(16, ctx); - flags = QuantizationFlags::Signed; - qmin = -32768; - qmax = 32767; + if (isSigned) { + flags = QuantizationFlags::Signed; + qmin = -32768; + qmax = 32767; + } else { + flags = 0; + qmin = 0; + qmax = 65535; + } } else { emitError(loc, "unsupported FakeQuant number of bits: ") << numBits; return nullptr; |