Open
单loop写后写依赖检测 #1
songyangyang18Add on Sep 11
Sep 11 Modify description of issue
Sep 11 Modify description of issue
Sep 11 Modify description of issue
Sep 11 Modify description of issue
Sep 11 Modify description of issue
Sep 11 Modify description of issue
Sep 11 Modify description of issue
Sep 11 Modify description of issue
Sep 11 Modify description of issue
1. 背景
当前的依赖关系可以分为三种,包括跨rootfunction的读后写/写后读/写后写。
读后写/写后读我们通过是否存在消费者给予WAR/RAW标记。
写后写的依赖判定,当前仅由tensor所在rootfunction数量>=2来决定。
问题:单rootfunction下写后写缺乏有效判定依据
问题单场景:在一次循环中,每次写同一块区域,依赖丢失,精度失败。
for i in pypto.loop(n, name="IDX_DJ", idx_name="i"): v1 = in_t.view([tile, hidden], [i * tile, 0], valid_shape=[(bs - i * tile).min(tile), hidden]) mul_ext0 = pypto.mul(v1, 4.0) pypto.assemble(mul_ext0, [0, 0], ext0_t)2. 泛化性场景分析
综合目前常见用例场景,大致可以分为两类。
第一类是offset只包含立即数或者循环不变量(offset = [0, 0], offset=[base, 0]),这一类往往明显存在写区域重叠;
第二种是offset包含循环变量(offset = [i * tile, 0]),这一类往往根据tile大小随着循环次数变化写区域,需要额外的区域重叠判定;
场景矩阵
写窗为
[offset, offset + tile),记第i次迭代的写框为 W(i),考察 W(i) 与 W(i+1) 是否可能重叠。idx_disjointi * tiletile,恰好相接不重叠idx_stride_2tilei * (2 * tile)2*tile,留空档idx_stride_tile_plus1i * (tile + 1)tile+1,严格分离idx_inv_base_plus_i_tilebase + i * tiletile;base在差值中相消idx_overlapi * (tile // 2)fixed_offset_same[0, 0]idx_inv_base_fixed[base, 0]3. 解决方案
通过表达式谓词求解,针对写操作(assemble)的tensor shape与offset,进行单loop循环间区域重叠检测预分析。
4. 决策点
方案修改量较大,实际使用场景上较少,申请CCB到下个版本转需求。