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

[TKW] Refactor test run config #265

Merged
merged 1 commit into from
Nov 12, 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
5 changes: 5 additions & 0 deletions iree/turbine/kernel/wave/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def run_test(func: Callable[[], None]) -> Callable[[], None]:
return func


def get_default_run_config() -> dict[Any, Any]:
"""Return default config for testing."""
return {"backend": "rocm", "device": "hip", "target": "gfx942"}


def print_trace(trace: CapturedTrace, custom_print: bool = True):
"""
Prints all subgraphs of a trace starting with the root graph.
Expand Down
15 changes: 8 additions & 7 deletions lit_tests/kernel/wave/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from iree.turbine.kernel.lang.global_symbols import *
from iree.turbine.kernel.wave.utils import (
run_test,
get_default_run_config,
get_mfma_load_elems_per_thread,
get_mfma_store_elems_per_thread,
)
Expand Down Expand Up @@ -1508,7 +1509,7 @@ def test(
res = tkw.sum(res, dim=N)
tkw.write(res, c, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

shape = (256, 128)
a = torch.randn(shape, dtype=torch.float16)
Expand Down Expand Up @@ -1584,7 +1585,7 @@ def test(
res = tkw.sum([lhs, rhs], dim=N)
tkw.write(res, c, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

shape = (256, 128)
a = torch.randn(shape, dtype=torch.float16)
Expand Down Expand Up @@ -1656,7 +1657,7 @@ def repeat(
result = repeat + repeat
tkw.write(result, c, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

shape = (256, 512)
a = torch.randn(shape, dtype=torch.float16)
Expand Down Expand Up @@ -1744,7 +1745,7 @@ def repeat(

tkw.write(repeat, c, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

shape = (256, 512)
a = torch.randn(shape, dtype=torch.float16)
Expand Down Expand Up @@ -1843,7 +1844,7 @@ def repeat(
tkw.write(res_max, c, elements_per_thread=1)
tkw.write(res_sum, d, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

shape = (256, 512)
a = torch.randn(shape, dtype=torch.float16)
Expand Down Expand Up @@ -1942,7 +1943,7 @@ def repeat(
res_max, res_sum = repeat
tkw.write(res_sum, c, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

shape = (256, 1024)
a = torch.randn(shape, dtype=torch.float32)
Expand Down Expand Up @@ -2003,7 +2004,7 @@ def test(
res = lhs + rhs
tkw.write(res, c, elements_per_thread=STORE_ELEMS_PER_THREAD)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

shape = (256, 128)
a = torch.ones(shape, dtype=torch.float16)
Expand Down
7 changes: 4 additions & 3 deletions tests/kernel/wave/wave_attention_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from iree.turbine.kernel.lang.global_symbols import *
from iree.turbine.kernel.wave.iree_utils import generate_iree_ref
from iree.turbine.kernel.wave.utils import (
get_default_run_config,
get_mfma_load_elems_per_thread,
get_mfma_store_elems_per_thread,
)
Expand Down Expand Up @@ -161,7 +162,7 @@ def repeat(
GLOBAL_MEMORY_UNITS: 4,
MMA_UNITS: 4,
}
config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()
if run_bench:
config["benchmark_batch_size"] = 10
config["benchmark_repetitions"] = 3
Expand Down Expand Up @@ -310,7 +311,7 @@ def repeat(
GLOBAL_MEMORY_UNITS: 4,
MMA_UNITS: 4,
}
config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()
if run_bench:
config["benchmark_batch_size"] = 10
config["benchmark_repetitions"] = 3
Expand Down Expand Up @@ -478,7 +479,7 @@ def repeat(
GLOBAL_MEMORY_UNITS: 4,
MMA_UNITS: 4,
}
config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()
if run_bench:
config["benchmark_batch_size"] = 10
config["benchmark_repetitions"] = 3
Expand Down
21 changes: 11 additions & 10 deletions tests/kernel/wave/wave_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from iree.turbine.kernel.wave.wave_sim import wave_sim
from iree.turbine.kernel.lang.global_symbols import *
from iree.turbine.kernel.wave.iree_utils import generate_iree_ref
from iree.turbine.kernel.wave.utils import get_default_run_config
import torch
from numpy.testing import assert_allclose, assert_equal
import pytest
Expand Down Expand Up @@ -92,7 +93,7 @@ def test(
res = tkw.read(a, elements_per_thread=ELEMS_PER_THREAD)
tkw.write(res, b, elements_per_thread=ELEMS_PER_THREAD)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

a = torch.randn(shape, dtype=torch.float16)
b = torch.zeros(shape, dtype=torch.float16)
Expand Down Expand Up @@ -149,7 +150,7 @@ def test(
res = tkw.read(a, elements_per_thread=ELEMS_PER_THREAD)
tkw.write(res, b, elements_per_thread=ELEMS_PER_THREAD)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

a = torch.randn(shape, dtype=torch.float16)
b = torch.zeros(shape, dtype=torch.float16)
Expand Down Expand Up @@ -208,7 +209,7 @@ def test(
res = tkw.read(a, mapping=mapping, elements_per_thread=ELEMS_PER_THREAD)
tkw.write(res, b, elements_per_thread=ELEMS_PER_THREAD)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

a = torch.randn(shape, dtype=torch.float16)
b = torch.zeros(shape[::-1], dtype=torch.float16)
Expand Down Expand Up @@ -266,7 +267,7 @@ def test(
res = tkw.read(a, elements_per_thread=ELEMS_PER_THREAD)
tkw.write(res, b, mapping=mapping, elements_per_thread=ELEMS_PER_THREAD)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

a = torch.randn(shape, dtype=torch.float16)
b = torch.zeros(shape[::-1], dtype=torch.float16)
Expand Down Expand Up @@ -321,7 +322,7 @@ def test(
res = tkw.sum(res, dim=N)
tkw.write(res, c, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

torch.manual_seed(1)
a = torch.randn(shape, dtype=torch.float16)
Expand Down Expand Up @@ -393,7 +394,7 @@ def repeat(
result = res_max / res_sum
tkw.write(result, c, elements_per_thread=1)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

torch.manual_seed(1)
a = torch.randn(shape, dtype=torch.float32)
Expand Down Expand Up @@ -492,7 +493,7 @@ def test(
res = tkw.read(a, mapping=mapping, elements_per_thread=ELEMS_PER_THREAD)
tkw.write(res, b, elements_per_thread=ELEMS_PER_THREAD)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

h_out = (h + 2 * padding - hf) // stride + 1
w_out = (w + 2 * padding - wf) // stride + 1
Expand Down Expand Up @@ -631,7 +632,7 @@ def repeat(acc: tkl.Register[M, NF, tkl.f32]) -> tkl.Register[M, NF, tkl.f32]:

out = torch.zeros_like(out_ref)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

with tk.gen.TestLaunchContext(
{
Expand Down Expand Up @@ -843,7 +844,7 @@ def repeat(acc: tkl.Register[M, NF, tkl.f32]) -> tkl.Register[M, NF, tkl.f32]:
repeat, out, mapping=out_mapping, elements_per_thread=ELEMS_PER_THREAD
)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

run_bench = request.config.getoption("--runperf")
dump_perf = request.config.getoption("--dump-perf-files-path")
Expand Down Expand Up @@ -939,7 +940,7 @@ def test(
res = tkw.cast(res, tkl.f16)
tkw.write(res, b, elements_per_thread=ELEMS_PER_THREAD)

config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()

a = torch.randn(shape, dtype=torch.float32)
b = torch.zeros(shape, dtype=torch.float16)
Expand Down
7 changes: 4 additions & 3 deletions tests/kernel/wave/wave_gemm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from iree.turbine.kernel.lang.global_symbols import *
from iree.turbine.kernel.wave.iree_utils import generate_iree_ref
from iree.turbine.kernel.wave.utils import (
get_default_run_config,
get_mfma_load_elems_per_thread,
get_mfma_store_elems_per_thread,
)
Expand Down Expand Up @@ -146,7 +147,7 @@ def repeat(acc: tkl.Register[M, N, tkl.f32]) -> tkl.Register[M, N, tkl.f32]:
GLOBAL_MEMORY_UNITS: 4,
MMA_UNITS: 4,
}
config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()
if run_bench:
config["benchmark_batch_size"] = 10
config["benchmark_repetitions"] = 3
Expand Down Expand Up @@ -265,7 +266,7 @@ def repeat(acc: tkl.Register[M, N, tkl.f32]) -> tkl.Register[M, N, tkl.f32]:
GLOBAL_MEMORY_UNITS: 4,
MMA_UNITS: 4,
}
config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()
if run_bench:
config["benchmark_batch_size"] = 10
config["benchmark_repetitions"] = 3
Expand Down Expand Up @@ -380,7 +381,7 @@ def repeat(
GLOBAL_MEMORY_UNITS: 4,
MMA_UNITS: 4,
}
config = {"backend": "rocm", "device": "hip", "target": "gfx942"}
config = get_default_run_config()
if run_bench:
config["benchmark_batch_size"] = 10
config["benchmark_repetitions"] = 3
Expand Down
Loading