Skip to content
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

Merged
merged 10 commits into from
Sep 25, 2024
Merged

add dense matmul benchmark #256

merged 10 commits into from
Sep 25, 2024

Conversation

jorendumoulin
Copy link
Contributor

@jorendumoulin jorendumoulin commented Sep 24, 2024

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

@jorendumoulin jorendumoulin marked this pull request as ready for review September 24, 2024 11:33
Copy link
Contributor

@JosseVanDelm JosseVanDelm left a 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):
Copy link
Contributor

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):
Copy link
Contributor

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

Comment on lines +10 to +50
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)
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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

@jorendumoulin jorendumoulin merged commit ae4ec7f into main Sep 25, 2024
14 checks passed
@jorendumoulin jorendumoulin deleted the joren/dense-benchmark branch September 25, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants