-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add dense matmul benchmark #256
Conversation
f1669ed
to
9d1610d
Compare
9d1610d
to
00e9e5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's do this!
We can probably refactor a bunch of things out of here though.
Furthermore, can you refactor everything that says tiled_matmul to not say it?
This is not a tiled matrix multiplication after all ;)
from util.snax_benchmark import SNAXBenchmark | ||
|
||
|
||
def create_tiled_matrix_multiply(k, m, n): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a tiled_matrix_multiply anymore :)
return module | ||
|
||
|
||
def write_module_to_file(module, file): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to move this to the tools folder at some point
def create_test_data(n, m, k): | ||
print(f"Creating test data with n={n}, m={m}, k={k}") | ||
# Reset random seed for reproducible behavior | ||
|
||
np.random.seed(0) | ||
|
||
A_size = [n, k] | ||
B_size = [k, m] | ||
|
||
# C = A.B | ||
low_bound = -128 | ||
high_bound = 127 | ||
|
||
A = np.random.randint(low_bound, high_bound, size=A_size, dtype=np.dtype("int8")) | ||
B = np.random.randint(low_bound, high_bound, size=B_size, dtype=np.dtype("int8")) | ||
|
||
# Make sure the product is possible! | ||
assert A.shape[1] == B.shape[0] | ||
C_golden = np.matmul(A.astype(np.dtype("int32")), B.astype(np.dtype("int32"))) | ||
C = np.zeros(C_golden.shape, np.dtype("int32")) | ||
|
||
# Perform layout transformations before writing to memory | ||
|
||
# only thing necessary: transform B from row-major to column-major | ||
B_new_layout = np.transpose(B) | ||
|
||
# C are just all zeros, so layout not important | ||
sizes = { | ||
"N_size": A.shape[0], | ||
"K_size": A.shape[1], | ||
"M_size": B.shape[1], | ||
} | ||
variables = { | ||
"A": A, | ||
"B": B_new_layout, | ||
"C_golden": C_golden, | ||
"C": C, | ||
} | ||
|
||
create_header("data.h", sizes, variables) | ||
create_data("data.c", variables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably move this to a more common folder :)
} | ||
} | ||
|
||
// insert mcycle to show fault in trace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a quick way to check if an operation succeeds by looking at the trace. if there are 3 mcycles, it was successful. if there are 4, an error has occured
This adds a benchmark that measures peak performance of the gemm accelerator measuring from the time it is launched until it is finished.
It is configured to run the benchmark on every push to main, and uploads the output report to github artifacts, sneek peak available here: https://github.com/KULeuven-MICAS/snax-mlir/actions/runs/11012799975