Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions src/op/ascend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ Stmt AscendCopy::Lower(const LowerArgs &T, arith::Analyzer *analyzer) const {
auto compute_valid_extent = [](PrimExpr min_val, PrimExpr extent,
PrimExpr shape) -> PrimExpr {
PrimExpr remaining = shape - min_val;
if (remaining.dtype().lanes() > 1) {
return extent;
}
return Select(remaining >= extent, extent,
Select(remaining > 0, remaining, 0));
};
Expand Down Expand Up @@ -570,6 +573,9 @@ Stmt AscendAtomicAdd::Lower(const LowerArgs &T,
auto compute_valid_extent = [](PrimExpr min_val, PrimExpr extent,
PrimExpr shape) -> PrimExpr {
PrimExpr remaining = shape - min_val;
if (remaining.dtype().lanes() > 1) {
return extent;
}
Comment on lines +576 to +578
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for compute_valid_extent is duplicated here from AscendCopy::Lower (line 333). To improve maintainability and reduce code duplication, consider refactoring this into a shared helper function or a static method within the file.

return Select(remaining >= extent, extent,
Select(remaining > 0, remaining, 0));
};
Expand Down Expand Up @@ -612,10 +618,6 @@ Stmt AscendAtomicAdd::Lower(const LowerArgs &T,
ICHECK_EQ(dst_extents.size(), dst->shape.size())
<< "tl.ascend_atomic_add destination region rank must match "
"destination buffer rank";
ICHECK_EQ(src_extents.size(), dst_extents.size())
<< "tl.ascend_atomic_add requires src and dst regions to have the same "
"rank, got src "
<< src_extents.size() << " and dst " << dst_extents.size();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The rank equality check between src_extents and dst_extents has been removed to support cases where the source and destination regions have different ranks (e.g., 2D to 4D). While this is necessary for the described fix, it is important to ensure that the total number of elements in both regions still matches. Consider adding a check to verify that src_len == dst_len after they are computed (around line 664) to prevent potential out-of-bounds access or mismatched data transfers.

std::stringstream ss;
if (src.scope() == "shared") {
Expand Down
15 changes: 13 additions & 2 deletions src/target/codegen_ascend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2252,8 +2252,19 @@ void CodeGenTileLangAscend::CopyCodegen(const CallNode *op) {
dst_var_id = dst_var->name_hint;
}

auto src_offset = PrintExpr(op->args[1].as<CallNode>()->args[2]);
auto dst_offset = PrintExpr(op->args[2].as<CallNode>()->args[2]);
auto src_offset_expr = op->args[1].as<CallNode>()->args[2];
auto dst_offset_expr = op->args[2].as<CallNode>()->args[2];
// AscendLowerParallelToVector may produce Ramp offsets (e.g. vid * stride).
// AscendC GlobalTensor/LocalTensor operator[] expects a scalar start offset;
// per-element strides within a tile are handled by DataCopyExtParams / DMA.
if (const auto *ramp = src_offset_expr.as<RampNode>()) {
src_offset_expr = ramp->base;
}
if (const auto *ramp = dst_offset_expr.as<RampNode>()) {
dst_offset_expr = ramp->base;
}
auto src_offset = PrintExpr(src_offset_expr);
auto dst_offset = PrintExpr(dst_offset_expr);

auto src_type = GetAccessPtrDtype(op->args[1].as<CallNode>());
auto dst_type = GetAccessPtrDtype(op->args[2].as<CallNode>());
Expand Down
10 changes: 7 additions & 3 deletions src/transform/ascend_storage_rewrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1460,9 +1460,13 @@ class VectorTypeAccessChecker : public StmtExprVisitor {
// vectorized pointer types (e.g. float16x4*). Once they do, this if
// statement should instead be replaced by the below ICHECK_EQ.
if (index_lanes * var_info.element_dtype.lanes() != value_dtype.lanes()) {
ICHECK_EQ(index_lanes, value_dtype.lanes());
lanes_used = 1;
var_info.element_dtype = var_info.element_dtype.with_lanes(1);
if (index_lanes > 1 && value_dtype.lanes() == 1) {
lanes_used = 1;
} else {
ICHECK_EQ(index_lanes, value_dtype.lanes());
lanes_used = 1;
var_info.element_dtype = var_info.element_dtype.with_lanes(1);
}
}

// TODO(Lunderberg): Uncomment this check once it can be applied.
Expand Down
Loading