Skip to content
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

[mlir][openacc] Update verifier to catch missing device type attribute #111586

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 14 additions & 11 deletions mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,20 +759,23 @@ static LogicalResult verifyDeviceTypeAndSegmentCountMatch(
Op op, OperandRange operands, DenseI32ArrayAttr segments,
ArrayAttr deviceTypes, llvm::StringRef keyword, int32_t maxInSegment = 0) {
std::size_t numOperandsInSegments = 0;

if (!segments)
return success();

for (auto segCount : segments.asArrayRef()) {
if (maxInSegment != 0 && segCount > maxInSegment)
return op.emitOpError() << keyword << " expects a maximum of "
<< maxInSegment << " values per segment";
numOperandsInSegments += segCount;
std::size_t nbOfSegments = 0;

if (segments) {
for (auto segCount : segments.asArrayRef()) {
if (maxInSegment != 0 && segCount > maxInSegment)
return op.emitOpError() << keyword << " expects a maximum of "
<< maxInSegment << " values per segment";
numOperandsInSegments += segCount;
++nbOfSegments;
}
}
if (numOperandsInSegments != operands.size())

if ((numOperandsInSegments != operands.size()) ||
(!deviceTypes && !operands.empty()))
return op.emitOpError()
<< keyword << " operand count does not match count in segments";
if (deviceTypes.getValue().size() != (size_t)segments.size())
if (deviceTypes && deviceTypes.getValue().size() != nbOfSegments)
return op.emitOpError()
<< keyword << " segment count does not match device_type count";
return success();
Expand Down
7 changes: 7 additions & 0 deletions mlir/test/Dialect/OpenACC/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,13 @@ acc.parallel num_gangs({%i64value: i64, %i64value : i64, %i64value : i64, %i64va

// -----

%0 = "arith.constant"() <{value = 1 : i64}> : () -> i64
// expected-error@+1 {{num_gangs operand count does not match count in segments}}
"acc.parallel"(%0) <{numGangsSegments = array<i32: 1>, operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0>}> ({
}) : (i64) -> ()

// -----

%i64value = arith.constant 1 : i64
acc.parallel {
// expected-error@+1 {{'acc.set' op cannot be nested in a compute operation}}
Expand Down
Loading