Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3113,6 +3113,39 @@ LogicalResult SubViewOp::verify() {
ArrayRef<int64_t> staticSizes = getStaticSizes();
ArrayRef<int64_t> staticStrides = getStaticStrides();

// Check number of static offsets, sizes and strides match source rank.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already verified by the ViewLikeOpInterface verifier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err yes indeed, and I was not hitting it because the issue I had was just before the Subview is created. I thought this patch was catching the issue but I confused the output for an assert. My bad.

int64_t baseRank = baseType.getRank();
size_t numStaticOffsets = staticOffsets.size();
if (static_cast<int64_t>(numStaticOffsets) != baseRank)
return emitError("number of static offsets (")
<< numStaticOffsets << ") does not match source rank (" << baseRank
<< ")";
size_t numStaticSizes = staticSizes.size();
if (static_cast<int64_t>(numStaticSizes) != baseRank)
return emitError("number of static sizes (")
<< numStaticSizes << ") does not match source rank (" << baseRank
<< ")";
size_t numStaticStrides = staticStrides.size();
if (static_cast<int64_t>(numStaticStrides) != baseRank)
return emitError("number of static strides (")
<< numStaticStrides << ") does not match source rank (" << baseRank
<< ")";

// Check number of dynamic offsets, sizes and strides is less of equal to the
// source rank.
size_t numOffsets = getOffsets().size();
if (static_cast<int64_t>(numOffsets) > baseRank)
return emitError("number of dynamic offsets (")
<< numOffsets << ") bigger than rank (" << baseRank << ")";
size_t numSizes = getSizes().size();
if (static_cast<int64_t>(numSizes) > baseRank)
return emitError("number of dynamic sizes (")
<< numSizes << ") bigger than rank (" << baseRank << ")";
size_t numStrides = getStrides().size();
if (static_cast<int64_t>(numStrides) > baseRank)
return emitError("number of dynamic strides (")
<< numStrides << ") bigger than rank (" << baseRank << ")";

// The base memref and the view memref should be in the same memory space.
if (baseType.getMemorySpace() != subViewType.getMemorySpace())
return emitError("different memory spaces specified for base memref "
Expand Down