Skip to content
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
6 changes: 4 additions & 2 deletions benchmarks/bench_groupwise_gemm_fp8_blackwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ def bench_groupwise_gemm_fp8_blackwell(m, n, k, in_dtype, out_dtype):
b_scale = torch.rand((k // 128, n // 128), dtype=torch.float32, device="cuda")

out = torch.empty((m, n), dtype=out_dtype, device="cuda")
gemm_fp8_nt_groupwise(a, b, a_scale, b_scale, out=out)
gemm_fp8_nt_groupwise(a, b, a_scale, b_scale, out=out, scale_major_mode="MN")

measurements = bench_gpu_time(
lambda: gemm_fp8_nt_groupwise(a, b, a_scale, b_scale, out=out)
lambda: gemm_fp8_nt_groupwise(
a, b, a_scale, b_scale, out=out, scale_major_mode="MN"
)
)
ms = np.median(measurements)
tflops_per_second = 2 * m * n * k * 1e-9 / ms
Expand Down
10 changes: 6 additions & 4 deletions benchmarks/bench_tgv_gemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_tgv_gemm_bf16_sm100_perf():

for m, n, k, has_bias, description in test_cases:
print(f"\n--- {description}: M={m}, N={n}, K={k}, has_bias={has_bias} ---")

flops = m * n * k * 2 / 1e12
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve readability and maintainability, it's a good practice to avoid using magic numbers. Consider defining 2 and 1e12 as named constants with descriptive names.

Suggested change
flops = m * n * k * 2 / 1e12
FLOPS_PER_MAC = 2
TFLOPS_SCALE = 1e12
flops = (m * n * k * FLOPS_PER_MAC) / TFLOPS_SCALE

# Create tensors
A = torch.randn(m, k, device="cuda", dtype=torch.bfloat16)
B = torch.randn(n, k, device="cuda", dtype=torch.bfloat16).t()
Expand Down Expand Up @@ -99,7 +99,9 @@ def test_tgv_gemm_bf16_sm100_perf():
torch.cuda.synchronize()
end_time = time.time()
cublas_avg_time = (end_time - start_time) / 100
print(f"CUBLAS average time: {cublas_avg_time * 1000:.6f} ms")
print(
f"CUBLAS average time: {cublas_avg_time * 1000:.6f} ms, {flops / cublas_avg_time:.3f} TFLOPS"
)

# Warmup
with autotune(tune_mode=True):
Expand Down Expand Up @@ -128,7 +130,7 @@ def test_tgv_gemm_bf16_sm100_perf():

tgv_avg_time = (end_time - start_time) / 100
print(
f"TGV average time: {tgv_avg_time * 1000:.6f} ms, speedup: {cublas_avg_time / tgv_avg_time:.2f}x"
f"TGV average time: {tgv_avg_time * 1000:.6f} ms, {flops / tgv_avg_time:.3f} TFLOPS, speedup: {cublas_avg_time / tgv_avg_time:.2f}x"
)

# Test with PDL
Expand All @@ -151,7 +153,7 @@ def test_tgv_gemm_bf16_sm100_perf():

pdl_avg_time = (end_time - start_time) / 100
print(
f"PDL average time: {pdl_avg_time * 1000:.6f} ms, speedup: {cublas_avg_time / pdl_avg_time:.2f}x"
f"PDL average time: {pdl_avg_time * 1000:.6f} ms, {flops / pdl_avg_time:.3f} TFLOPS, speedup: {cublas_avg_time / pdl_avg_time:.2f}x"
)

# Store results for CSV
Expand Down