From 22ade6367b18c79634455232167473607712b963 Mon Sep 17 00:00:00 2001 From: TaoTao-real Date: Fri, 3 Apr 2026 11:43:17 +0800 Subject: [PATCH] test: fix a5 incore offsets for rmsnorm and decode projection --- .../Sync/decode_projection_incore_0.pto | 78 +++++++++++++++++++ test/samples/Sync/rmsnorm_incore_0.pto | 74 ++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 test/samples/Sync/decode_projection_incore_0.pto create mode 100644 test/samples/Sync/rmsnorm_incore_0.pto diff --git a/test/samples/Sync/decode_projection_incore_0.pto b/test/samples/Sync/decode_projection_incore_0.pto new file mode 100644 index 00000000..43182464 --- /dev/null +++ b/test/samples/Sync/decode_projection_incore_0.pto @@ -0,0 +1,78 @@ +module attributes {pto.target_arch = "a5"} { + func.func @decode_projection_incore_0(%arg0: !pto.ptr, %arg1: !pto.ptr, %arg2: !pto.ptr, %arg3: index) attributes {pto.kernel_kind = #pto.kernel_kind} { + %c0i = arith.constant 0 : i64 + %c64 = arith.constant 64 : i64 + %c4160 = arith.constant 4160 : i64 + %c12352 = arith.constant 12352 : i64 + %c20544 = arith.constant 20544 : i64 + %c20608 = arith.constant 20608 : i64 + %c20672 = arith.constant 20672 : i64 + %c16 = arith.constant 16 : index + %c8192 = arith.constant 8192 : index + %c1 = arith.constant 1 : index + %cst = arith.constant 0.000000e+00 : f32 + %c0 = arith.constant 0 : index + %9 = arith.constant 64 : index + %c128 = arith.constant 128 : index + %cst_1 = arith.constant 1.220703e-04 : f32 + %cst_2 = arith.constant 1.000000e-06 : f32 + %hidden_states__ssa_v0_view = pto.make_tensor_view %arg0, shape = [%c16, %c8192], strides = [%c8192, %c1] {layout = #pto.layout}: !pto.tensor_view + %input_rms_weight__ssa_v0_view = pto.make_tensor_view %arg1, shape = [%c1, %c8192], strides = [%c8192, %c1] {layout = #pto.layout}: !pto.tensor_view + %normed_tile__ssa_v0_view = pto.make_tensor_view %arg2, shape = [%c16, %c8192], strides = [%c8192, %c1] {layout = #pto.layout}: !pto.tensor_view + %partial_sq_flat__tile = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.texpands ins(%cst : f32) outs(%partial_sq_flat__tile : !pto.tile_buf) + %partial_sq__tile = pto.alloc_tile addr = %c0i : !pto.tile_buf + scf.for %kb__idx_v0 = %c0 to %9 step %c1 { + %10 = arith.muli %kb__idx_v0, %c128 : index + %t__tile = pto.alloc_tile addr = %c64 : !pto.tile_buf + %hidden_states__ssa_v0_pview = pto.partition_view %hidden_states__ssa_v0_view, offsets = [%c0, %10], sizes = [%c16, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<16x128xbf16> + pto.tload ins(%hidden_states__ssa_v0_pview : !pto.partition_tensor_view<16x128xbf16>) outs(%t__tile : !pto.tile_buf) + %x_chunk__tile = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tcvt ins(%t__tile{rmode = #pto} : !pto.tile_buf) outs(%x_chunk__tile : !pto.tile_buf) + %0 = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tmul ins(%x_chunk__tile, %x_chunk__tile : !pto.tile_buf, !pto.tile_buf) outs(%0 : !pto.tile_buf) + %tmp_tile = pto.alloc_tile addr = %c12352 : !pto.tile_buf + %1 = pto.alloc_tile addr = %c20544 : !pto.tile_buf + pto.trowsum ins(%0, %tmp_tile : !pto.tile_buf, !pto.tile_buf) outs(%1 : !pto.tile_buf) + %partial_sq__rm_a0_tmp_v0 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %partial_sq__rm_a1_tmp_v1 = pto.alloc_tile addr = %c20544 : !pto.tile_buf + %partial_sq__row_major_tmp_v2 = pto.alloc_tile addr = %c20608 : !pto.tile_buf + pto.tadd ins(%partial_sq__rm_a0_tmp_v0, %partial_sq__rm_a1_tmp_v1 : !pto.tile_buf, !pto.tile_buf) outs(%partial_sq__row_major_tmp_v2 : !pto.tile_buf) + %2 = pto.alloc_tile addr = %c20608 : !pto.tile_buf + %partial_sq__tile_mv = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.tmov ins(%2 : !pto.tile_buf) outs(%partial_sq__tile_mv : !pto.tile_buf) + } + %t__rm_a0_tmp_v3 = pto.alloc_tile addr = %c20608 : !pto.tile_buf + %t__row_major_tmp_v4 = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.tmuls ins(%t__rm_a0_tmp_v3, %cst_1 : !pto.tile_buf, f32) outs(%t__row_major_tmp_v4 : !pto.tile_buf) + %3 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %t__rm_a0_tmp_v5 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %t__row_major_tmp_v6 = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.tadds ins(%t__rm_a0_tmp_v5, %cst_2 : !pto.tile_buf, f32) outs(%t__row_major_tmp_v6 : !pto.tile_buf) + %4 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %inv_rms_tile__rm_a0_tmp_v7 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %inv_rms_tile__row_major_tmp_v8 = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.trsqrt ins(%inv_rms_tile__rm_a0_tmp_v7 : !pto.tile_buf) outs(%inv_rms_tile__row_major_tmp_v8 : !pto.tile_buf) + %inv_rms_tile__tile = pto.alloc_tile addr = %c0i : !pto.tile_buf + scf.for %11 = %c0 to %9 step %c1 { + %12 = arith.muli %11, %c128 : index + %5 = pto.alloc_tile addr = %c64 : !pto.tile_buf + %13 = pto.partition_view %hidden_states__ssa_v0_view, offsets = [%c0, %12], sizes = [%c16, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<16x128xbf16> + pto.tload ins(%13 : !pto.partition_tensor_view<16x128xbf16>) outs(%5 : !pto.tile_buf) + %6 = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tcvt ins(%5{rmode = #pto} : !pto.tile_buf) outs(%6 : !pto.tile_buf) + %gamma__tile = pto.alloc_tile addr = %c20672 : !pto.tile_buf + %input_rms_weight__ssa_v0_pview = pto.partition_view %input_rms_weight__ssa_v0_view, offsets = [%c0, %12], sizes = [%c1, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<1x128xf32> + pto.tload ins(%input_rms_weight__ssa_v0_pview : !pto.partition_tensor_view<1x128xf32>) outs(%gamma__tile : !pto.tile_buf) + %7 = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.trowexpandmul ins(%6, %inv_rms_tile__tile : !pto.tile_buf, !pto.tile_buf) outs(%7 : !pto.tile_buf) + %normed__tile = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tcolexpandmul ins(%7, %gamma__tile : !pto.tile_buf, !pto.tile_buf) outs(%normed__tile : !pto.tile_buf) + %8 = pto.alloc_tile addr = %c64 : !pto.tile_buf + pto.tcvt ins(%normed__tile{rmode = #pto} : !pto.tile_buf) outs(%8 : !pto.tile_buf) + %normed_tile__iter_v1_pview = pto.partition_view %normed_tile__ssa_v0_view, offsets = [%c0, %12], sizes = [%c16, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<16x128xbf16> + pto.tstore ins(%8 : !pto.tile_buf) outs(%normed_tile__iter_v1_pview : !pto.partition_tensor_view<16x128xbf16>) + } + return + } +} diff --git a/test/samples/Sync/rmsnorm_incore_0.pto b/test/samples/Sync/rmsnorm_incore_0.pto new file mode 100644 index 00000000..49d237db --- /dev/null +++ b/test/samples/Sync/rmsnorm_incore_0.pto @@ -0,0 +1,74 @@ +module attributes {pto.target_arch = "a5"} { + func.func @rmsnorm_incore_0(%arg0: !pto.ptr, %arg1: !pto.ptr, %arg2: !pto.ptr, %arg3: index) attributes {pto.kernel_kind = #pto.kernel_kind} { + %c0i = arith.constant 0 : i64 + %c64 = arith.constant 64 : i64 + %c4160 = arith.constant 4160 : i64 + %c12352 = arith.constant 12352 : i64 + %c20544 = arith.constant 20544 : i64 + %c20608 = arith.constant 20608 : i64 + %c20672 = arith.constant 20672 : i64 + %c16 = arith.constant 16 : index + %c5120 = arith.constant 5120 : index + %c1 = arith.constant 1 : index + %cst = arith.constant 0.000000e+00 : f32 + %c0 = arith.constant 0 : index + %c40 = arith.constant 40 : index + %c128 = arith.constant 128 : index + %cst_1 = arith.constant 1.953125e-04 : f32 + %cst_2 = arith.constant 1.000000e-06 : f32 + %hidden_states__ssa_v0_view = pto.make_tensor_view %arg0, shape = [%c16, %c5120], strides = [%c5120, %c1] {layout = #pto.layout}: !pto.tensor_view + %input_rms_weight__ssa_v0_view = pto.make_tensor_view %arg1, shape = [%c1, %c5120], strides = [%c5120, %c1] {layout = #pto.layout}: !pto.tensor_view + %normed_out__iter_v1_view = pto.make_tensor_view %arg2, shape = [%c16, %c5120], strides = [%c5120, %c1] {layout = #pto.layout}: !pto.tensor_view + %partial_sq_flat__tile = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.texpands ins(%cst : f32) outs(%partial_sq_flat__tile : !pto.tile_buf) + %partial_sq__tile = pto.alloc_tile addr = %c0i : !pto.tile_buf + scf.for %kb__idx_v0 = %c0 to %c40 step %c1 { + %8 = arith.muli %kb__idx_v0, %c128 : index + %t__tile = pto.alloc_tile addr = %c64 : !pto.tile_buf + %hidden_states__ssa_v0_pview = pto.partition_view %hidden_states__ssa_v0_view, offsets = [%c0, %8], sizes = [%c16, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<16x128xbf16> + pto.tload ins(%hidden_states__ssa_v0_pview : !pto.partition_tensor_view<16x128xbf16>) outs(%t__tile : !pto.tile_buf) + %x_chunk__tile = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tcvt ins(%t__tile{rmode = #pto} : !pto.tile_buf) outs(%x_chunk__tile : !pto.tile_buf) + %0 = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tmul ins(%x_chunk__tile, %x_chunk__tile : !pto.tile_buf, !pto.tile_buf) outs(%0 : !pto.tile_buf) + %tmp_tile = pto.alloc_tile addr = %c12352 : !pto.tile_buf + %1 = pto.alloc_tile addr = %c20544 : !pto.tile_buf + pto.trowsum ins(%0, %tmp_tile : !pto.tile_buf, !pto.tile_buf) outs(%1 : !pto.tile_buf) + %partial_sq__rm_a0_tmp_v0 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %partial_sq__rm_a1_tmp_v1 = pto.alloc_tile addr = %c20544 : !pto.tile_buf + %partial_sq__row_major_tmp_v2 = pto.alloc_tile addr = %c20608 : !pto.tile_buf + pto.tadd ins(%partial_sq__rm_a0_tmp_v0, %partial_sq__rm_a1_tmp_v1 : !pto.tile_buf, !pto.tile_buf) outs(%partial_sq__row_major_tmp_v2 : !pto.tile_buf) + %2 = pto.alloc_tile addr = %c20608 : !pto.tile_buf + %partial_sq__tile_mv = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.tmov ins(%2 : !pto.tile_buf) outs(%partial_sq__tile_mv : !pto.tile_buf) + } + %t__rm_a0_tmp_v3 = pto.alloc_tile addr = %c20608 : !pto.tile_buf + %t__row_major_tmp_v4 = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.tmuls ins(%t__rm_a0_tmp_v3, %cst_1 : !pto.tile_buf, f32) outs(%t__row_major_tmp_v4 : !pto.tile_buf) + %3 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %variance__rm_a0_tmp_v5 = pto.alloc_tile addr = %c0i : !pto.tile_buf + %variance__row_major_tmp_v6 = pto.alloc_tile addr = %c0i : !pto.tile_buf + pto.tadds ins(%variance__rm_a0_tmp_v5, %cst_2 : !pto.tile_buf, f32) outs(%variance__row_major_tmp_v6 : !pto.tile_buf) + %variance__tile = pto.alloc_tile addr = %c0i : !pto.tile_buf + scf.for %9 = %c0 to %c40 step %c1 { + %10 = arith.muli %9, %c128 : index + %4 = pto.alloc_tile addr = %c64 : !pto.tile_buf + %11 = pto.partition_view %hidden_states__ssa_v0_view, offsets = [%c0, %10], sizes = [%c16, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<16x128xbf16> + pto.tload ins(%11 : !pto.partition_tensor_view<16x128xbf16>) outs(%4 : !pto.tile_buf) + %5 = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tcvt ins(%4{rmode = #pto} : !pto.tile_buf) outs(%5 : !pto.tile_buf) + %gamma__tile = pto.alloc_tile addr = %c20672 : !pto.tile_buf + %input_rms_weight__ssa_v0_pview = pto.partition_view %input_rms_weight__ssa_v0_view, offsets = [%c0, %10], sizes = [%c1, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<1x128xf32> + pto.tload ins(%input_rms_weight__ssa_v0_pview : !pto.partition_tensor_view<1x128xf32>) outs(%gamma__tile : !pto.tile_buf) + %6 = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.trowexpandmul ins(%5, %variance__tile : !pto.tile_buf, !pto.tile_buf) outs(%6 : !pto.tile_buf) + %normed__tile = pto.alloc_tile addr = %c4160 : !pto.tile_buf + pto.tcolexpandmul ins(%6, %gamma__tile : !pto.tile_buf, !pto.tile_buf) outs(%normed__tile : !pto.tile_buf) + %7 = pto.alloc_tile addr = %c64 : !pto.tile_buf + pto.tcvt ins(%normed__tile{rmode = #pto} : !pto.tile_buf) outs(%7 : !pto.tile_buf) + %normed_out__iter_v3_pview = pto.partition_view %normed_out__iter_v1_view, offsets = [%c0, %10], sizes = [%c16, %c128] : !pto.tensor_view -> !pto.partition_tensor_view<16x128xbf16> + pto.tstore ins(%7 : !pto.tile_buf) outs(%normed_out__iter_v3_pview : !pto.partition_tensor_view<16x128xbf16>) + } + return + } +}