feat: add gemm_n16_k2048 workloads and baseline solution

#1
definitions/gemm/gemm_n16_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_n16_k2048",
35
+ "description": "General matrix multiply (GEMM) C = A @ B.T. Captured from Qwen3.5-35B-A3B at TP=2. N=16, K=2048.",
36
+ "axes": {
37
+ "M": {
38
+ "type": "var"
39
+ },
40
+ "N": {
41
+ "type": "const",
42
+ "value": 16
43
+ },
44
+ "K": {
45
+ "type": "const",
46
+ "value": 2048
47
+ }
48
+ }
49
+ }
solutions/baseline/gemm/gemm_n16_k2048/torch_matmul_8b8ea6.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "torch_matmul_8b8ea6",
3
+ "definition": "gemm_n16_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_n16_k2048.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 == 16
9
+ assert K == 2048
10
+ C = torch.matmul(A, B.T)
11
+ return C
12
+
13
+
14
+ def generate_random_inputs(M, N=16, 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=16, 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
+ # Reference
33
+ ref_C = run(inputs["A"], inputs["B"])
34
+
35
+ # Direct torch comparison (fp32)
36
+ A_f32 = inputs["A"].float()
37
+ B_f32 = inputs["B"].float()
38
+ expected = torch.matmul(A_f32, B_f32.T).to(torch.bfloat16)
39
+
40
+ abs_diff = torch.abs(ref_C.float() - expected.float())
41
+ max_abs_diff = abs_diff.max().item()
42
+ mean_abs_diff = abs_diff.mean().item()
43
+
44
+ print(f"Max absolute difference: {max_abs_diff:.6e}")
45
+ print(f"Mean absolute difference: {mean_abs_diff:.6e}")
46
+
47
+ close = torch.allclose(ref_C.float(), expected.float(), atol=atol, rtol=rtol)
48
+ if close:
49
+ print(f"\n✓ PASSED (atol={atol}, rtol={rtol})")
50
+ else:
51
+ print(f"\n✗ FAILED (atol={atol}, rtol={rtol})")
52
+ return close
53
+
54
+
55
+ def main():
56
+ print("Testing GEMM N=16, K=2048 Reference Implementation")
57
+
58
+ test_configs = [1, 4, 16, 64, 256]
59
+ passed = 0
60
+ total = len(test_configs)
61
+
62
+ for M in test_configs:
63
+ try:
64
+ if test_correctness(M):
65
+ passed += 1
66
+ except Exception as e:
67
+ print(f"✗ Test failed with exception: {e}")
68
+ import traceback
69
+ traceback.print_exc()
70
+
71
+ print(f"\n{'='*60}")
72
+ print(f"Summary: {passed}/{total} tests passed")
73
+ print(f"{'='*60}")
74
+
75
+
76
+ if __name__ == "__main__":
77
+ main()
workloads/gemm/gemm_n16_k2048.jsonl ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":8192},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"894d7a9c-ee2f-4cc0-95d5-006e9775d985"},"solution":null,"evaluation":null}
2
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":1111},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"e3e2855c-fde5-4aaf-8396-7bb15721cdab"},"solution":null,"evaluation":null}
3
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":100},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"d3585ec1-b594-4001-96a3-6ee2ba4c76a5"},"solution":null,"evaluation":null}
4
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":99},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"7d575e8d-5007-4976-a606-df07c12982c7"},"solution":null,"evaluation":null}
5
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":98},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"b70191f9-91a0-4805-a640-5cdb070f114a"},"solution":null,"evaluation":null}
6
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":97},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"9f6bf52f-6c02-4cdc-bd87-628cad5a5b27"},"solution":null,"evaluation":null}
7
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":96},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"2dd26cae-0e05-48f9-82a9-b497015b499b"},"solution":null,"evaluation":null}
8
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":51},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"0685c3f2-6451-447f-b120-4518dbcd6ccc"},"solution":null,"evaluation":null}
9
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":7962},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"9c8a7c74-32e2-4a46-a995-bb51dbd44f0f"},"solution":null,"evaluation":null}
10
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":113},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"577b98c5-8b78-4287-8029-53f4c9686893"},"solution":null,"evaluation":null}
11
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":6016},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"ad81ba73-66fd-4528-ad88-a6472be4bb74"},"solution":null,"evaluation":null}
12
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":95},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"e67265a4-7410-4096-b044-5ee9a1e6ef4b"},"solution":null,"evaluation":null}
13
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":219},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"fefb0904-b550-4cdb-b9a9-c3d26725c0c1"},"solution":null,"evaluation":null}
14
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":7794},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"6aa45276-3441-477d-a45c-840dd7e52ef9"},"solution":null,"evaluation":null}
15
+ {"definition":"gemm_n16_k2048","workload":{"axes":{"M":5574},"inputs":{"A":{"type":"random"},"B":{"type":"random"}},"uuid":"7361cca7-4c72-45e6-bb46-702bf4695778"},"solution":null,"evaluation":null}