forked from Xilinx/mlir-aie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
76 lines (62 loc) · 2.42 KB
/
test.py
File metadata and controls
76 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# test.py -*- Python -*-
#
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# (c) Copyright 2024-2026 Advanced Micro Devices, Inc. or its affiliates
import numpy as np
from pathlib import Path
import sys
import aie.iron as iron
import aie.utils
import aie.utils.test as test_utils
from aie.utils.npukernel import NPUKernel
def main(opts):
# ------------------------------------------------------------
# Configure this to match your design's buffer size and type
# ------------------------------------------------------------
# Initialize data buffers and reference for verification
ref_buffer = np.arange(1, 4096 + 1, dtype=np.int32)
in_buffer = iron.tensor(ref_buffer, dtype=np.int32)
scale_factor = 3
in_factor = iron.tensor([scale_factor], dtype=np.int32)
out = iron.zeros(4096, dtype=np.int32)
ref_buffer = ref_buffer * scale_factor
# ----------------------------------------------------
# Prepare buffers and load compiled artifacts onto the device
# ----------------------------------------------------
npu_kernel = NPUKernel(opts.xclbin, opts.instr)
kernel_handle = aie.utils.DefaultNPURuntime.load(npu_kernel)
# ------------------------------------------------------
# Initialize run configs
# ------------------------------------------------------
errors = 0
# ------------------------------------------------------
# Main run loop
# ------------------------------------------------------
# Run kernel
if opts.verbosity >= 1:
print("Running Kernel.")
npu_time = aie.utils.DefaultNPURuntime.run(
kernel_handle, [in_buffer, in_factor, out]
)
if opts.verify:
if opts.verbosity >= 1:
print("Verifying results ...")
e = np.equal(out, ref_buffer)
errors = errors + np.size(e) - np.count_nonzero(e)
# ------------------------------------------------------
# Print verification and timing results
# ------------------------------------------------------
if not errors:
print("\nPASS!\n")
sys.exit(0)
else:
print("\nError count: ", errors)
print("\nFailed.\n")
sys.exit(1)
if __name__ == "__main__":
p = test_utils.create_default_argparser()
opts = p.parse_args(sys.argv[1:])
main(opts)