"""pdist kernel — pairwise p-norm distances over row pairs (upper-triangular output).
Ported from the Stage-4 verified PyPTO-Pro v2 delivery (custom/pdist/test_pdist.py,
verifier PASS 15/15, 16/16 cases, Stage 5 perf evidence) into the ops-math
AscendC packaging. The v2 m-lane row-major design structurally removes the v1
pair-lane transposed layout, whose transpose lowering (vgather2/vscatter at a
64-element row stride) serialized the UB banks — the fp16 [8192,512] case spent
97% of its 963ms in b16 vscatter; with zero transposes the same case runs at
~20.6ms.
* m-lane row-major layout: rows are loaded as a [64, M_BLK] tile in GM
natural row-major order (no transpose; scatter/gather count = 0) and
consumed pair-by-pair — pair p's 64 consecutive m values occupy one fp32
VF register via ``vf.load_align(rows, p*M_BLK + c*LANES)``. The anchor
row chunks a0/a1 are loaded once per VF call and reused across all 64
pairs (replaces the v1 per-m BRC broadcast).
* M-blocking with ping-pong partial-sum state: M blocks of M_BLK=128 columns
accumulate into a resident acc tile pair ([64, 128] fp32, row p = pair p:
cols 0-63 = 64-lane partial sum acc, cols 64-127 = the NaN counter for
PBranch 5), rotated with explicit indices mblk%2 / (mblk+1)%2 and
ordered by vf.mem_bar(VST_VLD)/(VLD_VST).
* M-tail lane neutralization: each chunk's tail lanes (beyond vc) are
zeroed with ``d = vf.select(d, zeros_r, preg_c)`` right after abs_sub
and BEFORE any p-branch chain (all branches map 0 -> 0 contribution);
accumulation then uses the FULL predicate so the nested chunk masks
never clear each other's lanes. Pair tail = finalize p-loop upper
bound vp + out32 valid [1, vp].
* Task tail: per pair one lane-internal ``vf.reduce_sum`` (or
``vf.reduce_max`` for p=inf) + inv-pow in the lane-0 scalar domain, then
a compact 4B write ``vf.store_align(out32, y, preg, p,
dist=FIRST_ELEMENT)`` — 64 pairs accumulate into a [1, 64] contiguous
segment written back with one ``pl.store`` (offsets=[0, base]).
* PBranch folding (TilingKey): PBranch (6 values) compiles a dedicated
instance per p-class; every variant's inner p loop is branch-free.
* Multi-core block-domain contiguous split: the B 64-pair task blocks are
split contiguously per core; each core locates its first block with a
closed-form binary search over cumsegs(i).
* dtype instances: fp32 and fp16 specializations of this single @pl.jit
kernel; the fp16 instance widens rows16/anchor16 with tile-level pl.cast
CAST_NONE at the KERNEL ENTRY (right after pl.load, before abs_sub —
earlier than the v1 post-transpose position), computes entirely in
fp32, and narrows the exit segment with pl.cast CAST_RINT.
* NaN/Inf semantics: exact chains propagate per pair via IEEE arithmetic;
p=inf is the Chebyshev comparison max (GPU/CUDA aligned: gt(NaN, acc)
is false, so NaN dims are ignored and an all-NaN pair keeps 0); general-p
carries an explicit ne(d,d)-based NaN counter (nan_cnt, acc tile cols
64-127) that overwrites the output with NaN in finalize; p=0 counts NaN
dims as mismatched (ne(NaN,0)=1, golden semantics).
Port adaptation (declared deviations vs the Stage-4 source, math identical):
NaN constants in PBranch 5 finalize are materialized with the in-repo idiom
ln(0) = -inf followed by |-inf - (-inf)| = NaN (see dense_lightning_indexer_
softmax_lse_v2.py write_neg_inf_vf for the -inf twin of this idiom), because
the CANN-tree pypto_pro serializes the vf.full(float("nan")) literal as the
libc function name ``nanf``, which bisheng rejects. PBranch 1 (p=+inf) keeps
the remote CUDA-aligned comparison-max chain (gt + select, no NaN counter)
instead of the Stage-4 vf.max + NaN-guard chain: NaN dims are ignored and an
all-NaN pair outputs 0, identical to the remote v1 semantics.
"""
from dataclasses import dataclass
import pypto_pro.language as pl
from pypto_pro.language import Vf as vf
from pypto_pro.runtime.tilingkey import TilingKeyField
TP = 64
M_BLK = 128
LANES = 64
CHUNKS = 2
ACC_STR = 128
NAN_COL = 64
VA_ROWS_F32 = 0x00000
VA_ANCHOR_F32 = 0x10000
VA_ACC_F32 = (
0x10400
)
VA_OUT32_F32 = 0x20400
VA_ROWS16 = 0x00000
VA_ROWS32 = 0x08000
VA_ANCHOR16 = 0x18000
VA_ANCHOR32 = 0x18200
VA_ACC_F16 = (
0x18600
)
VA_OUT32_F16 = 0x28600
VA_OUT16 = 0x28800
@dataclass
class PdistTiling:
N: int
M: int
B: int
p_val: float
inv_p: float
class PdistTilingKey:
PBranch = TilingKeyField(bits=3, values=[0, 1, 2, 3, 4, 5])
@pl.vector_function
def pdist_accum_init_vf(
rows_tile, anchor_tile, acc_out, vp: pl.DT_INT64, vc: pl.DT_INT64, p_val: pl.DT_FP32
):
"""First M block of a task: acc initialized from full(0.0).
acc_out = acc_group[1] (init always writes slot 1). acc tile [64,128],
row p = pair p: cols 0-63 = 64-lane partial sum acc (offset p*ACC_STR),
cols 64-127 = the NaN counter for PBranch 5 (offset p*ACC_STR+NAN_COL).
The zero init is safe for every PBranch: sums start at 0, and the
PBranch 1 comparison max is CUDA-aligned with agg = 0 (d=|.|>=0 never
loses to 0; NaN never wins a gt). fp32/fp16 instances share the same
structure (fp16 passes the widened rows32/anchor32 FP32 tiles).
"""
preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_FP32)
preg_c0 = vf.update_mask(pl.min(LANES, vc), dtype=pl.DT_FP32)
preg_c1 = vf.update_mask(pl.max(vc - LANES, 0), dtype=pl.DT_FP32)
zeros_r = vf.full(0.0, preg, dtype=pl.DT_FP32)
if PBranch == 0:
ones_r = vf.full(1.0, preg, dtype=pl.DT_FP32)
if PBranch == 5:
one_r = vf.full(1.0, preg, dtype=pl.DT_FP32)
a0 = vf.load_align(anchor_tile, 0)
a1 = vf.load_align(anchor_tile, LANES)
for p in pl.range(0, vp):
acc = vf.full(0.0, preg, dtype=pl.DT_FP32)
if PBranch == 5:
nan_cnt = vf.full(0.0, preg, dtype=pl.DT_FP32)
r = vf.load_align(rows_tile, p * M_BLK)
d = vf.abs_sub(a0, r, preg)
d = vf.select(d, zeros_r, preg_c0)
if PBranch == 0:
ne_m = vf.ne(d, 0.0, preg)
dp = vf.select(ones_r, zeros_r, ne_m)
acc = vf.add(acc, dp, preg)
elif PBranch == 1:
gt_m = vf.gt(d, acc, preg)
acc = vf.select(d, acc, gt_m)
elif PBranch == 2:
dp = vf.mul(d, d, preg)
acc = vf.add(acc, dp, preg)
elif PBranch == 3:
acc = vf.add(acc, d, preg)
elif PBranch == 4:
dp = vf.sqrt(d, preg)
acc = vf.add(acc, dp, preg)
else:
nz = vf.ne(d, 0.0, preg)
safe = vf.select(d, one_r, nz)
ld = vf.ln(safe, preg)
ld = vf.muls(ld, p_val, preg)
ed = vf.exp(ld, preg)
dp = vf.select(ed, zeros_r, nz)
acc = vf.add(acc, dp, preg)
nan_m = vf.ne(d, d, preg)
nan_f = vf.select(one_r, zeros_r, nan_m)
nan_cnt = vf.add(nan_cnt, nan_f, preg)
r = vf.load_align(rows_tile, p * M_BLK + LANES)
d = vf.abs_sub(a1, r, preg)
d = vf.select(d, zeros_r, preg_c1)
if PBranch == 0:
ne_m = vf.ne(d, 0.0, preg)
dp = vf.select(ones_r, zeros_r, ne_m)
acc = vf.add(acc, dp, preg)
elif PBranch == 1:
gt_m = vf.gt(d, acc, preg)
acc = vf.select(d, acc, gt_m)
elif PBranch == 2:
dp = vf.mul(d, d, preg)
acc = vf.add(acc, dp, preg)
elif PBranch == 3:
acc = vf.add(acc, d, preg)
elif PBranch == 4:
dp = vf.sqrt(d, preg)
acc = vf.add(acc, dp, preg)
else:
nz = vf.ne(d, 0.0, preg)
safe = vf.select(d, one_r, nz)
ld = vf.ln(safe, preg)
ld = vf.muls(ld, p_val, preg)
ed = vf.exp(ld, preg)
dp = vf.select(ed, zeros_r, nz)
acc = vf.add(acc, dp, preg)
nan_m = vf.ne(d, d, preg)
nan_f = vf.select(one_r, zeros_r, nan_m)
nan_cnt = vf.add(nan_cnt, nan_f, preg)
vf.store_align(acc_out, acc, preg, p * ACC_STR)
if PBranch == 5:
vf.store_align(acc_out, nan_cnt, preg, p * ACC_STR + NAN_COL)
vf.mem_bar(mode=pl.MemBarMode.VST_VLD)
vf.mem_bar(mode=pl.MemBarMode.VLD_VST)
@pl.vector_function
def pdist_accum_acc_vf(
rows_tile,
anchor_tile,
acc_in,
acc_out,
vp: pl.DT_INT64,
vc: pl.DT_INT64,
p_val: pl.DT_FP32,
):
"""Subsequent M blocks: read the previous partial sum (acc_in = slot mblk%2)
and keep accumulating, writing slot (mblk+1)%2."""
preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_FP32)
preg_c0 = vf.update_mask(pl.min(LANES, vc), dtype=pl.DT_FP32)
preg_c1 = vf.update_mask(pl.max(vc - LANES, 0), dtype=pl.DT_FP32)
zeros_r = vf.full(0.0, preg, dtype=pl.DT_FP32)
if PBranch == 0:
ones_r = vf.full(1.0, preg, dtype=pl.DT_FP32)
if PBranch == 5:
one_r = vf.full(1.0, preg, dtype=pl.DT_FP32)
a0 = vf.load_align(anchor_tile, 0)
a1 = vf.load_align(anchor_tile, LANES)
for p in pl.range(0, vp):
acc = vf.load_align(acc_in, p * ACC_STR)
if PBranch == 5:
nan_cnt = vf.load_align(acc_in, p * ACC_STR + NAN_COL)
r = vf.load_align(rows_tile, p * M_BLK)
d = vf.abs_sub(a0, r, preg)
d = vf.select(d, zeros_r, preg_c0)
if PBranch == 0:
ne_m = vf.ne(d, 0.0, preg)
dp = vf.select(ones_r, zeros_r, ne_m)
acc = vf.add(acc, dp, preg)
elif PBranch == 1:
gt_m = vf.gt(d, acc, preg)
acc = vf.select(d, acc, gt_m)
elif PBranch == 2:
dp = vf.mul(d, d, preg)
acc = vf.add(acc, dp, preg)
elif PBranch == 3:
acc = vf.add(acc, d, preg)
elif PBranch == 4:
dp = vf.sqrt(d, preg)
acc = vf.add(acc, dp, preg)
else:
nz = vf.ne(d, 0.0, preg)
safe = vf.select(d, one_r, nz)
ld = vf.ln(safe, preg)
ld = vf.muls(ld, p_val, preg)
ed = vf.exp(ld, preg)
dp = vf.select(ed, zeros_r, nz)
acc = vf.add(acc, dp, preg)
nan_m = vf.ne(d, d, preg)
nan_f = vf.select(one_r, zeros_r, nan_m)
nan_cnt = vf.add(nan_cnt, nan_f, preg)
r = vf.load_align(rows_tile, p * M_BLK + LANES)
d = vf.abs_sub(a1, r, preg)
d = vf.select(d, zeros_r, preg_c1)
if PBranch == 0:
ne_m = vf.ne(d, 0.0, preg)
dp = vf.select(ones_r, zeros_r, ne_m)
acc = vf.add(acc, dp, preg)
elif PBranch == 1:
gt_m = vf.gt(d, acc, preg)
acc = vf.select(d, acc, gt_m)
elif PBranch == 2:
dp = vf.mul(d, d, preg)
acc = vf.add(acc, dp, preg)
elif PBranch == 3:
acc = vf.add(acc, d, preg)
elif PBranch == 4:
dp = vf.sqrt(d, preg)
acc = vf.add(acc, dp, preg)
else:
nz = vf.ne(d, 0.0, preg)
safe = vf.select(d, one_r, nz)
ld = vf.ln(safe, preg)
ld = vf.muls(ld, p_val, preg)
ed = vf.exp(ld, preg)
dp = vf.select(ed, zeros_r, nz)
acc = vf.add(acc, dp, preg)
nan_m = vf.ne(d, d, preg)
nan_f = vf.select(one_r, zeros_r, nan_m)
nan_cnt = vf.add(nan_cnt, nan_f, preg)
vf.store_align(acc_out, acc, preg, p * ACC_STR)
if PBranch == 5:
vf.store_align(acc_out, nan_cnt, preg, p * ACC_STR + NAN_COL)
vf.mem_bar(mode=pl.MemBarMode.VST_VLD)
vf.mem_bar(mode=pl.MemBarMode.VLD_VST)
@pl.vector_function
def pdist_finalize_vf(acc_tile, out_tile, vp: pl.DT_INT64, inv_p: pl.DT_FP32):
"""Task tail: in-lane reduction + inv-pow + FIRST_ELEMENT 4B compact write.
Reads the last written slot (acc_group[n_mblk%2]). acc row p = pair p
(offset p*ACC_STR), tail lanes are always 0 (init 0 + tail-zeroed
accumulation) -> reduce_sum counts 0 with no effect / reduce_max (d>=0)
leaves the maximum unchanged. Each pair's reduction result lands in dst[0]
(remaining lanes zeroed), then store_align(dist=FIRST_ELEMENT) writes the
single 4B lane-0 element to out32 element p.
NaN constants are materialized as |-inf - (-inf)| with -inf = ln(0)
(in-repo idiom; avoids the float("nan") literal, see module docstring).
"""
preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_FP32)
for p in pl.range(0, vp):
acc = vf.load_align(acc_tile, p * ACC_STR)
if PBranch == 0:
y = vf.reduce_sum(acc, preg)
elif PBranch == 1:
y = vf.reduce_max(acc, preg)
elif PBranch == 2:
s = vf.reduce_sum(acc, preg)
y = vf.sqrt(s, preg)
elif PBranch == 3:
y = vf.reduce_sum(acc, preg)
elif PBranch == 4:
s = vf.reduce_sum(acc, preg)
y = vf.mul(s, s, preg)
else:
nan_cnt = vf.load_align(acc_tile, p * ACC_STR + NAN_COL)
s = vf.reduce_sum(acc, preg)
nz_s = vf.ne(s, 0.0, preg)
one_r = vf.full(1.0, preg, dtype=pl.DT_FP32)
zero_r = vf.full(0.0, preg, dtype=pl.DT_FP32)
s_safe = vf.select(s, one_r, nz_s)
ls = vf.ln(s_safe, preg)
ls = vf.muls(ls, inv_p, preg)
es = vf.exp(ls, preg)
y = vf.select(es, zero_r, nz_s)
nc_max = vf.reduce_max(
nan_cnt, preg
)
bad = vf.ne(nc_max, 0.0, preg)
ninf_r = vf.ln(zero_r, preg)
nan_r = vf.abs_sub(ninf_r, ninf_r, preg)
y = vf.select(nan_r, y, bad)
vf.store_align(out_tile, y, preg, p, dist=pl.StoreDist.FIRST_ELEMENT)
vf.mem_bar(mode=pl.MemBarMode.VLD_VST)
@pl.jit(
auto_mutex=True,
tiling_key=PdistTilingKey,
datatype={"x": "io_dtype", "y": "io_dtype"},
)
def pdist(
x: pl.Ptr[pl.DT_UINT8],
y: pl.Ptr[pl.DT_UINT8],
workspace: pl.Ptr[pl.DT_UINT8],
tiling: PdistTiling,
):
"""pdist m-lane distance kernel (main @pl.jit kernel, named after the op file).
x: [N, M] GM (fp32 or fp16, ND row-major); y: [N(N-1)/2] GM (same dtype as x).
workspace: unused by this kernel, but REQUIRED by the AscendC opc ABI — the runtime
passes (inputs..., workspace, tiling) in the args area, so the signature must keep
workspace as the second-to-last parameter (see dense_lightning_indexer_softmax_lse_v2).
io_dtype is the datatype-specialization compile-time constant: the
if io_dtype == pl.DT_FP16 branch folds at parse time, so each dtype instance
compiles only its own address table (fp32 / fp16).
The rows tile [64,128] is read row-major directly (pl.load GM 2D block);
the VF consumes it pair-by-pair via load_align(rows, p*M_BLK + c*LANES) —
no transpose anywhere.
"""
N = tiling.N
M = tiling.M
B = tiling.B
L = N * (N - 1) // 2
tensor_x = pl.make_tensor(x, [N, M], dtype=io_dtype)
tensor_y = pl.make_tensor(
y, [1, L], dtype=io_dtype
)
with pl.section_vector():
core_id = pl.get_block_idx()
num_cores = pl.get_block_num() * pl.get_subblock_num()
lo = core_id * B // num_cores
hi = (core_id + 1) * B // num_cores
qf = (N - 1) // 64
rf = N - 1 - qf * 64
F2 = 32 * qf * (qf - 1) + qf * rf
i = 0
i_hi = N - 2
for _b in pl.range(0, 17):
if i < i_hi:
mid = (i + i_hi + 1) // 2
tm = N - 1 - mid
qm = tm // 64
fm = 32 * qm * (qm - 1) + qm * (tm - qm * 64)
if mid + F2 - fm <= lo:
i = mid
else:
i_hi = mid - 1
ti = N - 1 - i
qi = ti // 64
fi = 32 * qi * (qi - 1) + qi * (ti - qi * 64)
jseg = lo - (i + F2 - fi)
if io_dtype == pl.DT_FP16:
rows16_group = pl.make_tile_group(
type=pl.TileType(
shape=[TP, M_BLK],
dtype=pl.DT_FP16,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_ROWS16,
mutex_ids=[0, 1],
)
rows32_group = pl.make_tile_group(
type=pl.TileType(
shape=[TP, M_BLK],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_ROWS32,
mutex_ids=[2, 3],
)
anchor16_group = pl.make_tile_group(
type=pl.TileType(
shape=[1, M_BLK],
dtype=pl.DT_FP16,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_ANCHOR16,
mutex_ids=[4, 5],
)
anchor32_group = pl.make_tile_group(
type=pl.TileType(
shape=[1, M_BLK],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_ANCHOR32,
mutex_ids=[6, 7],
)
acc_group = pl.make_tile_group(
type=pl.TileType(
shape=[TP, ACC_STR],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
),
addrs=VA_ACC_F16,
depth=2,
)
out32_group = pl.make_tile_group(
type=pl.TileType(
shape=[1, TP],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_OUT32_F16,
mutex_ids=[8, 9],
)
out16_group = pl.make_tile_group(
type=pl.TileType(
shape=[1, TP],
dtype=pl.DT_FP16,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_OUT16,
mutex_ids=[10, 11],
)
for t in pl.range(0, hi - lo):
j0 = i + 1 + jseg * TP
vp = pl.min(TP, N - 1 - i - jseg * TP)
base = (
i * (2 * N - i - 1)
) // 2 + jseg * TP
n_mblk = (M + M_BLK - 1) // M_BLK
for mblk in pl.range(0, n_mblk):
m0 = mblk * M_BLK
vc = pl.min(M_BLK, M - m0)
rows16_slot = rows16_group.next()
pl.set_validshape(rows16_slot, [vp, vc])
anchor16_slot = anchor16_group.next()
pl.set_validshape(anchor16_slot, [1, vc])
rows32_slot = rows32_group.next()
pl.set_validshape(rows32_slot, [vp, vc])
anchor32_slot = anchor32_group.next()
pl.set_validshape(anchor32_slot, [1, vc])
pl.load(rows16_slot, tensor_x, [j0, m0])
pl.load(anchor16_slot, tensor_x, [i, m0])
pl.cast(rows32_slot, rows16_slot, mode=pl.RoundMode.CAST_NONE)
pl.cast(anchor32_slot, anchor16_slot, mode=pl.RoundMode.CAST_NONE)
if mblk == 0:
pdist_accum_init_vf(
rows32_slot,
anchor32_slot,
acc_group[1],
vp,
vc,
tiling.p_val,
)
else:
pdist_accum_acc_vf(
rows32_slot,
anchor32_slot,
acc_group[mblk % 2],
acc_group[(mblk + 1) % 2],
vp,
vc,
tiling.p_val,
)
out32_slot = out32_group.next()
pl.set_validshape(out32_slot, [1, vp])
pdist_finalize_vf(acc_group[n_mblk % 2], out32_slot, vp, tiling.inv_p)
out16_slot = out16_group.next()
pl.set_validshape(out16_slot, [1, vp])
pl.cast(
out16_slot, out32_slot, mode=pl.RoundMode.CAST_RINT
)
pl.store(tensor_y, out16_slot, [0, base])
jseg = jseg + 1
segs_i = (N - 2 - i) // TP + 1
if jseg == segs_i:
i = i + 1
jseg = 0
else:
rows_group = pl.make_tile_group(
type=pl.TileType(
shape=[TP, M_BLK],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_ROWS_F32,
mutex_ids=[0, 1],
)
anchor_group = pl.make_tile_group(
type=pl.TileType(
shape=[1, M_BLK],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_ANCHOR_F32,
mutex_ids=[2, 3],
)
acc_group = pl.make_tile_group(
type=pl.TileType(
shape=[TP, ACC_STR],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
),
addrs=VA_ACC_F32,
depth=2,
)
out32_group = pl.make_tile_group(
type=pl.TileType(
shape=[1, TP],
dtype=pl.DT_FP32,
target_memory=pl.MemorySpace.Vec,
valid_shape=[-1, -1],
),
addrs=VA_OUT32_F32,
mutex_ids=[4, 5],
)
for t in pl.range(0, hi - lo):
j0 = i + 1 + jseg * TP
vp = pl.min(TP, N - 1 - i - jseg * TP)
base = (i * (2 * N - i - 1)) // 2 + jseg * TP
n_mblk = (M + M_BLK - 1) // M_BLK
for mblk in pl.range(0, n_mblk):
m0 = mblk * M_BLK
vc = pl.min(M_BLK, M - m0)
rows_slot = rows_group.next()
pl.set_validshape(rows_slot, [vp, vc])
anchor_slot = anchor_group.next()
pl.set_validshape(anchor_slot, [1, vc])
pl.load(rows_slot, tensor_x, [j0, m0])
pl.load(anchor_slot, tensor_x, [i, m0])
if mblk == 0:
pdist_accum_init_vf(
rows_slot, anchor_slot, acc_group[1], vp, vc, tiling.p_val
)
else:
pdist_accum_acc_vf(
rows_slot,
anchor_slot,
acc_group[mblk % 2],
acc_group[(mblk + 1) % 2],
vp,
vc,
tiling.p_val,
)
out_slot = out32_group.next()
pl.set_validshape(out_slot, [1, vp])
pdist_finalize_vf(acc_group[n_mblk % 2], out_slot, vp, tiling.inv_p)
pl.store(tensor_y, out_slot, [0, base])
jseg = jseg + 1
segs_i = (N - 2 - i) // TP + 1
if jseg == segs_i:
i = i + 1
jseg = 0