Skip to content

Commit 65bd5ed

Browse files
authored
[mlir][openacc] Update verifier to catch missing device type attribute (#111586)
Operands with device_type support need the corresponding attribute but this was not catches in the verifier if it was missing. The custom parser usually constructs it but creating the op from python could lead to a segfault in the printer. This patch updates the verifier so we catch this early on.
1 parent f0fc1d3 commit 65bd5ed

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -759,20 +759,23 @@ static LogicalResult verifyDeviceTypeAndSegmentCountMatch(
759759
Op op, OperandRange operands, DenseI32ArrayAttr segments,
760760
ArrayAttr deviceTypes, llvm::StringRef keyword, int32_t maxInSegment = 0) {
761761
std::size_t numOperandsInSegments = 0;
762-
763-
if (!segments)
764-
return success();
765-
766-
for (auto segCount : segments.asArrayRef()) {
767-
if (maxInSegment != 0 && segCount > maxInSegment)
768-
return op.emitOpError() << keyword << " expects a maximum of "
769-
<< maxInSegment << " values per segment";
770-
numOperandsInSegments += segCount;
762+
std::size_t nbOfSegments = 0;
763+
764+
if (segments) {
765+
for (auto segCount : segments.asArrayRef()) {
766+
if (maxInSegment != 0 && segCount > maxInSegment)
767+
return op.emitOpError() << keyword << " expects a maximum of "
768+
<< maxInSegment << " values per segment";
769+
numOperandsInSegments += segCount;
770+
++nbOfSegments;
771+
}
771772
}
772-
if (numOperandsInSegments != operands.size())
773+
774+
if ((numOperandsInSegments != operands.size()) ||
775+
(!deviceTypes && !operands.empty()))
773776
return op.emitOpError()
774777
<< keyword << " operand count does not match count in segments";
775-
if (deviceTypes.getValue().size() != (size_t)segments.size())
778+
if (deviceTypes && deviceTypes.getValue().size() != nbOfSegments)
776779
return op.emitOpError()
777780
<< keyword << " segment count does not match device_type count";
778781
return success();

mlir/test/Dialect/OpenACC/invalid.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ acc.parallel num_gangs({%i64value: i64, %i64value : i64, %i64value : i64, %i64va
507507

508508
// -----
509509

510+
%0 = "arith.constant"() <{value = 1 : i64}> : () -> i64
511+
// expected-error@+1 {{num_gangs operand count does not match count in segments}}
512+
"acc.parallel"(%0) <{numGangsSegments = array<i32: 1>, operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0>}> ({
513+
}) : (i64) -> ()
514+
515+
// -----
516+
510517
%i64value = arith.constant 1 : i64
511518
acc.parallel {
512519
// expected-error@+1 {{'acc.set' op cannot be nested in a compute operation}}

0 commit comments

Comments
 (0)