Skip to content

Commit 1061577

Browse files
committed
[mlir][polynomial] verify from_tensor coeff type
Use the coefficient type to verify if a tensor fits in a polynomial ring. Downstream we had originally not specified the coefficient type and just used the implied bit width of the coefficient modulus. Now that we specify the type, this is simpler.
1 parent cc2fafa commit 1061577

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

mlir/lib/Dialect/Polynomial/IR/PolynomialOps.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ LogicalResult FromTensorOp::verify() {
4747
return diag;
4848
}
4949

50-
APInt coefficientModulus = ring.getCoefficientModulus().getValue();
51-
unsigned cmodBitWidth = coefficientModulus.ceilLogBase2();
5250
unsigned inputBitWidth = getInput().getType().getElementTypeBitWidth();
53-
54-
if (inputBitWidth > cmodBitWidth) {
51+
if (inputBitWidth > ring.getCoefficientType().getIntOrFloatBitWidth()) {
5552
InFlightDiagnostic diag = emitOpError()
5653
<< "input tensor element type "
5754
<< getInput().getType().getElementType()

mlir/test/Dialect/Polynomial/ops_errors.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: mlir-opt --split-input-file --verify-diagnostics %s
22

33
#my_poly = #polynomial.int_polynomial<1 + x**1024>
4-
#ring = #polynomial.ring<coefficientType=i16, coefficientModulus=256:i32, polynomialModulus=#my_poly>
4+
#ring = #polynomial.ring<coefficientType=i16>
55
!ty = !polynomial.polynomial<ring=#ring>
66

77
func.func @test_from_tensor_too_large_coeffs() {

0 commit comments

Comments
 (0)