feat: add gemm_n512_k2048 workloads and baseline solution

#3
definitions/gemm/gemm_n512_k2048.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "op_type": "gemm",
3
+ "tags": [
4
+ "model:qwen3.5-35b-a3b",
5
+ "status:reference",
6
+ "tp:2"
7
+ ],
8
+ "inputs": {
9
+ "A": {
10
+ "shape": [
11
+ "M",
12
+ "K"
13
+ ],
14
+ "dtype": "bfloat16"
15
+ },
16
+ "B": {
17
+ "shape": [
18
+ "N",
19
+ "K"
20
+ ],
21
+ "dtype": "bfloat16"
22
+ }
23
+ },
24
+ "outputs": {
25
+ "C": {
26
+ "shape": [
27
+ "M",
28
+ "N"
29
+ ],
30
+ "dtype": "bfloat16"
31
+ }
32
+ },
33
+ "reference": "import torch\n\ndef run(A, B):\n C = torch.matmul(A, B.T)\n return C",
34
+ "name": "gemm_n512_k2048",
35
+ "description": "General matrix multiply (GEMM) C = A @ B.T. Captured from Qwen3.5-35B-A3B at TP=2. N=512, K=2048.",
36
+ "axes": {
37
+ "M": {
38
+ "type": "var"
39
+ },
40
+ "N": {
41
+ "type": "const",
42
+ "value": 512
43
+ },
44
+ "K": {
45
+ "type": "const",
46
+ "value": 2048
47
+ }
48
+ }
49
+ }
solutions/baseline/gemm/gemm_n512_k2048/torch_matmul_8b8ea6.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "torch_matmul_8b8ea6",
3
+ "definition": "gemm_n512_k2048",
4
+ "author": "PyTorch",
5
+ "spec": {
6
+ "language": "python",
7
+ "target_hardware": [
8
+ "NVIDIA_H100",
9
+ "NVIDIA_A100",
10
+ "CPU"
11
+ ],
12
+ "entry_point": "main.py::run",
13
+ "dependencies": [],
14
+ "destination_passing_style": false
15
+ },
16
+ "sources": [
17
+ {
18
+ "path": "main.py",
19
+ "content": "import torch\n\ndef run(A, B):\n C = torch.matmul(A, B.T)\n return C"
20
+ }
21
+ ],
22
+ "description": "Baseline GEMM implemented with torch.matmul."
23
+ }
tests/references/test_gemm_n512_k2048.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+
4
+ def run(A, B):
5
+ M, K = A.shape
6
+ N, K2 = B.shape
7
+ assert K == K2
8
+ assert N == 512
9
+ assert K == 2048
10
+ C = torch.matmul(A, B.T)
11
+ return C
12
+
13
+
14
+ def generate_random_inputs(M, N=512, K=2048, device="cuda"):
15
+ A = torch.randn(M, K, dtype=torch.bfloat16, device=device)
16
+ B = torch.randn(N, K, dtype=torch.bfloat16, device=device)
17
+ return {"A": A, "B": B}
18
+
19
+
20
+ def test_correctness(M=32, atol=1e-2, rtol=1e-2):
21
+ print(f"\n{'='*60}")
22
+ print(f"Testing GEMM N=512, K=2048, M={M}")
23
+ print(f"{'='*60}")
24
+
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+ if device == "cpu":
27
+ print("WARNING: CUDA not available, skipping test")
28
+ return True
29
+
30
+ inputs = generate_random_inputs(M, device=device)
31
+
32
+ ref_C = run(inputs["A"], inputs["B"])
33
+
34
+ A_f32 = inputs["A"].float()
35
+ B_f32 = inputs["B"].float()
36
+ expected = torch.matmul(A_f32, B_f32.T).to(torch.bfloat16)
37
+
38
+ abs_diff = torch.abs(ref_C.float() - expected.float())
39
+ max_abs_diff = abs_diff.max().item()
40
+ mean_abs_diff = abs_diff.mean().item()
41
+
42
+ print(f"Max absolute difference: {max_abs_diff:.6e}")
43
+ print(f"Mean absolute difference: {mean_abs_diff:.6e}")
44
+
45
+ close = torch.allclose(ref_C.float(), expected.float(), atol=atol, rtol=rtol)
46
+ if close:
47
+ print(f"\nβœ“ PASSED (atol={atol}, rtol={rtol})")
48
+ else:
49
+ print(f"\nβœ— FAILED (atol={atol}, rtol={rtol})")
50
+ return close
51
+
52
+
53
+ def main():
54
+ print("Testing GEMM N=512, K=2048 Reference Implementation")
55
+
56
+ test_configs = [1, 4, 16, 64, 256]
57
+ passed = 0
58
+ total = len(test_configs)
59
+
60
+ for M in test_configs:
61
+ try:
62
+ if test_correctness(M):
63
+ passed += 1
64
+ except Exception as e:
65
+ print(f"βœ— Test failed with exception: {e}")
66
+ import traceback
67
+ traceback.print_exc()
68
+
69
+ print(f"\n{'='*60}")
70
+ print(f"Summary: {passed}/{total} tests passed")
71
+ print(f"{'='*60}")
72
+
73
+
74
+ if __name__ == "__main__":
75
+ main()
workloads/gemm/gemm_n512_k2048.jsonl ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":8192},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"e3253003-7ed4-4c98-9b72-d9bf1bd31f2a"},"solution":null,"evaluation":null}
2
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":1111},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"f7670b35-e258-42dd-98e2-a1d00bc1f889"},"solution":null,"evaluation":null}
3
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":100},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"af5c5626-d798-42e3-ac09-ca6e16ca50d6"},"solution":null,"evaluation":null}
4
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":99},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"63601b13-03a1-46e1-9aef-fc7595645dfc"},"solution":null,"evaluation":null}
5
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":98},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"283ef5fb-8e7f-482f-9b49-e77d3709e53e"},"solution":null,"evaluation":null}
6
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":97},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"769d33ae-ded8-4864-95a9-8b0070957a8b"},"solution":null,"evaluation":null}
7
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":96},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"b38c420e-63bb-4ab2-8b86-bbe54b172fe2"},"solution":null,"evaluation":null}
8
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":51},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"956336e2-4d66-442c-a511-073f9b73036c"},"solution":null,"evaluation":null}
9
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":7962},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"ceb33a84-8854-4639-b937-45ffd736d091"},"solution":null,"evaluation":null}
10
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":113},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"f3518ee6-b062-4228-9806-e7f61e98875a"},"solution":null,"evaluation":null}
11
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":6016},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"4d841f31-5098-4be1-ad1e-850aa682c608"},"solution":null,"evaluation":null}
12
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":95},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"ea42c706-2b1e-43a2-a579-18e984f7cb11"},"solution":null,"evaluation":null}
13
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":219},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"7d88c702-a277-4aaa-a151-4cedc8e1ec1b"},"solution":null,"evaluation":null}
14
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":7794},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"8e242714-feb3-4d27-b10f-fb97dd6666cf"},"solution":null,"evaluation":null}
15
+ {"definition":"gemm_n512_k2048","workload":{"axes":{"M":5574},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"b7dd4d94-09a3-4fc3-a587-0f401c9ee350"},"solution":null,"evaluation":null}