forked from Xilinx/mlir-aie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
113 lines (98 loc) · 2.72 KB
/
test.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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 Advanced Micro Devices, Inc.
import argparse
import pyxrt as xrt
# Add default args to standard parser object
def create_default_argparser():
p = argparse.ArgumentParser()
p.add_argument(
"-x", "--xclbin", required=True, dest="xclbin", help="the input xclbin path"
)
p.add_argument(
"-k",
"--kernel",
required=True,
dest="kernel",
default="MLIR_AIE",
help="the kernel name in the XCLBIN (for instance MLIR_AIE)",
)
p.add_argument(
"-v", "--verbosity", default=0, type=int, help="the verbosity of the output"
)
p.add_argument(
"-i",
"--instr",
dest="instr",
default="instr.txt",
help="path of file containing userspace instructions sent to the NPU",
)
p.add_argument(
"--verify",
dest="verify",
default=True,
help="whether to verify the AIE computed output",
)
p.add_argument(
"--iters",
dest="iters",
default=1,
type=int,
help="number of benchmark iterations",
)
p.add_argument(
"--warmup",
dest="warmup_iters",
default=0,
type=int,
help="number of warmup iterations",
)
p.add_argument(
"-t",
"--trace_sz",
dest="trace_size",
default=0,
type=int,
help="trace size in bytes",
)
p.add_argument(
"--trace_file",
dest="trace_file",
default="trace.txt",
help="where to store trace output",
)
return p
# options
def parse_args(args):
p = create_default_argparser()
return p.parse_args(args)
# def write_out_trace(trace_buffer, trace_size, trace_file):
# try:
# with open(trace_file, "wt") as f:
# f.write(trace_buffer)
# except Exception as e:
# print(e)
# sys.exit(1)
def init_xrt_load_kernel(opts):
# Get a device handle
device = xrt.device(0)
# Load the xclbin
xclbin = xrt.xclbin(opts.xclbin)
# Load the kernel
kernels = xclbin.get_kernels()
try:
xkernel = [k for k in kernels if opts.kernel in k.get_name()][0]
except:
print(f"Kernel '{opts.kernel}' not found in '{opts.xclbin}'")
exit(-1)
# Register xclbin
device.register_xclbin(xclbin)
# Get a hardware context
context = xrt.hw_context(device, xclbin.get_uuid())
# get a kernel handle
kernel = xrt.kernel(context, xkernel.get_name())
return (device, kernel)