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 hipBLAS/cuBLAS distinction in benchmark_gemm.py #1393

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions benchmarks/benchmark_gemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from triton.testing import do_bench

if torch.version.cuda:
backendBLAS = "cuBLAS"
elif torch.version.hip:
backendBLAS = "hipBLAS"

def benchmark_forward(fn, *inputs, repeats=10, desc='', verbose=True, **kwinputs):
"""Use Pytorch Benchmark on the forward pass of an arbitrary function."""
Expand Down Expand Up @@ -34,10 +38,10 @@ def benchmark_forward(fn, *inputs, repeats=10, desc='', verbose=True, **kwinputs
b = torch.randn(n, k, device=device, dtype=dtype).transpose(-1, -2)
nFLOPS_matmul = 2 * m * n * k
time.sleep(2) # to reduce power throttling
timing = benchmark_forward(torch.matmul, a, b, desc='cuBLAS', verbose=verbose, repeats=repeats)[1]
timing = benchmark_forward(torch.matmul, a, b, desc=backendBLAS, verbose=verbose, repeats=repeats)[1]
tflops_matmul[k] = nFLOPS_matmul / timing.mean * 1e-12
print(f'[torch.utils.benchmark] cuBLAS, {m = }, {n = }, {k = }: {timing.mean * 1e3:.3f}ms, {tflops_matmul[k]:.1f} TFLOPS')
print(f'[torch.utils.benchmark] {backendBLAS}, {m = }, {n = }, {k = }: {timing.mean * 1e3:.3f}ms, {tflops_matmul[k]:.1f} TFLOPS')
time.sleep(2) # to reduce power throttling
ms = do_bench(lambda: torch.matmul(a, b), warmup=10, rep=repeats)
tflops_matmul1[k] = nFLOPS_matmul / ms * 1e-9
print(f'[triton.test.do_bench] cuBLAS, {m = }, {n = }, {k = }: {ms:.3f}ms, {tflops_matmul1[k]:.1f} TFLOPS')
print(f'[triton.test.do_bench] {backendBLAS}, {m = }, {n = }, {k = }: {ms:.3f}ms, {tflops_matmul1[k]:.1f} TFLOPS')