Skip to content

Commit 6bcec91

Browse files
naummoGoogle-ML-Automation
authored andcommitted
[Mosaic] Improve error verbosity of tpu.memref_slice verification
Breaks down the compound verification conditional into smaller checks with verbose error messages. PiperOrigin-RevId: 707699990
1 parent 89a54a9 commit 6bcec91

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

jaxlib/mosaic/dialect/tpu/tpu_ops.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,25 @@ LogicalResult MemRefSliceOp::verify() {
119119
// the canonicalizer, so we allow this when attributes are "unset" in the
120120
// target type. Note that MemRefType does not allow a null layout so we treat
121121
// the default identity affine map as an "unset" value instead.
122-
return success(
123-
(target_memory_space == nullptr ||
124-
target_memory_space == source_type.getMemorySpace()) &&
125-
((isa<AffineMapAttr>(target_layout) && target_layout.isIdentity()) ||
126-
target_type.getLayout() == source_type.getLayout()) &&
127-
getDynamicSizes().size() == target_type.getNumDynamicDims());
122+
bool is_target_memory_space_provided = target_memory_space != nullptr;
123+
if (is_target_memory_space_provided &&
124+
target_memory_space != source_type.getMemorySpace()) {
125+
return emitOpError(
126+
"Memory spaces must match if the target memory space is provided.");
127+
}
128+
bool is_target_layout_identity_map =
129+
isa<AffineMapAttr>(target_layout) && target_layout.isIdentity();
130+
if (!is_target_layout_identity_map &&
131+
target_type.getLayout() != source_type.getLayout()) {
132+
return emitOpError(
133+
"Layouts must match if the target layout is not an identity map.");
134+
}
135+
if (getDynamicSizes().size() != target_type.getNumDynamicDims()) {
136+
return emitOpError(
137+
"Number of provided dynamic dimensions sizes must match the number of "
138+
"dynamic dimensions in the target type.");
139+
}
140+
return success();
128141
}
129142

130143
LogicalResult MemRefSliceOp::canonicalize(MemRefSliceOp op,

0 commit comments

Comments
 (0)