|
| 1 | +# Copyright (C) 2026 Advanced Micro Devices, Inc. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +# RUN: %python %s | FileCheck %s |
| 5 | + |
| 6 | +"""Test that Bd.packet emits a distinct aie.dma_bd_packet op BEFORE the |
| 7 | +aie.dma_bd, rather than a `packet` attribute on the dma_bd. The CDO/xclbin |
| 8 | +backends (AIERT, AIETargetXAIEV2) read the packet header only from the |
| 9 | +dma_bd_packet op, so the header must be emitted as that op to reach hardware.""" |
| 10 | + |
| 11 | +import numpy as np |
| 12 | + |
| 13 | +from aie.iron import Bd, Buffer, DmaChannel, Program, Runtime, TileDma |
| 14 | +from aie.iron.device import NPU2Col1, Tile |
| 15 | +from aie.dialects._aie_enum_gen import AIETileType, DMAChannelDir |
| 16 | + |
| 17 | + |
| 18 | +def emit_packet_bd(): |
| 19 | + n = 256 |
| 20 | + vector_ty = np.ndarray[(n,), np.dtype[np.int32]] |
| 21 | + |
| 22 | + compute_tile = Tile(col=0, row=2, tile_type=AIETileType.CoreTile) |
| 23 | + buf = Buffer(tile=compute_tile, type=vector_ty, name="pkt_buf") |
| 24 | + |
| 25 | + tile_dma = TileDma( |
| 26 | + tile=compute_tile, |
| 27 | + channels=[ |
| 28 | + DmaChannel( |
| 29 | + direction=DMAChannelDir.MM2S, |
| 30 | + channel=0, |
| 31 | + bds=[ |
| 32 | + Bd( |
| 33 | + buffer=buf, |
| 34 | + offset=0, |
| 35 | + length=n, |
| 36 | + packet=(0, 5), |
| 37 | + next="self", |
| 38 | + ), |
| 39 | + ], |
| 40 | + ), |
| 41 | + ], |
| 42 | + ) |
| 43 | + |
| 44 | + rt = Runtime() |
| 45 | + rt.add_tile_dma(tile_dma) |
| 46 | + with rt.sequence(vector_ty) as _: |
| 47 | + pass |
| 48 | + |
| 49 | + return Program(NPU2Col1(), rt).resolve_program() |
| 50 | + |
| 51 | + |
| 52 | +# The packet header is a distinct op emitted immediately before the dma_bd, |
| 53 | +# and the dma_bd itself carries no packet attribute. |
| 54 | +# CHECK: aie.dma_bd_packet(0, 5) |
| 55 | +# CHECK-NEXT: aie.dma_bd({{.*}} : memref<256xi32>, 0, 256) |
| 56 | +# CHECK-NOT: aie.dma_bd({{.*}}packet |
| 57 | +print(emit_packet_bd()) |
0 commit comments