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 benchmark support for e2e tests #183

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
if: "contains(matrix.os, 'mi300') && !cancelled()"
run: |
export WAVE_RUN_E2E_TESTS=1
pytest -n 4 ./tests/kernel/wave/
pytest -n 4 --capture=tee-sys ./tests/kernel/wave/

- name: Run LIT tests
if: ${{ !cancelled() }}
Expand Down
27 changes: 26 additions & 1 deletion shark_turbine/kernel/wave/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import torch.fx as fx
import shark_turbine.kernel.lang as tkl


import tempfile
from ...support.conversions import TORCH_DTYPE_TO_SIGNED_MLIR_TYPE_ASM
from iree.compiler.dialects.transform import (
interpreter as transform_interpreter,
any_op_t,
Expand Down Expand Up @@ -372,7 +375,29 @@ def compile_and_invoke(
_invoke(ctx.vm_context, device, func, kernel_inputs, kernel_outputs)

if run_bench:
inputs = [inp.numpy() for inp in kernel_inputs]
bench_with_constant_weights = config.get("bench_with_constant_weights", False)
tempfiles = []
inputs = []
if bench_with_constant_weights:
erman-gurses marked this conversation as resolved.
Show resolved Hide resolved
for inp in kernel_inputs:
inputs.append(
"x".join(
[str(x) for x in inp.shape]
+ [TORCH_DTYPE_TO_SIGNED_MLIR_TYPE_ASM[inp.dtype]]
)
)
else:
for inp in kernel_inputs:
tf = tempfile.NamedTemporaryFile()
torch.save(inp, tf)
tempfiles.append(tf)
inputs.append("@" + tf.name)

benchmark_results = bench.benchmark_module(
mod,
entry_function=func_name,
)

benchmark_results = bench.benchmark_module(
mod,
entry_function=func_name,
Expand Down
8 changes: 8 additions & 0 deletions tests/kernel/wave/wave_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def test(
},
canonicalize=True,
run=True,
run_bench=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be enabled by default, we need a separate option. Also, where bench results are saved?

run_config=config,
):
test(a, b)
Expand Down Expand Up @@ -214,6 +215,7 @@ def test(
},
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
):
test(a, b)
Expand Down Expand Up @@ -270,6 +272,7 @@ def test(
},
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
):
test(a, b)
Expand Down Expand Up @@ -326,6 +329,7 @@ def test(
},
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
):
test(a, b, c)
Expand Down Expand Up @@ -401,6 +405,7 @@ def repeat(
},
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
):
test(a, b, c)
Expand Down Expand Up @@ -505,6 +510,7 @@ def test(
},
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
):
test(a, b)
Expand Down Expand Up @@ -635,6 +641,7 @@ def repeat(acc: tkl.Register[M, NF, tkl.f32]) -> tkl.Register[M, NF, tkl.f32]:
},
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
):
gpu_func(x, we, out)
Expand Down Expand Up @@ -771,6 +778,7 @@ def repeat(acc: tkl.Register[M, NF, tkl.f32]) -> tkl.Register[M, NF, tkl.f32]:
},
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
):
conv(x, we, out)
Expand Down
1 change: 1 addition & 0 deletions tests/kernel/wave/wave_gemm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def repeat(acc: tkl.Register[M, N, tkl.f32]) -> tkl.Register[M, N, tkl.f32]:
hyperparams,
canonicalize=True,
run=True,
run_bench=True,
run_config=config,
schedule=enable_scheduling,
):
Expand Down
Loading