|
| 1 | +// |
| 2 | +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +// See https://llvm.org/LICENSE.txt for license information. |
| 4 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | +// |
| 6 | +// (c) Copyright 2024 AMD Inc. |
| 7 | + |
| 8 | +// RUN: aie-opt --aie-dma-tasks-to-npu %s | FileCheck %s |
| 9 | + |
| 10 | +// This test verifies that a dma_bd with a transfer length that would overflow a |
| 11 | +// 32-bit integer when converted to bytes is handled correctly. Without the fix, |
| 12 | +// `len * element_size_bytes` would overflow to 0 or a wrong value, causing a |
| 13 | +// false "Buffer descriptor length does not match" error. |
| 14 | +// |
| 15 | +// memref<536870912xi64>: 536870912 elements * 8 bytes = 4294967296 bytes. |
| 16 | +// In 32-bit words: 4294967296 / 4 = 1073741824 (= 0x40000000). |
| 17 | +// Without overflow fix, the byte count truncates to 0, so len_addr_granularity |
| 18 | +// would be 0 instead of 1073741824, triggering a spurious validation error. |
| 19 | + |
| 20 | +// CHECK-LABEL: aie.runtime_sequence |
| 21 | +// CHECK: aiex.npu.writebd |
| 22 | +// CHECK-SAME: buffer_length = 1073741824 : i32 |
| 23 | + |
| 24 | +module { |
| 25 | + aie.device(npu1) { |
| 26 | + %tile_0_0 = aie.tile(0, 0) |
| 27 | + |
| 28 | + aie.runtime_sequence(%arg0: memref<536870912xi64>) { |
| 29 | + %t1 = aiex.dma_configure_task(%tile_0_0, MM2S, 0) { |
| 30 | + aie.dma_bd(%arg0 : memref<536870912xi64>, 0, 536870912, |
| 31 | + [<size=1, stride=1>, <size=1, stride=1>, <size=536870912, stride=1>]) {bd_id = 0 : i32} |
| 32 | + aie.end |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | +} |
0 commit comments