Skip to content

Commit 9c3a745

Browse files
hunhoffegithub-actions[bot]Copilotandrej
authored
IRON host runtime abstraction (#2737)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]> Co-authored-by: André Rösti <[email protected]>
1 parent 19b473b commit 9c3a745

File tree

127 files changed

+4435
-4321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+4435
-4321
lines changed

.github/workflows/buildAndTestRyzenAI.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
matrix:
6262
runner_type: [ amd7940hs, amdhx370 ]
6363
env:
64-
IRON_CACHE_HOME: ${{ github.workspace }}/iron-cache-${{ matrix.runner_type }}-${{ github.run_id }}
64+
NPU_CACHE_HOME: ${{ github.workspace }}/iron-cache-${{ matrix.runner_type }}-${{ github.run_id }}
6565
PIP_CACHE_DIR: ${{ github.workspace }}/.pip-cache-${{ matrix.runner_type }}-${{ github.run_id }}
6666
steps:
6767
- uses: actions/checkout@v4
@@ -130,18 +130,21 @@ jobs:
130130
$CMAKE_ARGS
131131
132132
# Create runner-specific cache directory
133-
rm -rf $IRON_CACHE_HOME
134-
mkdir $IRON_CACHE_HOME
133+
rm -rf $NPU_CACHE_HOME
134+
mkdir $NPU_CACHE_HOME
135+
136+
# Set number of contexts to maintain in cache per process
137+
export XRT_CONTEXT_CACHE_SIZE=3
135138
136139
ninja install
137140
ninja check-aie
138141
ninja check-aie-concurrency
139142
popd
140143
141-
- name: Cleanup IRON_CACHE_HOME
144+
- name: Cleanup NPU_CACHE_HOME
142145
if: always()
143146
run: |
144-
rm -rf $IRON_CACHE_HOME
147+
rm -rf $NPU_CACHE_HOME
145148
rm -rf $PIP_CACHE_DIR
146149
147150
build-quick-setup:
@@ -152,7 +155,7 @@ jobs:
152155
matrix:
153156
runner_type: [ amd7940hs, amdhx370 ]
154157
env:
155-
IRON_CACHE_HOME: ${{ github.workspace }}/iron-cache-${{ matrix.runner_type }}-${{ github.run_id }}
158+
NPU_CACHE_HOME: ${{ github.workspace }}/iron-cache-${{ matrix.runner_type }}-${{ github.run_id }}
156159
PIP_CACHE_DIR: ${{ github.workspace }}/.pip-cache-${{ matrix.runner_type }}-${{ github.run_id }}
157160
steps:
158161
- uses: actions/checkout@v4
@@ -200,17 +203,20 @@ jobs:
200203
LIT_OPTS="-j12 $LIT_OPTS"
201204
fi
202205
206+
# Set number of contexts to maintain in cache per process
207+
export XRT_CONTEXT_CACHE_SIZE=3
208+
203209
# Create runner-specific cache directory
204-
rm -rf $IRON_CACHE_HOME
205-
mkdir $IRON_CACHE_HOME
210+
rm -rf $NPU_CACHE_HOME
211+
mkdir $NPU_CACHE_HOME
206212
207213
ninja install
208214
ninja check-reference-designs
209215
ninja check-programming-guide
210216
popd
211217
212-
- name: Cleanup IRON_CACHE_HOME
218+
- name: Cleanup NPU_CACHE_HOME
213219
if: always()
214220
run: |
215-
rm -rf $IRON_CACHE_HOME
221+
rm -rf $NPU_CACHE_HOME
216222
rm -rf $PIP_CACHE_DIR

.github/workflows/buildAndTestVitis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
matrix:
6262
runner_type: [ ubuntu-vitis ]
6363
env:
64-
IRON_CACHE_HOME: ${{ github.workspace }}/iron-cache-${{ matrix.runner_type }}-${{ github.run_id }}
64+
NPU_CACHE_HOME: ${{ github.workspace }}/iron-cache-${{ matrix.runner_type }}-${{ github.run_id }}
6565
steps:
6666
- uses: actions/checkout@v4
6767
with:
@@ -125,13 +125,13 @@ jobs:
125125
$CMAKE_ARGS
126126
127127
# Create runner-specific cache directory
128-
rm -rf $IRON_CACHE_HOME
129-
mkdir $IRON_CACHE_HOME
128+
rm -rf $NPU_CACHE_HOME
129+
mkdir $NPU_CACHE_HOME
130130
131131
ninja install
132132
ninja check-aie
133133
popd
134134
135-
- name: Cleanup IRON_CACHE_HOME
135+
- name: Cleanup NPU_CACHE_HOME
136136
if: always()
137-
run: rm -rf $IRON_CACHE_HOME
137+
run: rm -rf $NPU_CACHE_HOME

programming_examples/basic/matrix_multiplication/makefile-common

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#
7-
# Copyright (C) 2025, Advanced Micro Devices, Inc.
7+
# Copyright (C) 2025-2026, Advanced Micro Devices, Inc.
88
#
99
##===----------------------------------------------------------------------===##
1010

@@ -196,13 +196,13 @@ run: ${targetname}.exe ${xclbin_target}
196196
trace: ${targetname}.exe ${trace_xclbin_target} ${insts_target}
197197
export XRT_HACK_UNSECURE_LOADING_XCLBIN=1 && \
198198
${powershell} ./$< -x ${trace_xclbin_target} -i ${insts_target} -k MLIR_AIE -M $M -K $K -N $N ${runargs} -t ${trace_size}
199-
${srcdir}/../../../../python/utils/parse_trace.py --input trace.txt --mlir ${trace_mlir_target} --output trace_mm.json
199+
${srcdir}/../../../../python/utils/trace/parse.py --input trace.txt --mlir ${trace_mlir_target} --output trace_mm.json
200200

201201
# ${powershell} ./$< -x ${trace_xclbin_target} -i ${insts_target} -k MLIR_AIE -M $M -K $K -N $N -v 1 --warmup 0 --iters 1 -t ${trace_size}
202202

203203
.PHONY: parse_trace
204204
parse_trace:
205-
${srcdir}/../../../../python/utils/parse_trace.py --input trace.txt --mlir ${trace_mlir_target} --output trace_mm.json
205+
${srcdir}/../../../../python/utils/trace/parse.py --input trace.txt --mlir ${trace_mlir_target} --output trace_mm.json
206206

207207
.PHONY: clean
208208
clean: clean_trace

programming_examples/basic/matrix_multiplication/single_core/single_core.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See https://llvm.org/LICENSE.txt for license information.
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
#
6-
# (c) Copyright 2025 AMD Inc.
6+
# (c) Copyright 2025-2026 AMD Inc.
77
import argparse
88
import numpy as np
99
import sys
@@ -12,7 +12,6 @@
1212
from aie.dialects.aie import *
1313
from aie.dialects.aiex import *
1414
import aie.utils.trace as trace_utils
15-
from aie.utils.trace import PortEvent
1615
from aie.iron.controlflow import range_
1716
from aie.iron.dtype import str_to_dtype
1817

@@ -280,28 +279,28 @@ def sequence(A, B, C):
280279
trace_size=trace_size,
281280
coretile_events=[
282281
# captures input A (PORT_RUNNING_0, at port number 1, master for inputs)
283-
trace_utils.PortEvent(
284-
trace_utils.CoreEvent.PORT_RUNNING_0,
282+
trace_utils.events.PortEvent(
283+
trace_utils.events.CoreEvent.PORT_RUNNING_0,
285284
port_number=1,
286285
master=True,
287286
),
288287
# captures input B (PORT_RUNNING_1, at port number 2, master for inputs)
289-
trace_utils.PortEvent(
290-
trace_utils.CoreEvent.PORT_RUNNING_1,
288+
trace_utils.events.PortEvent(
289+
trace_utils.events.CoreEvent.PORT_RUNNING_1,
291290
port_number=2,
292291
master=True,
293292
),
294293
# captures output C (PORT_RUNNING_2, at port number 1, slave for outputs)
295-
trace_utils.PortEvent(
296-
trace_utils.CoreEvent.PORT_RUNNING_2,
294+
trace_utils.events.PortEvent(
295+
trace_utils.events.CoreEvent.PORT_RUNNING_2,
297296
port_number=1,
298297
master=False,
299298
),
300-
trace_utils.CoreEvent.INSTR_EVENT_0,
301-
trace_utils.CoreEvent.INSTR_EVENT_1,
302-
trace_utils.CoreEvent.MEMORY_STALL,
303-
trace_utils.CoreEvent.LOCK_STALL,
304-
trace_utils.CoreEvent.INSTR_VECTOR,
299+
trace_utils.events.CoreEvent.INSTR_EVENT_0,
300+
trace_utils.events.CoreEvent.INSTR_EVENT_1,
301+
trace_utils.events.CoreEvent.MEMORY_STALL,
302+
trace_utils.events.CoreEvent.LOCK_STALL,
303+
trace_utils.events.CoreEvent.INSTR_VECTOR,
305304
],
306305
)
307306

programming_examples/basic/packet_switch/test.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7-
// Copyright (C) 2025, Advanced Micro Devices, Inc.
7+
// Copyright (C) 2025-2026, Advanced Micro Devices, Inc.
88
//
99
//===----------------------------------------------------------------------===//
1010

@@ -113,10 +113,13 @@ int main(int argc, const char *argv[]) {
113113
ref = srcVecA[i] + 2; // ref for the second input packet
114114
}
115115
if (*(bufOut + i) != ref) {
116-
if (errors < 10) {
116+
if (errors < 100) {
117117
std::cout << "Error in output " << i << "; Input: " << srcVecA[i]
118118
<< "; Output: " << *(bufOut + i) << " != reference:" << ref
119119
<< std::endl;
120+
} else if (errors == 100) {
121+
std::cout << "..." << std::endl;
122+
std::cout << "[Errors truncated]" << std::endl;
120123
}
121124
errors++;
122125
}

programming_examples/basic/passthrough_kernel/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#
7-
# Copyright (C) 2024, Advanced Micro Devices, Inc.
7+
# Copyright (C) 2024-2026, Advanced Micro Devices, Inc.
88
#
99
##===----------------------------------------------------------------------===##
1010

@@ -82,13 +82,13 @@ run_py: build/final_${data_size}.xclbin build/insts_${data_size}.bin
8282

8383
trace: ${targetname}_${data_size}.exe build/final_trace_${data_size}.xclbin build/insts_${data_size}.bin
8484
${powershell} ./$< -x build/final_trace_${data_size}.xclbin -i build/insts_${data_size}.bin -k MLIR_AIE -t ${trace_size}
85-
${srcdir}/../../../python/utils/parse_trace.py --input trace.txt --mlir build/aie2_trace_lineBased_8b_${data_size}.mlir --output trace_passthrough_kernel.json
86-
${srcdir}/../../../python/utils/get_trace_summary.py --input trace_passthrough_kernel.json
85+
${srcdir}/../../../python/utils/trace/parse.py --input trace.txt --mlir build/aie2_trace_lineBased_8b_${data_size}.mlir --output trace_passthrough_kernel.json
86+
${srcdir}/../../../python/utils/trace/get_trace_summary.py --input trace_passthrough_kernel.json
8787

8888
trace_py: build/final_trace_${data_size}.xclbin build/insts_${data_size}.bin
8989
${powershell} python3 ${srcdir}/test.py -x build/final_trace_${data_size}.xclbin -i build/insts_${data_size}.bin -k MLIR_AIE -t ${trace_size} -i1s ${in1_size} -os ${out_size}
90-
${srcdir}/../../../python/utils/parse_trace.py --input trace.txt --mlir build/aie2_trace_lineBased_8b_${data_size}.mlir --output trace_${targetname}.json
91-
${srcdir}/../../../python/utils/get_trace_summary.py --input trace_${targetname}.json
90+
${srcdir}/../../../python/utils/trace/parse.py --input trace.txt --mlir build/aie2_trace_lineBased_8b_${data_size}.mlir --output trace_${targetname}.json
91+
${srcdir}/../../../python/utils/trace/get_trace_summary.py --input trace_${targetname}.json
9292

9393
clean_trace:
9494
rm -rf tmpTrace trace.txt parse*json trace*json

programming_examples/basic/passthrough_kernel/run_strix_makefile.lit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// (c) Copyright 2024 Advanced Micro Devices, Inc.
1+
// (c) Copyright 2024-2026 Advanced Micro Devices, Inc.
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33
//
44
// REQUIRES: ryzen_ai_npu2, peano
@@ -9,4 +9,4 @@
99
// RUN: make -f %S/Makefile devicename=npu2
1010
// RUN: %run_on_npu2% make -f %S/Makefile run devicename=npu2
1111
// RUN: make -f %S/Makefile clean
12-
// RUN: env CHESS=false %run_on_npu2% make -f %S/Makefile trace devicename=npu2
12+
// RUN: env CHESS=false %run_on_npu2% make -f %S/Makefile trace devicename=npu2

programming_examples/basic/passthrough_kernel/test.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#
7-
# (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates
7+
# (c) Copyright 2024-2026 Advanced Micro Devices, Inc. or its affiliates
88
import numpy as np
99
import sys
10-
import aie.utils.xrt as xrt_utils
1110
import aie.utils.test as test_utils
11+
import aie.iron as iron
12+
from aie.utils import DefaultNPURuntime
1213

1314

1415
def main(opts):
1516
in1_size = int(opts.in1_size) # in bytes
16-
in2_size = int(opts.in2_size) # in bytes
1717
out_size = int(opts.out_size) # in bytes
1818

1919
# --------------------------------------------------------------------------
@@ -36,28 +36,23 @@ def main(opts):
3636
assert out_size == in1_size
3737

3838
# Initialize data
39-
in1_data = np.arange(0, in1_volume, dtype=in1_dtype)
40-
out_data = np.zeros([out_volume], dtype=out_dtype)
41-
42-
# Define reference data
43-
ref = in1_data
39+
ref = np.arange(0, in1_volume, dtype=in1_dtype)
40+
in1 = iron.tensor(ref, dtype=in1_dtype)
41+
out = iron.zeros([out_volume], dtype=out_dtype)
4442

4543
# --------------------------------------------------------------------------
4644

4745
print("Running...\n")
48-
res = xrt_utils.setup_and_run_aie(
49-
in1_dtype,
50-
None,
51-
out_dtype,
52-
in1_data,
53-
None,
54-
out_data,
55-
in1_volume,
56-
None,
57-
out_volume,
58-
ref,
59-
opts,
46+
npu_opts = test_utils.create_npu_kernel(opts)
47+
res = DefaultNPURuntime.run_test(
48+
npu_opts.npu_kernel,
49+
[in1, out],
50+
{1: ref},
51+
verify=npu_opts.verify,
52+
verbosity=npu_opts.verbosity,
6053
)
54+
if res == 0:
55+
print("\nPASS!\n")
6156
sys.exit(res)
6257

6358

programming_examples/basic/passthrough_pykernel/passthrough_pykernel.ipynb

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"from aie.helpers.dialects.func import func\n",
2525
"from aie.iron.controlflow import range_\n",
2626
"\n",
27-
"from aie.utils.xrt import setup_aie, execute as execute_on_aie\n",
27+
"from aie.utils import NPUKernel, DefaultNPURuntime, get_current_device\n",
28+
"import aie.iron as iron\n",
29+
"from aie.iron.device import NPU2\n",
2830
"import aie.utils.test as test_utils"
2931
]
3032
},
@@ -69,7 +71,11 @@
6971
" N = vector_size\n",
7072
" lineWidthInBytes = N // 4 # chop input in 4 sub-tensors\n",
7173
"\n",
72-
" @device(AIEDevice.npu1_1col)\n",
74+
" d = get_current_device()\n",
75+
" if d is None:\n",
76+
" raise RuntimeError(\"Could not determine current device\")\n",
77+
"\n",
78+
" @device(d.resolve())\n",
7379
" def device_body():\n",
7480
" # define types\n",
7581
" line_ty = np.ndarray[(lineWidthInBytes,), np.dtype[np.uint8]]\n",
@@ -106,20 +112,15 @@
106112
"\n",
107113
" @runtime_sequence(vector_ty, vector_ty, vector_ty)\n",
108114
" def sequence(inTensor, outTensor, notUsed):\n",
109-
" npu_dma_memcpy_nd(\n",
110-
" metadata=of_in,\n",
111-
" bd_id=0,\n",
112-
" mem=inTensor,\n",
113-
" sizes=[1, 1, 1, N],\n",
114-
" issue_token=True,\n",
115+
" in_task = shim_dma_single_bd_task(\n",
116+
" of_in, inTensor, sizes=[1, 1, 1, N], issue_token=True\n",
115117
" )\n",
116-
" npu_dma_memcpy_nd(\n",
117-
" metadata=of_out,\n",
118-
" bd_id=1,\n",
119-
" mem=outTensor,\n",
120-
" sizes=[1, 1, 1, N],\n",
118+
" out_task = shim_dma_single_bd_task(\n",
119+
" of_out, outTensor, sizes=[1, 1, 1, N], issue_token=True\n",
121120
" )\n",
122-
" dma_wait(of_in, of_out)"
121+
"\n",
122+
" dma_start_task(in_task, out_task)\n",
123+
" dma_await_task(in_task, out_task)"
123124
]
124125
},
125126
{
@@ -181,19 +182,22 @@
181182
"source": [
182183
"dtype = np.uint8\n",
183184
"\n",
184-
"app = setup_aie(\n",
185+
"npu_kernel = NPUKernel(\n",
185186
" \"notebook_build/notebook.xclbin\",\n",
186187
" \"notebook_build/notebook_insts.bin\",\n",
187-
" VECTOR_SIZE,\n",
188-
" dtype,\n",
189-
" None,\n",
190-
" None,\n",
191-
" VECTOR_SIZE,\n",
192-
" dtype,\n",
188+
" kernel_name=\"MLIR_AIE\",\n",
193189
")\n",
190+
"kernel_handle = DefaultNPURuntime.load(npu_kernel)\n",
191+
"\n",
194192
"input = np.arange(1, VECTOR_SIZE + 1, dtype=dtype)\n",
193+
"in_tensor = iron.tensor(input, dtype=dtype)\n",
194+
"out_tensor = iron.zeros(VECTOR_SIZE, dtype=dtype)\n",
195+
"\n",
196+
"buffers = [in_tensor, out_tensor]\n",
197+
"\n",
195198
"print(\"Running...\")\n",
196-
"aie_output = execute_on_aie(app, input)\n",
199+
"DefaultNPURuntime.run(kernel_handle, buffers)\n",
200+
"aie_output = out_tensor.numpy()\n",
197201
"\n",
198202
"# Copy output results and verify they are correct\n",
199203
"errors = 0\n",

0 commit comments

Comments
 (0)