-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·80 lines (64 loc) · 2.56 KB
/
test.py
File metadata and controls
executable file
·80 lines (64 loc) · 2.56 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
77
78
79
80
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import sys
import pytest
from pathlib import Path
from iron.operators.gemv.op import AIEGEMV
from iron.operators.gemv.reference import generate_golden_reference
from iron.common.test_utils import run_test
def generate_test_params(extensive=False):
params = [
(128, 128, 1, 32, 128),
(2048, 8192, 1, 1, 2048),
(8192, 2048, 1, 4, 1024),
(2048, 8192, 2, 1, 1024),
(8192, 2048, 2, 4, 1024),
(2048, 8192, 4, 1, 512),
(8192, 2048, 4, 4, 1024),
(2048, 8192, 8, 1, 256),
(8192, 2048, 8, 4, 1024),
]
names = [
f"matrix_vector_mul_{M}x{K}_{tile_size_input}tsi_{tile_size_output}tso_{num_aie_columns}col"
for M, K, num_aie_columns, tile_size_input, tile_size_output in params
]
return params, names
regular_params, regular_names = generate_test_params(extensive=False)
extensive_params, extensive_names = generate_test_params(extensive=True)
# Combine params with marks - extensive params get pytest.mark.extensive
all_params = [
pytest.param(*params, id=name)
for params, name in zip(regular_params, regular_names)
] + [
pytest.param(*params, marks=pytest.mark.extensive, id=name)
for params, name in zip(extensive_params, extensive_names)
]
@pytest.mark.metrics(
Latency=r"Latency \(us\): (?P<value>[\d\.]+)",
Bandwidth=r"Effective Bandwidth: (?P<value>[\d\.e\+-]+) GB/s",
Throughput=r"Throughput: (?P<value>[\d\.e\+-]+) GFLOP/s",
)
@pytest.mark.parametrize(
"M,K,num_aie_columns,tile_size_input,tile_size_output", all_params
)
def test_gemv(M, K, num_aie_columns, tile_size_input, tile_size_output, aie_context):
golden_ref = generate_golden_reference(M=M, K=K)
operator = AIEGEMV(
M=M,
K=K,
num_aie_columns=num_aie_columns,
tile_size_input=tile_size_input,
tile_size_output=tile_size_output,
context=aie_context,
)
input_buffers = {"matrix": golden_ref["A"].flatten(), "vector": golden_ref["B"]}
output_buffers = {"output": golden_ref["C"]}
errors, latency_us, bandwidth_gbps = run_test(
operator, input_buffers, output_buffers, rel_tol=0.04, abs_tol=1e-3
)
print(f"\nLatency: {latency_us:.1f} us")
gflops = (2.0 * M * K) / (latency_us * 1e-6) / 1e9
print(f"Throughput: {gflops:.6e} GFLOP/s")
print(f"Effective Bandwidth: {bandwidth_gbps:.6e} GB/s\n")
assert not errors, f"Test failed with errors: {errors}"