|
| 1 | +//===- cpp_link_with_func_level.mlir ---------------------------*- MLIR -*-===// |
| 2 | +// |
| 3 | +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +// Copyright (C) 2026, Advanced Micro Devices, Inc. |
| 8 | +// |
| 9 | +//===----------------------------------------------------------------------===// |
| 10 | + |
| 11 | +// Canonical new style: link_with is on func.func, not on aie.core. |
| 12 | +// Verify that AIEAssignCoreLinkFiles populates link_files on the core and |
| 13 | +// that the ldscript/BCF emitters produce the correct entries. |
| 14 | + |
| 15 | +// RUN: aie-opt --verify-diagnostics --aie-assign-core-link-files %s | FileCheck %s --check-prefix=OPT |
| 16 | +// RUN: aie-opt --verify-diagnostics --aie-assign-core-link-files %s | aie-translate --aie-generate-ldscript --tilecol=0 --tilerow=2 | FileCheck %s --check-prefix=LDSCRIPT |
| 17 | +// RUN: aie-opt --verify-diagnostics --aie-assign-core-link-files %s | aie-translate --aie-generate-bcf --tilecol=0 --tilerow=2 | FileCheck %s --check-prefix=BCF |
| 18 | + |
| 19 | +// OPT: link_files = ["f.o"] |
| 20 | + |
| 21 | +// LDSCRIPT: INPUT(f.o) |
| 22 | + |
| 23 | +// BCF: _include _file f.o |
| 24 | + |
| 25 | +module { |
| 26 | + aie.device(npu1_1col) { |
| 27 | + %tile_0_0 = aie.tile(0, 0) |
| 28 | + %tile_0_2 = aie.tile(0, 2) |
| 29 | + |
| 30 | + aie.objectfifo @of_in(%tile_0_0, {%tile_0_2}, 2 : i32) : !aie.objectfifo<memref<16xi32>> |
| 31 | + aie.objectfifo @of_out(%tile_0_2, {%tile_0_0}, 2 : i32) : !aie.objectfifo<memref<16xi32>> |
| 32 | + |
| 33 | + func.func private @f(memref<16xi32>, memref<16xi32>) attributes {link_with = "f.o"} |
| 34 | + |
| 35 | + %core_0_2 = aie.core(%tile_0_2) { |
| 36 | + %subview_in = aie.objectfifo.acquire @of_in(Consume, 1) : !aie.objectfifosubview<memref<16xi32>> |
| 37 | + %elem_in = aie.objectfifo.subview.access %subview_in[0] : !aie.objectfifosubview<memref<16xi32>> -> memref<16xi32> |
| 38 | + |
| 39 | + %subview_out = aie.objectfifo.acquire @of_out(Produce, 1) : !aie.objectfifosubview<memref<16xi32>> |
| 40 | + %elem_out = aie.objectfifo.subview.access %subview_out[0] : !aie.objectfifosubview<memref<16xi32>> -> memref<16xi32> |
| 41 | + |
| 42 | + func.call @f(%elem_in, %elem_out) : (memref<16xi32>, memref<16xi32>) -> () |
| 43 | + |
| 44 | + aie.objectfifo.release @of_in(Consume, 1) |
| 45 | + aie.objectfifo.release @of_out(Produce, 1) |
| 46 | + aie.end |
| 47 | + } |
| 48 | + |
| 49 | + aie.runtime_sequence(%in : memref<16xi32>, %out : memref<16xi32>) { |
| 50 | + %c0 = arith.constant 0 : i64 |
| 51 | + %c1 = arith.constant 1 : i64 |
| 52 | + %c16 = arith.constant 16 : i64 |
| 53 | + aiex.npu.dma_memcpy_nd(%out[%c0,%c0,%c0,%c0][%c1,%c1,%c1,%c16][%c0,%c0,%c0,%c1]) {metadata = @of_out, id = 1 : i64} : memref<16xi32> |
| 54 | + aiex.npu.dma_memcpy_nd(%in[%c0,%c0,%c0,%c0][%c1,%c1,%c1,%c16][%c0,%c0,%c0,%c1]) {metadata = @of_in, id = 0 : i64, issue_token = true} : memref<16xi32> |
| 55 | + aiex.npu.dma_wait {symbol = @of_out} |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments