Skip to content

Commit

Permalink
[TPU][Mosaic][Easy] Add verification for AssumeMultipleOp.
Browse files Browse the repository at this point in the history
A user must use AssumeMultipleOp to annotate integer constants that are divisible by the given multiple.

PiperOrigin-RevId: 726994750
  • Loading branch information
Google-ML-Automation committed Feb 15, 2025
1 parent 962eb41 commit 2a5ad2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions jaxlib/mosaic/dialect/tpu/tpu.td
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def TPU_AssumeMultipleOp : TPU_Op<"assume_multiple", [Pure, SameOperandsAndResul
I32Attr:$multiple
);
let results = (outs AnyTypeOf<[Index, AnyInteger]>:$result);
let hasVerifier = 1;
}

def TPU_MemRefSliceOp : TPU_Op<"memref_slice", [Pure, AttrSizedOperandSegments]> {
Expand Down
21 changes: 21 additions & 0 deletions jaxlib/mosaic/dialect/tpu/tpu_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,27 @@ LogicalResult DynamicGatherOp::verify() {
return success();
}

LogicalResult AssumeMultipleOp::verify() {
auto operand_value = getValue();
auto divisor = getMultiple();
if (auto cst_op = operand_value.getDefiningOp<arith::ConstantOp>()) {
auto int_attr = dyn_cast<IntegerAttr>(cst_op.getValue());
// Illegal usage of AssumeMultipleOp.
if (!int_attr) {
return emitOpError(
"Illegal user annotation, expected an integer, but got ")
<< cst_op.getValue();
}
if (int_attr.getInt() % divisor != 0) {
return emitOpError(
"Illegal user annotation, expected an integer that is "
"divisible by the multiple, but got ")
<< int_attr.getInt() << " % " << divisor;
}
}
return success();
}

} // namespace tpu
} // namespace mlir

Expand Down

0 comments on commit 2a5ad2d

Please sign in to comment.