-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir] ViewLikeInterface - verify ranks in verifyOffsetSizeAndStrideOp #147926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,32 @@ SliceBoundsVerificationResult mlir::verifyInBoundsSlice( | |
|
||
LogicalResult | ||
mlir::detail::verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op) { | ||
// A dynamic size is represented as ShapedType::kDynamic in `static_sizes`. | ||
// Its corresponding Value appears in `sizes`. Thus, the number of dynamic | ||
// dimensions in `static_sizes` must equal the rank of `sizes`. | ||
// The same applies to strides and offsets. | ||
unsigned int numDynamicDims = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
llvm::count_if(op.getStaticSizes(), ShapedType::isDynamic); | ||
if (op.getSizes().size() != numDynamicDims) { | ||
return op->emitError("expected sizes rank to match the number of dynamic " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I wouldn't use the term "rank" because users may think of the rank of the source e.g.:
|
||
"dimensions (") | ||
<< op.getSizes().size() << " vs " << numDynamicDims << ")"; | ||
} | ||
unsigned int numDynamicStrides = | ||
llvm::count_if(op.getStaticStrides(), ShapedType::isDynamic); | ||
if (op.getStrides().size() != numDynamicStrides) { | ||
return op->emitError("expected strides rank to match the number of dynamic " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
"strides (") | ||
<< op.getStrides().size() << " vs " << numDynamicStrides << ")"; | ||
} | ||
unsigned int numDynamicOffsets = | ||
llvm::count_if(op.getStaticOffsets(), ShapedType::isDynamic); | ||
if (op.getOffsets().size() != numDynamicOffsets) { | ||
return op->emitError("expected offsets rank to match the number of dynamic " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
"offsets (") | ||
<< op.getOffsets().size() << " vs " << numDynamicOffsets << ")"; | ||
} | ||
|
||
std::array<unsigned, 3> maxRanks = op.getArrayAttrMaxRanks(); | ||
// Offsets can come in 2 flavors: | ||
// 1. Either single entry (when maxRanks == 1). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use C++ style static_cast and size_t.