Skip to content

Commit

Permalink
Add stream_read/write verifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchenye committed Feb 15, 2024
1 parent 8d436f7 commit 73e8373
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions lib/Dialect/HLS/IR/HLSOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,19 @@ void StreamOp::getEffects(
//===----------------------------------------------------------------------===//

LogicalResult StreamReadOp::verify() {
auto channelType = getChannel().getType();
if (getResult())
if (getChannel().getType().getElementType() != getResult().getType())
if (channelType.getElementType() != getResult().getType())
return emitOpError("result type doesn't align with channel type");

auto loops = getSurroundingLoops(*this, getChannel().getParentBlock());
auto tripCounts = getLoopTripCounts(loops);
auto steps = getLoopSteps(loops);
if (!tripCounts || !steps ||
channelType.getIterTripCounts() != ArrayRef<int64_t>(*tripCounts) ||
channelType.getIterSteps() != ArrayRef<int64_t>(*steps))
return emitOpError("iteration trip counts or steps doesn't align with "
"stream type's iteration trip counts or steps");
return success();
}

Expand All @@ -271,8 +281,18 @@ void StreamReadOp::getEffects(
//===----------------------------------------------------------------------===//

LogicalResult StreamWriteOp::verify() {
if (getChannel().getType().getElementType() != getValue().getType())
auto channelType = getChannel().getType();
if (channelType.getElementType() != getValue().getType())
return emitOpError("value type doesn't align with channel type");

auto loops = getSurroundingLoops(*this, getChannel().getParentBlock());
auto tripCounts = getLoopTripCounts(loops);
auto steps = getLoopSteps(loops);
if (!tripCounts || !steps ||
channelType.getIterTripCounts() != ArrayRef<int64_t>(*tripCounts) ||
channelType.getIterSteps() != ArrayRef<int64_t>(*steps))
return emitOpError("iteration trip counts or steps doesn't align with "
"stream type's iteration trip counts or steps");
return success();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/HLS/IR/HLSTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool hls::StreamType::isConvertableWith(RankedTensorType tensor) const {
return false;
if (getDataType() != tensor.getElementType())
return false;
if (getShape() != SmallVector<int64_t>(tensor.getShape()))
if (ArrayRef<int64_t>(getShape()) != tensor.getShape())
return false;
return true;
}

0 comments on commit 73e8373

Please sign in to comment.