fix(pto): relax tmrgsort format2 tmp shape check#641
Conversation
Codex Review该评论由 review 机器人自动更新。
SummaryReview failed at stage Findings未生成结构化 findings,因为 review 过程提前失败。 Log Tail |
There was a problem hiding this comment.
Code Review
This pull request relaxes the shape verification for TMrgSortOp in PTO.cpp to allow the temporary buffer (tmp) to have a different shape than the destination buffer (dst), accompanied by a new test case. The reviewer pointed out that removing the shape check entirely is too permissive and could lead to out-of-bounds access if the temporary buffer is smaller than the destination. They suggested enforcing a minimum column size for the temporary buffer and adding checks to ensure all operands are rank-2 with a single row.
| for (Value src : getSrcs()) { | ||
| Type srcTy = src.getType(); | ||
| if (getElemTy(srcTy) != elemTy) |
There was a problem hiding this comment.
Removing the shape check entirely is too permissive. While tmp.cols > dst.cols is valid as per the PR description, tmp.cols < dst.cols would likely lead to out-of-bounds access during the copy from tmp to dst. Consider enforcing tmp.cols >= dst.cols when both are static.
Furthermore, since tmp is used as a staging buffer for the merge operation, it should ideally be large enough to hold the sum of all source columns to avoid buffer overflows during the merge step.
Lastly, format2 should verify that all operands are rank-2 with 1 row, consistent with format1 validation.
auto dstShape = getShapeVec(dstTy);
auto tmpShape = getShapeVec(tmpTy);
if (dstShape.size() != 2 || tmpShape.size() != 2)
return emitOpError() << "format2 expects dst/tmp to be rank-2 tile-shaped";
if ((dstShape[0] != mlir::ShapedType::kDynamic && dstShape[0] != 1) ||
(tmpShape[0] != mlir::ShapedType::kDynamic && tmpShape[0] != 1))
return emitOpError() << "format2 expects dst/tmp rows == 1";
if (dstShape[1] != mlir::ShapedType::kDynamic &&
tmpShape[1] != mlir::ShapedType::kDynamic &&
tmpShape[1] < dstShape[1])
return emitOpError() << "format2 expects tmp.cols >= dst.cols";
for (Value src : getSrcs()) {
Type srcTy = src.getType();
auto sShape = getShapeVec(srcTy);
if (sShape.size() != 2 || (sShape[0] != mlir::ShapedType::kDynamic && sShape[0] != 1))
return emitOpError() << "format2 expects src to be rank-2 with 1 row";
if (getElemTy(srcTy) != elemTy)c52ac10 to
6c3f204
Compare
A5 板测成功
|
A3 板测完成(有跳过)
|
…rmat2 fix(pto): relax tmrgsort format2 tmp shape check
Summary
pto.tmrgsortformat2 verifier by removing the strictdst/tmpshape-equality checktmp.cols > dst.colsRoot Cause
TMrgSortOp::verify()requireddstShape == tmpShapefor format2, but the PTO-ISA/C++ implementation usestmpas a staging buffer viavmrgsort4(tmpPtr, ...)and then copies onlydstColelements fromtmptodst.Repro
Validation
ptoaswithninja -C build ptoasbuild/tools/ptoas/ptoas --pto-arch=a3 test/lit/pto/tmrgsort_format2_tmp_larger_emitc.ptobuild/tools/ptoas/ptoas --pto-arch=a3 test/lit/pto/tmrgsort_variants_emitc.ptobuild/tools/ptoas/ptoas --pto-arch=a3 test/lit/pto/tmrgsort_executed_constant_emitc.ptoCloses #640