From 0ebebe5b064cda97d86f9138c2bfe4dfe083320b Mon Sep 17 00:00:00 2001 From: likai00 Date: Tue, 14 Jul 2026 21:53:24 +0800 Subject: [PATCH] fix tfillpad --- lib/TileOps/tfillpad_expand_template.py | 31 +++++++++++++------------ lib/TileOps/tfillpad_template.py | 31 +++++++++++++------------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/TileOps/tfillpad_expand_template.py b/lib/TileOps/tfillpad_expand_template.py index 9fa3f435cd..6368503484 100644 --- a/lib/TileOps/tfillpad_expand_template.py +++ b/lib/TileOps/tfillpad_expand_template.py @@ -74,12 +74,12 @@ def template_tfillpad_expand(src: pto.Tile, dst: pto.Tile): has_valid_expansion = (src_valid_cols < dst_valid_cols) or (src_valid_rows < dst_valid_rows) # PadValue handling - dtype-specific - if pto.constexpr(dtype == pto.f32): - if pto.constexpr(dst.pad_value == pto.PadValue.ZERO): - if has_valid_expansion: - fill_scalar = pto.f32(_NEG1_F32) - else: - fill_scalar = pto.f32(0.0) + if pto.constexpr(dtype == pto.f32): + if pto.constexpr(dst.pad_value == pto.PadValue.ZERO): + if has_valid_expansion: + fill_scalar = pto.f32(_NEG1_F32) + else: + fill_scalar = pto.f32(0.0) elif pto.constexpr(dst.pad_value != pto.PadValue.NULL): fill_scalar = dst.pad_value.eval() else: @@ -131,15 +131,16 @@ def template_tfillpad_expand(src: pto.Tile, dst: pto.Tile): fill_scalar = pto.i8(0) # Phase 1: Copy aligned valid blocks - for row in range(0, src_valid_rows, 1): - remained = aligned_col - for col in range(0, aligned_col, lanes): - mask, remained = pto.make_mask(dtype, remained) - data = pto.vlds(src[row, col:]) - pto.vsts(data, dst[row, col:], mask) + if aligned_col > 0: + for row in range(0, src_valid_rows, 1): + remained = aligned_col + for col in range(0, aligned_col, lanes): + mask, remained = pto.make_mask(dtype, remained) + data = pto.vlds(src[row, col:]) + pto.vsts(data, dst[row, col:], mask) # Phase 2: Fill col padding - if aligned_col < dst_valid_cols: + if aligned_col < dst_valid_cols: for row in range(0, dst_valid_rows, 1): remained = dst_valid_cols - aligned_col for col in range(aligned_col, dst_valid_cols, lanes): @@ -148,7 +149,7 @@ def template_tfillpad_expand(src: pto.Tile, dst: pto.Tile): pto.vsts(vec, dst[row, col:], mask) # Phase 3: Copy tail valid lanes - if has_tail: + if has_tail: for row in range(0, src_valid_rows, 1): remained = src_valid_cols - aligned_col mask_copy, remained = pto.make_mask(dtype, remained) @@ -164,4 +165,4 @@ def template_tfillpad_expand(src: pto.Tile, dst: pto.Tile): vec = pto.vdup(fill_scalar, mask) pto.vsts(vec, dst[row, col:], mask) - return + return diff --git a/lib/TileOps/tfillpad_template.py b/lib/TileOps/tfillpad_template.py index 3378cb1983..b78af6f821 100644 --- a/lib/TileOps/tfillpad_template.py +++ b/lib/TileOps/tfillpad_template.py @@ -80,12 +80,12 @@ def template_tfillpad(src: pto.Tile, dst: pto.Tile): has_valid_expansion = (src_valid_cols < dst_valid_cols) or (src_valid_rows < dst_valid_rows) # PadValue handling - dtype-specific (inline to avoid external call) - if pto.constexpr(dtype == pto.f32): - if pto.constexpr(dst.pad_value == pto.PadValue.ZERO): - if has_valid_expansion: - fill_scalar = pto.f32(_NEG1_F32) - else: - fill_scalar = pto.f32(0.0) + if pto.constexpr(dtype == pto.f32): + if pto.constexpr(dst.pad_value == pto.PadValue.ZERO): + if has_valid_expansion: + fill_scalar = pto.f32(_NEG1_F32) + else: + fill_scalar = pto.f32(0.0) elif pto.constexpr(dst.pad_value != pto.PadValue.NULL): fill_scalar = dst.pad_value.eval() else: @@ -137,15 +137,16 @@ def template_tfillpad(src: pto.Tile, dst: pto.Tile): fill_scalar = pto.i8(0) # Phase 1: Copy aligned valid blocks - for row in range(0, src_valid_rows, 1): - remained = aligned_col - for col in range(0, aligned_col, lanes): - mask, remained = pto.make_mask(dtype, remained) - data = pto.vlds(src[row, col:]) - pto.vsts(data, dst[row, col:], mask) + if aligned_col > 0: + for row in range(0, src_valid_rows, 1): + remained = aligned_col + for col in range(0, aligned_col, lanes): + mask, remained = pto.make_mask(dtype, remained) + data = pto.vlds(src[row, col:]) + pto.vsts(data, dst[row, col:], mask) # Phase 2: Fill cols from aligned_col to dst_cols-1 - if aligned_col < dst_cols: + if aligned_col < dst_cols: for row in range(0, src_valid_rows, 1): remained = dst_cols - aligned_col for col in range(aligned_col, dst_cols, lanes): @@ -154,7 +155,7 @@ def template_tfillpad(src: pto.Tile, dst: pto.Tile): pto.vsts(vec, dst[row, col:], mask) # Phase 3: Copy tail valid lanes - if has_tail: + if has_tail: for row in range(0, src_valid_rows, 1): remained = src_valid_cols - aligned_col mask_copy, remained = pto.make_mask(dtype, remained) @@ -170,4 +171,4 @@ def template_tfillpad(src: pto.Tile, dst: pto.Tile): vec = pto.vdup(fill_scalar, mask) pto.vsts(vec, dst[row, col:], mask) - return + return