diff --git a/definitions/gemm/gemm_fp32_n1024_k2048.json b/definitions/gemm/gemm_bf16_n1024_k2048.json similarity index 83% rename from definitions/gemm/gemm_fp32_n1024_k2048.json rename to definitions/gemm/gemm_bf16_n1024_k2048.json index eba5eb0dc72ed77b20ea8272fc3c2d843a5ac756..82a4046f1d0839d3b1070521c1e43ef3b7254005 100644 --- a/definitions/gemm/gemm_fp32_n1024_k2048.json +++ b/definitions/gemm/gemm_bf16_n1024_k2048.json @@ -1,5 +1,5 @@ { - "name": "gemm_fp32_n1024_k2048", + "name": "gemm_bf16_n1024_k2048", "op_type": "gemm", "description": "expert ffn N=1024 K=2048", "tags": [ @@ -26,14 +26,14 @@ "M", "K" ], - "dtype": "float32" + "dtype": "bfloat16" }, "B": { "shape": [ "N", "K" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -46,5 +46,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(A, B):\n return A @ B.T\n" + "reference": "import numpy as np\ndef run(A, B):\n return A.astype(np.float32) @ B.astype(np.float32).T\n" } diff --git a/definitions/gemm/gemm_fp32_n1408_k2048.json b/definitions/gemm/gemm_bf16_n1408_k2048.json similarity index 83% rename from definitions/gemm/gemm_fp32_n1408_k2048.json rename to definitions/gemm/gemm_bf16_n1408_k2048.json index ca47bd7a1ea42d4d30a3da4766348f8f2e35119b..ac7961116fcf1f2554b515d9ff3f3071e4272490 100644 --- a/definitions/gemm/gemm_fp32_n1408_k2048.json +++ b/definitions/gemm/gemm_bf16_n1408_k2048.json @@ -1,5 +1,5 @@ { - "name": "gemm_fp32_n1408_k2048", + "name": "gemm_bf16_n1408_k2048", "op_type": "gemm", "description": "expert ffn N=1408 K=2048", "tags": [ @@ -26,14 +26,14 @@ "M", "K" ], - "dtype": "float32" + "dtype": "bfloat16" }, "B": { "shape": [ "N", "K" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -46,5 +46,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(A, B):\n return A @ B.T\n" + "reference": "import numpy as np\ndef run(A, B):\n return A.astype(np.float32) @ B.astype(np.float32).T\n" } diff --git a/definitions/gemm/gemm_fp32_n2048_k1024.json b/definitions/gemm/gemm_bf16_n2048_k1024.json similarity index 83% rename from definitions/gemm/gemm_fp32_n2048_k1024.json rename to definitions/gemm/gemm_bf16_n2048_k1024.json index 30f2836d69dbc2a62d0602ac845a7d11b4738113..b726787dacc182a08fffce0159ce3a30b4650bd7 100644 --- a/definitions/gemm/gemm_fp32_n2048_k1024.json +++ b/definitions/gemm/gemm_bf16_n2048_k1024.json @@ -1,5 +1,5 @@ { - "name": "gemm_fp32_n2048_k1024", + "name": "gemm_bf16_n2048_k1024", "op_type": "gemm", "description": "expert ffn N=2048 K=1024", "tags": [ @@ -26,14 +26,14 @@ "M", "K" ], - "dtype": "float32" + "dtype": "bfloat16" }, "B": { "shape": [ "N", "K" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -46,5 +46,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(A, B):\n return A @ B.T\n" + "reference": "import numpy as np\ndef run(A, B):\n return A.astype(np.float32) @ B.astype(np.float32).T\n" } diff --git a/definitions/gemm/gemm_fp32_n2048_k1408.json b/definitions/gemm/gemm_bf16_n2048_k1408.json similarity index 83% rename from definitions/gemm/gemm_fp32_n2048_k1408.json rename to definitions/gemm/gemm_bf16_n2048_k1408.json index 2381f45b982b21e17a70f6c689322e0ba30f58f2..4ac30d2da25a7ddb0afd0c120922f927d5f31bc7 100644 --- a/definitions/gemm/gemm_fp32_n2048_k1408.json +++ b/definitions/gemm/gemm_bf16_n2048_k1408.json @@ -1,5 +1,5 @@ { - "name": "gemm_fp32_n2048_k1408", + "name": "gemm_bf16_n2048_k1408", "op_type": "gemm", "description": "expert ffn N=2048 K=1408", "tags": [ @@ -26,14 +26,14 @@ "M", "K" ], - "dtype": "float32" + "dtype": "bfloat16" }, "B": { "shape": [ "N", "K" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -46,5 +46,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(A, B):\n return A @ B.T\n" + "reference": "import numpy as np\ndef run(A, B):\n return A.astype(np.float32) @ B.astype(np.float32).T\n" } diff --git a/definitions/gemm/gemm_fp32_n2048_k2048.json b/definitions/gemm/gemm_bf16_n2048_k2048.json similarity index 83% rename from definitions/gemm/gemm_fp32_n2048_k2048.json rename to definitions/gemm/gemm_bf16_n2048_k2048.json index f0ea183ddb1296f9b6aa657e6cbc3272fbdcaf6b..e647197c9941d90daeaa0a30b0b879f5c59f39f8 100644 --- a/definitions/gemm/gemm_fp32_n2048_k2048.json +++ b/definitions/gemm/gemm_bf16_n2048_k2048.json @@ -1,5 +1,5 @@ { - "name": "gemm_fp32_n2048_k2048", + "name": "gemm_bf16_n2048_k2048", "op_type": "gemm", "description": "attn proj N=2048 K=2048", "tags": [ @@ -26,14 +26,14 @@ "M", "K" ], - "dtype": "float32" + "dtype": "bfloat16" }, "B": { "shape": [ "N", "K" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -46,5 +46,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(A, B):\n return A @ B.T\n" + "reference": "import numpy as np\ndef run(A, B):\n return A.astype(np.float32) @ B.astype(np.float32).T\n" } diff --git a/definitions/gemm/gemm_q4_k_m_n1024_k2048.json b/definitions/gemm/gemm_q4_k_m_n1024_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..4b557f428a14043e50089a183391c8e95605301a --- /dev/null +++ b/definitions/gemm/gemm_q4_k_m_n1024_k2048.json @@ -0,0 +1,72 @@ +{ + "name": "gemm_q4_k_m_n1024_k2048", + "op_type": "gemm", + "description": "expert ffn N=1024 K=2048", + "tags": [ + "status:active", + "model:olmoe-1b-7b", + "baseline-solution:llama.cpp" + ], + "axes": { + "M": { + "type": "var" + }, + "N": { + "type": "const", + "value": 1024 + }, + "K": { + "type": "const", + "value": 2048 + }, + "K_half": { + "type": "const", + "value": 1024 + }, + "K_sub": { + "type": "const", + "value": 64 + } + }, + "inputs": { + "A": { + "shape": [ + "M", + "K" + ], + "dtype": "bfloat16" + }, + "B_q4": { + "shape": [ + "N", + "K_half" + ], + "dtype": "uint8" + }, + "B_scales": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + }, + "B_mins": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + } + }, + "outputs": { + "C": { + "shape": [ + "M", + "N" + ], + "dtype": "float32" + } + }, + "constraints": [], + "reference": "import numpy as np\n\n\ndef dq4k(q4, scales, mins):\n K = q4.shape[-1] * 2\n lo = (q4 & 0x0F).astype(np.float32)\n hi = (q4 >> 4).astype(np.float32)\n nib = np.empty(q4.shape[:-1] + (K,), dtype=np.float32)\n nib[..., 0::2] = lo\n nib[..., 1::2] = hi\n s = np.repeat(scales.astype(np.float32), 32, axis=-1)\n m = np.repeat(mins.astype(np.float32), 32, axis=-1)\n return s * nib - m\n\n\ndef run(A, B_q4, B_scales, B_mins):\n A_f = A.astype(np.float32)\n B_f = dq4k(B_q4, B_scales, B_mins)\n return A_f @ B_f.T\n" +} diff --git a/definitions/gemm/gemm_q4_k_m_n1408_k2048.json b/definitions/gemm/gemm_q4_k_m_n1408_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..ba252718ec5d73f47be514dab97f19fd9d4015ed --- /dev/null +++ b/definitions/gemm/gemm_q4_k_m_n1408_k2048.json @@ -0,0 +1,72 @@ +{ + "name": "gemm_q4_k_m_n1408_k2048", + "op_type": "gemm", + "description": "expert ffn N=1408 K=2048", + "tags": [ + "status:active", + "model:qwen1.5-moe-a2.7b", + "baseline-solution:llama.cpp" + ], + "axes": { + "M": { + "type": "var" + }, + "N": { + "type": "const", + "value": 1408 + }, + "K": { + "type": "const", + "value": 2048 + }, + "K_half": { + "type": "const", + "value": 1024 + }, + "K_sub": { + "type": "const", + "value": 64 + } + }, + "inputs": { + "A": { + "shape": [ + "M", + "K" + ], + "dtype": "bfloat16" + }, + "B_q4": { + "shape": [ + "N", + "K_half" + ], + "dtype": "uint8" + }, + "B_scales": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + }, + "B_mins": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + } + }, + "outputs": { + "C": { + "shape": [ + "M", + "N" + ], + "dtype": "float32" + } + }, + "constraints": [], + "reference": "import numpy as np\n\n\ndef dq4k(q4, scales, mins):\n K = q4.shape[-1] * 2\n lo = (q4 & 0x0F).astype(np.float32)\n hi = (q4 >> 4).astype(np.float32)\n nib = np.empty(q4.shape[:-1] + (K,), dtype=np.float32)\n nib[..., 0::2] = lo\n nib[..., 1::2] = hi\n s = np.repeat(scales.astype(np.float32), 32, axis=-1)\n m = np.repeat(mins.astype(np.float32), 32, axis=-1)\n return s * nib - m\n\n\ndef run(A, B_q4, B_scales, B_mins):\n A_f = A.astype(np.float32)\n B_f = dq4k(B_q4, B_scales, B_mins)\n return A_f @ B_f.T\n" +} diff --git a/definitions/gemm/gemm_q4_k_m_n2048_k1024.json b/definitions/gemm/gemm_q4_k_m_n2048_k1024.json new file mode 100644 index 0000000000000000000000000000000000000000..0b7b19badcc0a51575173818c85d9d3b01872d61 --- /dev/null +++ b/definitions/gemm/gemm_q4_k_m_n2048_k1024.json @@ -0,0 +1,72 @@ +{ + "name": "gemm_q4_k_m_n2048_k1024", + "op_type": "gemm", + "description": "expert ffn N=2048 K=1024", + "tags": [ + "status:active", + "model:olmoe-1b-7b", + "baseline-solution:llama.cpp" + ], + "axes": { + "M": { + "type": "var" + }, + "N": { + "type": "const", + "value": 2048 + }, + "K": { + "type": "const", + "value": 1024 + }, + "K_half": { + "type": "const", + "value": 512 + }, + "K_sub": { + "type": "const", + "value": 32 + } + }, + "inputs": { + "A": { + "shape": [ + "M", + "K" + ], + "dtype": "bfloat16" + }, + "B_q4": { + "shape": [ + "N", + "K_half" + ], + "dtype": "uint8" + }, + "B_scales": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + }, + "B_mins": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + } + }, + "outputs": { + "C": { + "shape": [ + "M", + "N" + ], + "dtype": "float32" + } + }, + "constraints": [], + "reference": "import numpy as np\n\n\ndef dq4k(q4, scales, mins):\n K = q4.shape[-1] * 2\n lo = (q4 & 0x0F).astype(np.float32)\n hi = (q4 >> 4).astype(np.float32)\n nib = np.empty(q4.shape[:-1] + (K,), dtype=np.float32)\n nib[..., 0::2] = lo\n nib[..., 1::2] = hi\n s = np.repeat(scales.astype(np.float32), 32, axis=-1)\n m = np.repeat(mins.astype(np.float32), 32, axis=-1)\n return s * nib - m\n\n\ndef run(A, B_q4, B_scales, B_mins):\n A_f = A.astype(np.float32)\n B_f = dq4k(B_q4, B_scales, B_mins)\n return A_f @ B_f.T\n" +} diff --git a/definitions/gemm/gemm_q4_k_m_n2048_k1536.json b/definitions/gemm/gemm_q4_k_m_n2048_k1536.json new file mode 100644 index 0000000000000000000000000000000000000000..38cb251db3cf0334c31332383cc0587d6b1a43f2 --- /dev/null +++ b/definitions/gemm/gemm_q4_k_m_n2048_k1536.json @@ -0,0 +1,72 @@ +{ + "name": "gemm_q4_k_m_n2048_k1536", + "op_type": "gemm", + "description": "expert ffn N=2048 K=1536 (K rounded up from 1408 to 1536, the next multiple of 256, since Q4_K requires the reduction dim divisible by 256; real GGML would fall back to Q5_0 for the unrounded 1408 shape)", + "tags": [ + "status:active", + "model:qwen1.5-moe-a2.7b", + "baseline-solution:llama.cpp" + ], + "axes": { + "M": { + "type": "var" + }, + "N": { + "type": "const", + "value": 2048 + }, + "K": { + "type": "const", + "value": 1536 + }, + "K_half": { + "type": "const", + "value": 768 + }, + "K_sub": { + "type": "const", + "value": 48 + } + }, + "inputs": { + "A": { + "shape": [ + "M", + "K" + ], + "dtype": "bfloat16" + }, + "B_q4": { + "shape": [ + "N", + "K_half" + ], + "dtype": "uint8" + }, + "B_scales": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + }, + "B_mins": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + } + }, + "outputs": { + "C": { + "shape": [ + "M", + "N" + ], + "dtype": "float32" + } + }, + "constraints": [], + "reference": "import numpy as np\n\n\ndef dq4k(q4, scales, mins):\n K = q4.shape[-1] * 2\n lo = (q4 & 0x0F).astype(np.float32)\n hi = (q4 >> 4).astype(np.float32)\n nib = np.empty(q4.shape[:-1] + (K,), dtype=np.float32)\n nib[..., 0::2] = lo\n nib[..., 1::2] = hi\n s = np.repeat(scales.astype(np.float32), 32, axis=-1)\n m = np.repeat(mins.astype(np.float32), 32, axis=-1)\n return s * nib - m\n\n\ndef run(A, B_q4, B_scales, B_mins):\n A_f = A.astype(np.float32)\n B_f = dq4k(B_q4, B_scales, B_mins)\n return A_f @ B_f.T\n" +} diff --git a/definitions/gemm/gemm_q4_k_m_n2048_k2048.json b/definitions/gemm/gemm_q4_k_m_n2048_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..0637d238515c2dfda4bc43c019cee33591cb6b07 --- /dev/null +++ b/definitions/gemm/gemm_q4_k_m_n2048_k2048.json @@ -0,0 +1,72 @@ +{ + "name": "gemm_q4_k_m_n2048_k2048", + "op_type": "gemm", + "description": "expert ffn N=2048 K=2048", + "tags": [ + "status:active", + "model:qwen1.5-moe-a2.7b", + "baseline-solution:llama.cpp" + ], + "axes": { + "M": { + "type": "var" + }, + "N": { + "type": "const", + "value": 2048 + }, + "K": { + "type": "const", + "value": 2048 + }, + "K_half": { + "type": "const", + "value": 1024 + }, + "K_sub": { + "type": "const", + "value": 64 + } + }, + "inputs": { + "A": { + "shape": [ + "M", + "K" + ], + "dtype": "bfloat16" + }, + "B_q4": { + "shape": [ + "N", + "K_half" + ], + "dtype": "uint8" + }, + "B_scales": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + }, + "B_mins": { + "shape": [ + "N", + "K_sub" + ], + "dtype": "float16" + } + }, + "outputs": { + "C": { + "shape": [ + "M", + "N" + ], + "dtype": "float32" + } + }, + "constraints": [], + "reference": "import numpy as np\n\n\ndef dq4k(q4, scales, mins):\n K = q4.shape[-1] * 2\n lo = (q4 & 0x0F).astype(np.float32)\n hi = (q4 >> 4).astype(np.float32)\n nib = np.empty(q4.shape[:-1] + (K,), dtype=np.float32)\n nib[..., 0::2] = lo\n nib[..., 1::2] = hi\n s = np.repeat(scales.astype(np.float32), 32, axis=-1)\n m = np.repeat(mins.astype(np.float32), 32, axis=-1)\n return s * nib - m\n\n\ndef run(A, B_q4, B_scales, B_mins):\n A_f = A.astype(np.float32)\n B_f = dq4k(B_q4, B_scales, B_mins)\n return A_f @ B_f.T\n" +} diff --git a/definitions/mha/mha_fp32_h16_d128_kvh16.json b/definitions/mha/mha_bf16_h16_d128_kvh16.json similarity index 58% rename from definitions/mha/mha_fp32_h16_d128_kvh16.json rename to definitions/mha/mha_bf16_h16_d128_kvh16.json index 9f6b1446bd59673fa2270ff5cae77e8252808f6e..15756528fdff942027cc166ab28fb30246453f89 100644 --- a/definitions/mha/mha_fp32_h16_d128_kvh16.json +++ b/definitions/mha/mha_bf16_h16_d128_kvh16.json @@ -1,5 +1,5 @@ { - "name": "mha_fp32_h16_d128_kvh16", + "name": "mha_bf16_h16_d128_kvh16", "op_type": "mha", "description": "MHA h=16 d=128 kv=16", "tags": [ @@ -34,7 +34,7 @@ "n_heads", "head_dim" ], - "dtype": "float32" + "dtype": "bfloat16" }, "K": { "shape": [ @@ -42,7 +42,7 @@ "kv_heads", "head_dim" ], - "dtype": "float32" + "dtype": "bfloat16" }, "V": { "shape": [ @@ -50,7 +50,7 @@ "kv_heads", "head_dim" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -64,5 +64,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(Q, K, V):\n M = Q.shape[0]; S = K.shape[0]\n K_e = K\n V_e = V\n Qt = Q.transpose(1, 0, 2)\n Kt = K_e.transpose(1, 0, 2)\n Vt = V_e.transpose(1, 0, 2)\n scores = np.matmul(Qt, Kt.transpose(0, 2, 1)) * 0.08838834764831845\n scores -= scores.max(-1, keepdims=True)\n probs = np.exp(scores)\n probs /= probs.sum(-1, keepdims=True)\n return np.matmul(probs, Vt).transpose(1, 0, 2)\n" + "reference": "import numpy as np\ndef run(Q, K, V):\n Q = Q.astype(np.float32)\n K = K.astype(np.float32)\n V = V.astype(np.float32)\n M = Q.shape[0]; S = K.shape[0]\n K_e = K\n V_e = V\n Qt = Q.transpose(1, 0, 2)\n Kt = K_e.transpose(1, 0, 2)\n Vt = V_e.transpose(1, 0, 2)\n scores = np.matmul(Qt, Kt.transpose(0, 2, 1)) * 0.08838834764831845\n scores -= scores.max(-1, keepdims=True)\n probs = np.exp(scores)\n probs /= probs.sum(-1, keepdims=True)\n return np.matmul(probs, Vt).transpose(1, 0, 2)\n" } diff --git a/definitions/moe/moe_fp32_e60_k4_d2048_ff1408.json b/definitions/moe/moe_bf16_e60_k4_d2048_ff1408.json similarity index 51% rename from definitions/moe/moe_fp32_e60_k4_d2048_ff1408.json rename to definitions/moe/moe_bf16_e60_k4_d2048_ff1408.json index 4ca60e765199a39e50f3121a83acde7ffdfce5a7..3831407eddf829316a243ad4e17726e42497baec 100644 --- a/definitions/moe/moe_fp32_e60_k4_d2048_ff1408.json +++ b/definitions/moe/moe_bf16_e60_k4_d2048_ff1408.json @@ -1,5 +1,5 @@ { - "name": "moe_fp32_e60_k4_d2048_ff1408", + "name": "moe_bf16_e60_k4_d2048_ff1408", "op_type": "moe", "description": "MoE e=60 k=4 d=2048 ff=1408", "tags": [ @@ -34,14 +34,14 @@ "n_tokens", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "router_weight": { "shape": [ "n_expert", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "gate_proj": { "shape": [ @@ -49,7 +49,7 @@ "n_ff", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "up_proj": { "shape": [ @@ -57,7 +57,7 @@ "n_ff", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "down_proj": { "shape": [ @@ -65,7 +65,7 @@ "n_embd", "n_ff" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -78,5 +78,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(hidden_states, router_weight, gate_proj, up_proj, down_proj):\n T = hidden_states.shape[0]\n logits = hidden_states @ router_weight.T\n probs = np.exp(logits - logits.max(-1, keepdims=True))\n probs /= probs.sum(-1, keepdims=True)\n top_idx = np.argsort(probs, axis=-1)[:, -4:]\n top_w = np.take_along_axis(probs, top_idx, axis=-1)\n top_w /= top_w.sum(-1, keepdims=True)\n out = np.zeros((T, 2048), dtype=np.float32)\n for t in range(T):\n for ki in range(4):\n e = top_idx[t, ki]\n g = gate_proj[e] @ hidden_states[t]\n u = up_proj[e] @ hidden_states[t]\n silu = g / (1 + np.exp(-g))\n out[t] += top_w[t, ki] * (down_proj[e] @ (silu * u))\n return out\n" + "reference": "import numpy as np\ndef run(hidden_states, router_weight, gate_proj, up_proj, down_proj):\n hidden_states = hidden_states.astype(np.float32)\n router_weight = router_weight.astype(np.float32)\n gate_proj = gate_proj.astype(np.float32)\n up_proj = up_proj.astype(np.float32)\n down_proj = down_proj.astype(np.float32)\n T = hidden_states.shape[0]\n logits = hidden_states @ router_weight.T\n probs = np.exp(logits - logits.max(-1, keepdims=True))\n probs /= probs.sum(-1, keepdims=True)\n top_idx = np.argsort(probs, axis=-1)[:, -4:]\n top_w = np.take_along_axis(probs, top_idx, axis=-1)\n top_w /= top_w.sum(-1, keepdims=True)\n out = np.zeros((T, 2048), dtype=np.float32)\n for t in range(T):\n for ki in range(4):\n e = top_idx[t, ki]\n g = gate_proj[e] @ hidden_states[t]\n u = up_proj[e] @ hidden_states[t]\n silu = g / (1 + np.exp(-g))\n out[t] += top_w[t, ki] * (down_proj[e] @ (silu * u))\n return out\n" } diff --git a/definitions/moe/moe_fp32_e64_k8_d2048_ff1024.json b/definitions/moe/moe_bf16_e64_k8_d2048_ff1024.json similarity index 51% rename from definitions/moe/moe_fp32_e64_k8_d2048_ff1024.json rename to definitions/moe/moe_bf16_e64_k8_d2048_ff1024.json index 10389955ec62b5434528d08797441a9a90e38073..90c84f233975491738879a80d711858de3fd7d79 100644 --- a/definitions/moe/moe_fp32_e64_k8_d2048_ff1024.json +++ b/definitions/moe/moe_bf16_e64_k8_d2048_ff1024.json @@ -1,5 +1,5 @@ { - "name": "moe_fp32_e64_k8_d2048_ff1024", + "name": "moe_bf16_e64_k8_d2048_ff1024", "op_type": "moe", "description": "MoE e=64 k=8 d=2048 ff=1024", "tags": [ @@ -34,14 +34,14 @@ "n_tokens", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "router_weight": { "shape": [ "n_expert", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "gate_proj": { "shape": [ @@ -49,7 +49,7 @@ "n_ff", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "up_proj": { "shape": [ @@ -57,7 +57,7 @@ "n_ff", "n_embd" ], - "dtype": "float32" + "dtype": "bfloat16" }, "down_proj": { "shape": [ @@ -65,7 +65,7 @@ "n_embd", "n_ff" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -78,5 +78,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(hidden_states, router_weight, gate_proj, up_proj, down_proj):\n T = hidden_states.shape[0]\n logits = hidden_states @ router_weight.T\n probs = np.exp(logits - logits.max(-1, keepdims=True))\n probs /= probs.sum(-1, keepdims=True)\n top_idx = np.argsort(probs, axis=-1)[:, -8:]\n top_w = np.take_along_axis(probs, top_idx, axis=-1)\n top_w /= top_w.sum(-1, keepdims=True)\n out = np.zeros((T, 2048), dtype=np.float32)\n for t in range(T):\n for ki in range(8):\n e = top_idx[t, ki]\n g = gate_proj[e] @ hidden_states[t]\n u = up_proj[e] @ hidden_states[t]\n silu = g / (1 + np.exp(-g))\n out[t] += top_w[t, ki] * (down_proj[e] @ (silu * u))\n return out\n" + "reference": "import numpy as np\ndef run(hidden_states, router_weight, gate_proj, up_proj, down_proj):\n hidden_states = hidden_states.astype(np.float32)\n router_weight = router_weight.astype(np.float32)\n gate_proj = gate_proj.astype(np.float32)\n up_proj = up_proj.astype(np.float32)\n down_proj = down_proj.astype(np.float32)\n T = hidden_states.shape[0]\n logits = hidden_states @ router_weight.T\n probs = np.exp(logits - logits.max(-1, keepdims=True))\n probs /= probs.sum(-1, keepdims=True)\n top_idx = np.argsort(probs, axis=-1)[:, -8:]\n top_w = np.take_along_axis(probs, top_idx, axis=-1)\n top_w /= top_w.sum(-1, keepdims=True)\n out = np.zeros((T, 2048), dtype=np.float32)\n for t in range(T):\n for ki in range(8):\n e = top_idx[t, ki]\n g = gate_proj[e] @ hidden_states[t]\n u = up_proj[e] @ hidden_states[t]\n silu = g / (1 + np.exp(-g))\n out[t] += top_w[t, ki] * (down_proj[e] @ (silu * u))\n return out\n" } diff --git a/definitions/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json b/definitions/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json new file mode 100644 index 0000000000000000000000000000000000000000..57d7173c020e1a0004a015c309f0aa6a8d70c474 --- /dev/null +++ b/definitions/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json @@ -0,0 +1,146 @@ +{ + "name": "moe_q4_k_m_e60_k4_d2048_ff1536", + "op_type": "moe", + "description": "MoE q4_k_m e=60 k=4 d=2048 ff=1536 (ff rounded up from 1408 to 1536, the next multiple of 256, since Q4_K requires the reduction dim divisible by 256; real GGML would fall back to Q5_0 for the unrounded 1408 shape on down_proj)", + "tags": [ + "status:active", + "model:qwen1.5-moe-a2.7b", + "baseline-solution:llama.cpp" + ], + "axes": { + "n_tokens": { + "type": "var" + }, + "n_embd": { + "type": "const", + "value": 2048 + }, + "n_ff": { + "type": "const", + "value": 1536 + }, + "n_expert": { + "type": "const", + "value": 60 + }, + "n_expert_used": { + "type": "const", + "value": 4 + }, + "n_embd_half": { + "type": "const", + "value": 1024 + }, + "n_embd_sub": { + "type": "const", + "value": 64 + }, + "n_ff_half": { + "type": "const", + "value": 768 + }, + "n_ff_sub": { + "type": "const", + "value": 48 + } + }, + "inputs": { + "hidden_states": { + "shape": [ + "n_tokens", + "n_embd" + ], + "dtype": "bfloat16" + }, + "router_weight": { + "shape": [ + "n_expert", + "n_embd" + ], + "dtype": "float32" + }, + "gate_proj_q4": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_half" + ], + "dtype": "uint8" + }, + "gate_proj_scales": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "gate_proj_mins": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "up_proj_q4": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_half" + ], + "dtype": "uint8" + }, + "up_proj_scales": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "up_proj_mins": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "down_proj_q4": { + "shape": [ + "n_expert", + "n_embd", + "n_ff_half" + ], + "dtype": "uint8" + }, + "down_proj_scales": { + "shape": [ + "n_expert", + "n_embd", + "n_ff_sub" + ], + "dtype": "float16" + }, + "down_proj_mins": { + "shape": [ + "n_expert", + "n_embd", + "n_ff_sub" + ], + "dtype": "float16" + } + }, + "outputs": { + "output": { + "shape": [ + "n_tokens", + "n_embd" + ], + "dtype": "float32" + } + }, + "constraints": [], + "reference": "import numpy as np\n\n\ndef dq4k(q4, scales, mins):\n K = q4.shape[-1] * 2\n lo = (q4 & 0x0F).astype(np.float32)\n hi = (q4 >> 4).astype(np.float32)\n nib = np.empty(q4.shape[:-1] + (K,), dtype=np.float32)\n nib[..., 0::2] = lo\n nib[..., 1::2] = hi\n s = np.repeat(scales.astype(np.float32), 32, axis=-1)\n m = np.repeat(mins.astype(np.float32), 32, axis=-1)\n return s * nib - m\n\n\ndef run(hidden_states, router_weight,\n gate_proj_q4, gate_proj_scales, gate_proj_mins,\n up_proj_q4, up_proj_scales, up_proj_mins,\n down_proj_q4, down_proj_scales, down_proj_mins):\n hs_f = hidden_states.astype(np.float32)\n T = hs_f.shape[0]\n logits = hs_f @ router_weight.astype(np.float32).T\n probs = np.exp(logits - logits.max(-1, keepdims=True))\n probs /= probs.sum(-1, keepdims=True)\n top_idx = np.argsort(probs, axis=-1)[:, -4:]\n top_w = np.take_along_axis(probs, top_idx, axis=-1)\n top_w /= top_w.sum(-1, keepdims=True)\n out = np.zeros((T, 2048), dtype=np.float32)\n for t in range(T):\n for ki in range(4):\n e = top_idx[t, ki]\n gp = dq4k(gate_proj_q4[e], gate_proj_scales[e], gate_proj_mins[e])\n up = dq4k(up_proj_q4[e], up_proj_scales[e], up_proj_mins[e])\n dn = dq4k(down_proj_q4[e], down_proj_scales[e], down_proj_mins[e])\n g = gp @ hs_f[t]; u = up @ hs_f[t]\n silu = g / (1 + np.exp(-g))\n out[t] += top_w[t, ki] * (dn @ (silu * u))\n return out\n" +} diff --git a/definitions/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json b/definitions/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json new file mode 100644 index 0000000000000000000000000000000000000000..7868fe7fd77f04bbdd091d16e05f1187608e3554 --- /dev/null +++ b/definitions/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json @@ -0,0 +1,146 @@ +{ + "name": "moe_q4_k_m_e64_k8_d2048_ff1024", + "op_type": "moe", + "description": "MoE q4_k_m e=64 k=8 d=2048 ff=1024", + "tags": [ + "status:active", + "model:olmoe-1b-7b", + "baseline-solution:llama.cpp" + ], + "axes": { + "n_tokens": { + "type": "var" + }, + "n_embd": { + "type": "const", + "value": 2048 + }, + "n_ff": { + "type": "const", + "value": 1024 + }, + "n_expert": { + "type": "const", + "value": 64 + }, + "n_expert_used": { + "type": "const", + "value": 8 + }, + "n_embd_half": { + "type": "const", + "value": 1024 + }, + "n_embd_sub": { + "type": "const", + "value": 64 + }, + "n_ff_half": { + "type": "const", + "value": 512 + }, + "n_ff_sub": { + "type": "const", + "value": 32 + } + }, + "inputs": { + "hidden_states": { + "shape": [ + "n_tokens", + "n_embd" + ], + "dtype": "bfloat16" + }, + "router_weight": { + "shape": [ + "n_expert", + "n_embd" + ], + "dtype": "float32" + }, + "gate_proj_q4": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_half" + ], + "dtype": "uint8" + }, + "gate_proj_scales": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "gate_proj_mins": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "up_proj_q4": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_half" + ], + "dtype": "uint8" + }, + "up_proj_scales": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "up_proj_mins": { + "shape": [ + "n_expert", + "n_ff", + "n_embd_sub" + ], + "dtype": "float16" + }, + "down_proj_q4": { + "shape": [ + "n_expert", + "n_embd", + "n_ff_half" + ], + "dtype": "uint8" + }, + "down_proj_scales": { + "shape": [ + "n_expert", + "n_embd", + "n_ff_sub" + ], + "dtype": "float16" + }, + "down_proj_mins": { + "shape": [ + "n_expert", + "n_embd", + "n_ff_sub" + ], + "dtype": "float16" + } + }, + "outputs": { + "output": { + "shape": [ + "n_tokens", + "n_embd" + ], + "dtype": "float32" + } + }, + "constraints": [], + "reference": "import numpy as np\n\n\ndef dq4k(q4, scales, mins):\n K = q4.shape[-1] * 2\n lo = (q4 & 0x0F).astype(np.float32)\n hi = (q4 >> 4).astype(np.float32)\n nib = np.empty(q4.shape[:-1] + (K,), dtype=np.float32)\n nib[..., 0::2] = lo\n nib[..., 1::2] = hi\n s = np.repeat(scales.astype(np.float32), 32, axis=-1)\n m = np.repeat(mins.astype(np.float32), 32, axis=-1)\n return s * nib - m\n\n\ndef run(hidden_states, router_weight,\n gate_proj_q4, gate_proj_scales, gate_proj_mins,\n up_proj_q4, up_proj_scales, up_proj_mins,\n down_proj_q4, down_proj_scales, down_proj_mins):\n hs_f = hidden_states.astype(np.float32)\n T = hs_f.shape[0]\n logits = hs_f @ router_weight.astype(np.float32).T\n probs = np.exp(logits - logits.max(-1, keepdims=True))\n probs /= probs.sum(-1, keepdims=True)\n top_idx = np.argsort(probs, axis=-1)[:, -8:]\n top_w = np.take_along_axis(probs, top_idx, axis=-1)\n top_w /= top_w.sum(-1, keepdims=True)\n out = np.zeros((T, 2048), dtype=np.float32)\n for t in range(T):\n for ki in range(8):\n e = top_idx[t, ki]\n gp = dq4k(gate_proj_q4[e], gate_proj_scales[e], gate_proj_mins[e])\n up = dq4k(up_proj_q4[e], up_proj_scales[e], up_proj_mins[e])\n dn = dq4k(down_proj_q4[e], down_proj_scales[e], down_proj_mins[e])\n g = gp @ hs_f[t]; u = up @ hs_f[t]\n silu = g / (1 + np.exp(-g))\n out[t] += top_w[t, ki] * (dn @ (silu * u))\n return out\n" +} diff --git a/definitions/rms_norm/rms_norm_fp32_d2048.json b/definitions/rms_norm/rms_norm_bf16_d2048.json similarity index 64% rename from definitions/rms_norm/rms_norm_fp32_d2048.json rename to definitions/rms_norm/rms_norm_bf16_d2048.json index a4517f7994c919a08f3b87ac43576cd9fed06e09..e2dfa0ea3a0ec2d4e9df7e5dc741a542b4168cbb 100644 --- a/definitions/rms_norm/rms_norm_fp32_d2048.json +++ b/definitions/rms_norm/rms_norm_bf16_d2048.json @@ -1,5 +1,5 @@ { - "name": "rms_norm_fp32_d2048", + "name": "rms_norm_bf16_d2048", "op_type": "rms_norm", "description": "RMSNorm D=2048", "tags": [ @@ -22,13 +22,13 @@ "M", "D" ], - "dtype": "float32" + "dtype": "bfloat16" }, "weight": { "shape": [ "D" ], - "dtype": "float32" + "dtype": "bfloat16" } }, "outputs": { @@ -41,5 +41,5 @@ } }, "constraints": [], - "reference": "import numpy as np\ndef run(x, weight):\n rms = np.sqrt(np.mean(x ** 2, axis=-1, keepdims=True) + 1e-6)\n return (x / rms) * weight\n" + "reference": "import numpy as np\ndef run(x, weight):\n x = x.astype(np.float32)\n weight = weight.astype(np.float32)\n rms = np.sqrt(np.mean(x ** 2, axis=-1, keepdims=True) + 1e-6)\n return (x / rms) * weight\n" } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n1024_k2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n1024_k2048.json similarity index 56% rename from solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n1024_k2048.json rename to solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n1024_k2048.json index 5f652c34b944df05831f9798af0b46695adc0a74..5335ea93575e7b15367d907d2da5aebfa1e680d3 100644 --- a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n1024_k2048.json +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n1024_k2048.json @@ -1,6 +1,6 @@ { - "name": "baseline-llamacpp-arm_gemm_fp32_n1024_k2048", - "definition": "gemm_fp32_n1024_k2048", + "name": "baseline-llamacpp-arm_gemm_bf16_n1024_k2048", + "definition": "gemm_bf16_n1024_k2048", "dataset": "llama.cpp", "author": "baseline-llamacpp-arm", "description": "llama.cpp (ggml) fp32 baseline for gemm_fp32_n1024_k2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", @@ -25,15 +25,15 @@ "sources": [ { "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For the bf16 variant, A and B are raw bf16 (uint16_t) bit patterns.\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" }, { "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1024;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1024;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B bf16 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" }, { "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_F32;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_BF16;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" } ] } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n1408_k2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n1408_k2048.json similarity index 56% rename from solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n1408_k2048.json rename to solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n1408_k2048.json index c607648cffed57f3cba8a2e8827c3cdf72bc475f..69ec306d4829a7c78d1f0a74dd4f1331e5cf894a 100644 --- a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n1408_k2048.json +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n1408_k2048.json @@ -1,6 +1,6 @@ { - "name": "baseline-llamacpp-arm_gemm_fp32_n1408_k2048", - "definition": "gemm_fp32_n1408_k2048", + "name": "baseline-llamacpp-arm_gemm_bf16_n1408_k2048", + "definition": "gemm_bf16_n1408_k2048", "dataset": "llama.cpp", "author": "baseline-llamacpp-arm", "description": "llama.cpp (ggml) fp32 baseline for gemm_fp32_n1408_k2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", @@ -25,15 +25,15 @@ "sources": [ { "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For the bf16 variant, A and B are raw bf16 (uint16_t) bit patterns.\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" }, { "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1408;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1408;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B bf16 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" }, { "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_F32;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_BF16;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" } ] } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k1024.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k1024.json similarity index 56% rename from solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k1024.json rename to solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k1024.json index af5a5ed8a25506b92bc349524b08f3a350c0d341..e3662f49f0397d71d69792c61e044de0593a0333 100644 --- a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k1024.json +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k1024.json @@ -1,6 +1,6 @@ { - "name": "baseline-llamacpp-arm_gemm_fp32_n2048_k1024", - "definition": "gemm_fp32_n2048_k1024", + "name": "baseline-llamacpp-arm_gemm_bf16_n2048_k1024", + "definition": "gemm_bf16_n2048_k1024", "dataset": "llama.cpp", "author": "baseline-llamacpp-arm", "description": "llama.cpp (ggml) fp32 baseline for gemm_fp32_n2048_k1024. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", @@ -25,15 +25,15 @@ "sources": [ { "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For the bf16 variant, A and B are raw bf16 (uint16_t) bit patterns.\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" }, { "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1024;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1024;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B bf16 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" }, { "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_F32;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_BF16;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" } ] } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k1408.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k1408.json similarity index 56% rename from solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k1408.json rename to solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k1408.json index 228ec07ca1eefbd2ca47d8b8fe6dce2def48dfc4..79ef1b03710a9c97eb11c2a10fc782621f36df08 100644 --- a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k1408.json +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k1408.json @@ -1,6 +1,6 @@ { - "name": "baseline-llamacpp-arm_gemm_fp32_n2048_k1408", - "definition": "gemm_fp32_n2048_k1408", + "name": "baseline-llamacpp-arm_gemm_bf16_n2048_k1408", + "definition": "gemm_bf16_n2048_k1408", "dataset": "llama.cpp", "author": "baseline-llamacpp-arm", "description": "llama.cpp (ggml) fp32 baseline for gemm_fp32_n2048_k1408. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", @@ -25,15 +25,15 @@ "sources": [ { "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For the bf16 variant, A and B are raw bf16 (uint16_t) bit patterns.\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" }, { "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1408;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1408;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B bf16 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" }, { "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_F32;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_BF16;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" } ] } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k2048.json similarity index 56% rename from solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k2048.json rename to solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k2048.json index 19329e0ee0fbb32b34b0a2942071a99b63d22e51..75f38a65f9e8ed23a3d3d7456698630aa8c2a514 100644 --- a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_fp32_n2048_k2048.json +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_bf16_n2048_k2048.json @@ -1,6 +1,6 @@ { - "name": "baseline-llamacpp-arm_gemm_fp32_n2048_k2048", - "definition": "gemm_fp32_n2048_k2048", + "name": "baseline-llamacpp-arm_gemm_bf16_n2048_k2048", + "definition": "gemm_bf16_n2048_k2048", "dataset": "llama.cpp", "author": "baseline-llamacpp-arm", "description": "llama.cpp (ggml) fp32 baseline for gemm_fp32_n2048_k2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", @@ -25,15 +25,15 @@ "sources": [ { "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A \u00b7 B^T row-major [M, N].\n// For the bf16 variant, A and B are raw bf16 (uint16_t) bit patterns.\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" }, { "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B bf16 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" }, { "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_F32;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// C = A \u00b7 B^T via ggml_mul_mat(B, A) \u2014 ggml computes result[n, m] =\n// B_row_n \u00b7 A_row_m over ne0=K, which in ggml's [ne0=N, ne1=M] layout is\n// exactly row-major C[M, N]. For q8_0 both operands are already in ggml\n// block_q8_0 layout, so mul_mat's vec_dot uses the supplied quantization\n// directly (src1->type == vec_dot_type \u2014 no re-quantization of A).\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8)\n{\n const ggml_type qt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_BF16;\n\n // Input tensors: metadata only, data points at the adapter-owned buffers.\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, qt, K, M);\n a->data = const_cast(A);\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, qt, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack (cplan work buffer, alignment)\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] \u2192 row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" } ] } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n1024_k2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n1024_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..3d9d9b189b8895fa5f6db62cdd40fd9dfe1094d6 --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n1024_k2048.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_gemm_q4_k_m_n1024_k2048", + "definition": "gemm_q4_k_m_n1024_k2048", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) Q4_K baseline for gemm_q4_k_m_n1024_k2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [], + "entry_point": "binding.cpp::armbench_entry_gemm" + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A . B^T row-major [M, N].\n// A is bf16 (raw uint16 bit pattern, one value per K element -- NOT\n// block-quantized; weight-only Q4_K design keeps activations at the bf16\n// baseline tier). B is a ggml block_q4_K row: (K/256) 144-byte blocks per\n// row, {fp16 d; fp16 dmin; uint8 scales[12]; uint8 qs[128]} (repacked by the\n// Python adapter from the flat nibble/scale/min Definition tensors).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1024;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B block_q4_K [N, K/256 blocks],\n// [2]=NULL (B_scales, consumed by adapter repack), [3]=NULL (B_mins);\n// var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n#include \n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\n// C = A . B^T via ggml_mul_mat(B, A). B is a real Q4_K weight tensor; A\n// arrives as bf16 and is widened to F32 up front (plain scalar loop, outside\n// ggml) because ggml_compute_forward_mul_mat asserts src1->type == F32\n// whenever src0 is a k-quant type (Q4_K's paired vec_dot_type is Q8_K, not\n// bf16 or Q4_K itself). ggml's own library code then dynamically quantizes\n// this F32 activation to Q8_K internally -- nothing else to write here.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A_bf16, const void* B, float* C,\n int64_t M, int64_t N, int64_t K)\n{\n std::vector A_f32((size_t)M * K);\n const uint16_t* a_bits = reinterpret_cast(A_bf16);\n for (size_t i = 0; i < A_f32.size(); ++i) A_f32[i] = bf16_to_f32(a_bits[i]);\n\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, K, M);\n a->data = A_f32.data();\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, GGML_TYPE_Q4_K, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + (size_t)M * K * sizeof(float) * 2 // cplan: A -> Q8_K scratch (generous)\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] -> row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n1408_k2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n1408_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..68ab7e31961423d0114d3d4f4f910468cc00307a --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n1408_k2048.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_gemm_q4_k_m_n1408_k2048", + "definition": "gemm_q4_k_m_n1408_k2048", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) Q4_K baseline for gemm_q4_k_m_n1408_k2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [], + "entry_point": "binding.cpp::armbench_entry_gemm" + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A . B^T row-major [M, N].\n// A is bf16 (raw uint16 bit pattern, one value per K element -- NOT\n// block-quantized; weight-only Q4_K design keeps activations at the bf16\n// baseline tier). B is a ggml block_q4_K row: (K/256) 144-byte blocks per\n// row, {fp16 d; fp16 dmin; uint8 scales[12]; uint8 qs[128]} (repacked by the\n// Python adapter from the flat nibble/scale/min Definition tensors).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1408;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B block_q4_K [N, K/256 blocks],\n// [2]=NULL (B_scales, consumed by adapter repack), [3]=NULL (B_mins);\n// var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n#include \n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\n// C = A . B^T via ggml_mul_mat(B, A). B is a real Q4_K weight tensor; A\n// arrives as bf16 and is widened to F32 up front (plain scalar loop, outside\n// ggml) because ggml_compute_forward_mul_mat asserts src1->type == F32\n// whenever src0 is a k-quant type (Q4_K's paired vec_dot_type is Q8_K, not\n// bf16 or Q4_K itself). ggml's own library code then dynamically quantizes\n// this F32 activation to Q8_K internally -- nothing else to write here.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A_bf16, const void* B, float* C,\n int64_t M, int64_t N, int64_t K)\n{\n std::vector A_f32((size_t)M * K);\n const uint16_t* a_bits = reinterpret_cast(A_bf16);\n for (size_t i = 0; i < A_f32.size(); ++i) A_f32[i] = bf16_to_f32(a_bits[i]);\n\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, K, M);\n a->data = A_f32.data();\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, GGML_TYPE_Q4_K, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + (size_t)M * K * sizeof(float) * 2 // cplan: A -> Q8_K scratch (generous)\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] -> row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k1024.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k1024.json new file mode 100644 index 0000000000000000000000000000000000000000..9b34902e7119193848f73c496c7d59ced77752bd --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k1024.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_gemm_q4_k_m_n2048_k1024", + "definition": "gemm_q4_k_m_n2048_k1024", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) Q4_K baseline for gemm_q4_k_m_n2048_k1024. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [], + "entry_point": "binding.cpp::armbench_entry_gemm" + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A . B^T row-major [M, N].\n// A is bf16 (raw uint16 bit pattern, one value per K element -- NOT\n// block-quantized; weight-only Q4_K design keeps activations at the bf16\n// baseline tier). B is a ggml block_q4_K row: (K/256) 144-byte blocks per\n// row, {fp16 d; fp16 dmin; uint8 scales[12]; uint8 qs[128]} (repacked by the\n// Python adapter from the flat nibble/scale/min Definition tensors).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1024;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B block_q4_K [N, K/256 blocks],\n// [2]=NULL (B_scales, consumed by adapter repack), [3]=NULL (B_mins);\n// var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n#include \n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\n// C = A . B^T via ggml_mul_mat(B, A). B is a real Q4_K weight tensor; A\n// arrives as bf16 and is widened to F32 up front (plain scalar loop, outside\n// ggml) because ggml_compute_forward_mul_mat asserts src1->type == F32\n// whenever src0 is a k-quant type (Q4_K's paired vec_dot_type is Q8_K, not\n// bf16 or Q4_K itself). ggml's own library code then dynamically quantizes\n// this F32 activation to Q8_K internally -- nothing else to write here.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A_bf16, const void* B, float* C,\n int64_t M, int64_t N, int64_t K)\n{\n std::vector A_f32((size_t)M * K);\n const uint16_t* a_bits = reinterpret_cast(A_bf16);\n for (size_t i = 0; i < A_f32.size(); ++i) A_f32[i] = bf16_to_f32(a_bits[i]);\n\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, K, M);\n a->data = A_f32.data();\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, GGML_TYPE_Q4_K, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + (size_t)M * K * sizeof(float) * 2 // cplan: A -> Q8_K scratch (generous)\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] -> row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k1536.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k1536.json new file mode 100644 index 0000000000000000000000000000000000000000..7ad6719c0d90adff6a81d615684e4246ac7e2fbd --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k1536.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_gemm_q4_k_m_n2048_k1536", + "definition": "gemm_q4_k_m_n2048_k1536", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) Q4_K baseline for gemm_q4_k_m_n2048_k1536. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [], + "entry_point": "binding.cpp::armbench_entry_gemm" + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A . B^T row-major [M, N].\n// A is bf16 (raw uint16 bit pattern, one value per K element -- NOT\n// block-quantized; weight-only Q4_K design keeps activations at the bf16\n// baseline tier). B is a ggml block_q4_K row: (K/256) 144-byte blocks per\n// row, {fp16 d; fp16 dmin; uint8 scales[12]; uint8 qs[128]} (repacked by the\n// Python adapter from the flat nibble/scale/min Definition tensors).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1536;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B block_q4_K [N, K/256 blocks],\n// [2]=NULL (B_scales, consumed by adapter repack), [3]=NULL (B_mins);\n// var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n#include \n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\n// C = A . B^T via ggml_mul_mat(B, A). B is a real Q4_K weight tensor; A\n// arrives as bf16 and is widened to F32 up front (plain scalar loop, outside\n// ggml) because ggml_compute_forward_mul_mat asserts src1->type == F32\n// whenever src0 is a k-quant type (Q4_K's paired vec_dot_type is Q8_K, not\n// bf16 or Q4_K itself). ggml's own library code then dynamically quantizes\n// this F32 activation to Q8_K internally -- nothing else to write here.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A_bf16, const void* B, float* C,\n int64_t M, int64_t N, int64_t K)\n{\n std::vector A_f32((size_t)M * K);\n const uint16_t* a_bits = reinterpret_cast(A_bf16);\n for (size_t i = 0; i < A_f32.size(); ++i) A_f32[i] = bf16_to_f32(a_bits[i]);\n\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, K, M);\n a->data = A_f32.data();\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, GGML_TYPE_Q4_K, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + (size_t)M * K * sizeof(float) * 2 // cplan: A -> Q8_K scratch (generous)\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] -> row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..91687683ed2c44d8be2a97ccc41c7b8ffe518dbb --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/gemm/gemm_q4_k_m_n2048_k2048.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_gemm_q4_k_m_n2048_k2048", + "definition": "gemm_q4_k_m_n2048_k2048", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) Q4_K baseline for gemm_q4_k_m_n2048_k2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_gemm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [], + "entry_point": "binding.cpp::armbench_entry_gemm" + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A . B^T row-major [M, N].\n// A is bf16 (raw uint16 bit pattern, one value per K element -- NOT\n// block-quantized; weight-only Q4_K design keeps activations at the bf16\n// baseline tier). B is a ggml block_q4_K row: (K/256) 144-byte blocks per\n// row, {fp16 d; fp16 dmin; uint8 scales[12]; uint8 qs[128]} (repacked by the\n// Python adapter from the flat nibble/scale/min Definition tensors).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A bf16 [M,K], [1]=B block_q4_K [N, K/256 blocks],\n// [2]=NULL (B_scales, consumed by adapter repack), [3]=NULL (B_mins);\n// var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"gemm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n#include \n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\n// C = A . B^T via ggml_mul_mat(B, A). B is a real Q4_K weight tensor; A\n// arrives as bf16 and is widened to F32 up front (plain scalar loop, outside\n// ggml) because ggml_compute_forward_mul_mat asserts src1->type == F32\n// whenever src0 is a k-quant type (Q4_K's paired vec_dot_type is Q8_K, not\n// bf16 or Q4_K itself). ggml's own library code then dynamically quantizes\n// this F32 activation to Q8_K internally -- nothing else to write here.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_gemm(const void* A_bf16, const void* B, float* C,\n int64_t M, int64_t N, int64_t K)\n{\n std::vector A_f32((size_t)M * K);\n const uint16_t* a_bits = reinterpret_cast(A_bf16);\n for (size_t i = 0; i < A_f32.size(); ++i) A_f32[i] = bf16_to_f32(a_bits[i]);\n\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* a = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, K, M);\n a->data = A_f32.data();\n ggml_tensor* b = ggml_new_tensor_2d(ctx_in, GGML_TYPE_Q4_K, K, N);\n b->data = const_cast(B);\n\n const size_t mem =\n (size_t)N * M * sizeof(float) // C\n + (size_t)M * K * sizeof(float) * 2 // cplan: A -> Q8_K scratch (generous)\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20); // slack\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* c = ggml_mul_mat(ctx, b, a); // [N, M] -> row-major [M, N]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, c);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(C, c->data, (size_t)N * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/mha/mha_bf16_h16_d128_kvh16.json b/solutions/llama.cpp/baseline-llamacpp-arm/mha/mha_bf16_h16_d128_kvh16.json new file mode 100644 index 0000000000000000000000000000000000000000..c4159c609b68bad7e2f0c8885d4cfd1990d304ff --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/mha/mha_bf16_h16_d128_kvh16.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_mha_bf16_h16_d128_kvh16", + "definition": "mha_bf16_h16_d128_kvh16", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) fp32 baseline for mha_fp32_h16_d128_kvh16. binding.cpp bakes the const axes as constexpr and implements armbench_entry_mha over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "entry_point": "binding.cpp::armbench_entry_mha", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "mha.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) mha baseline.\n// Called by armbench_entry_mha (binding.cpp); implemented by kernel.cpp.\n// Q is row-major bf16 [M, n_heads, head_dim]; K/V are row-major bf16\n// [S, kv_heads, head_dim]; out is row-major fp32 [M, n_heads, head_dim].\n// Non-causal softmax(Q\u00b7K^T / sqrt(head_dim))\u00b7V per head.\nint armbench_llamacpp_mha(const void* Q, const void* K, const void* V,\n float* out, int64_t M, int64_t S,\n int64_t n_heads, int64_t head_dim, int64_t kv_heads);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"mha.h\"\n\nnamespace {\nconstexpr int64_t kNHeads = 16;\nconstexpr int64_t kHeadDim = 128;\nconstexpr int64_t kKvHeads = 16;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=Q bf16 [M,n_heads,head_dim], [1]=K bf16 [S,kv_heads,head_dim],\n// [2]=V bf16 [S,kv_heads,head_dim]; var_axes: [0]=M, [1]=S\nint armbench_entry_mha(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_mha(\n inputs[0],\n inputs[1],\n inputs[2],\n reinterpret_cast(output),\n var_axes[0], var_axes[1], kNHeads, kHeadDim, kKvHeads);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"mha.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n\n// The non-flash attention path from llama.cpp's build_attn_mha:\n// kq = ggml_mul_mat(k, q) // [S, M, h]\n// kq = ggml_soft_max_ext(kq, mask=null, 1/sqrt(d), 0) // non-causal\n// kqv = ggml_mul_mat(cont(permute(v)), kq) // [d, M, h]\n// out = cont(permute(kqv)) // [d, h, M] = row-major [M, h, d]\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_mha(const void* Q, const void* K, const void* V,\n float* out, int64_t M, int64_t S,\n int64_t n_heads, int64_t head_dim, int64_t kv_heads)\n{\n const int64_t d = head_dim, h = n_heads, kvh = kv_heads;\n\n ggml_init_params ip_in = { 6 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n // ggml ne order is reversed vs numpy: [M, h, d] row-major \u2192 ne = [d, h, M].\n ggml_tensor* q = ggml_new_tensor_3d(ctx_in, GGML_TYPE_BF16, d, h, M);\n q->data = const_cast(Q);\n ggml_tensor* k = ggml_new_tensor_3d(ctx_in, GGML_TYPE_BF16, d, kvh, S);\n k->data = const_cast(K);\n ggml_tensor* v = ggml_new_tensor_3d(ctx_in, GGML_TYPE_BF16, d, kvh, S);\n v->data = const_cast(V);\n\n const size_t mem =\n 2 * (size_t)S * M * h * sizeof(float) // kq + softmax\n + (size_t)S * d * kvh * sizeof(float) // v transposed (cont)\n + 2 * (size_t)d * M * h * sizeof(float) // kqv + merged\n + 32 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* qp = ggml_permute(ctx, q, 0, 2, 1, 3); // [d, M, h]\n ggml_tensor* kp = ggml_permute(ctx, k, 0, 2, 1, 3); // [d, S, kvh]\n ggml_tensor* kq = ggml_mul_mat(ctx, kp, qp); // [S, M, h]\n kq = ggml_soft_max_ext(ctx, kq, nullptr,\n 1.0f / sqrtf((float)d), 0.0f); // non-causal\n ggml_tensor* vp = ggml_cont(ctx, ggml_permute(ctx, v, 1, 2, 0, 3)); // [S, d, kvh]\n ggml_tensor* kqv = ggml_mul_mat(ctx, vp, kq); // [d, M, h]\n ggml_tensor* merged =\n ggml_cont(ctx, ggml_permute(ctx, kqv, 0, 2, 1, 3)); // [d, h, M]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, merged);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, merged->data, (size_t)d * h * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/mha/mha_fp32_h16_d128_kvh16.json b/solutions/llama.cpp/baseline-llamacpp-arm/mha/mha_fp32_h16_d128_kvh16.json deleted file mode 100644 index b1ac2bfd6c2936e562cb04e8b596670b8dc5af32..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/baseline-llamacpp-arm/mha/mha_fp32_h16_d128_kvh16.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "baseline-llamacpp-arm_mha_fp32_h16_d128_kvh16", - "definition": "mha_fp32_h16_d128_kvh16", - "dataset": "llama.cpp", - "author": "baseline-llamacpp-arm", - "description": "llama.cpp (ggml) fp32 baseline for mha_fp32_h16_d128_kvh16. binding.cpp bakes the const axes as constexpr and implements armbench_entry_mha over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", - "spec": { - "language": "cpp", - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_mha", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O3", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "mha.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) mha baseline.\n// Called by armbench_entry_mha (binding.cpp); implemented by kernel.cpp.\n// Q is row-major fp32 [M, n_heads, head_dim]; K/V are row-major fp32\n// [S, kv_heads, head_dim]; out is row-major fp32 [M, n_heads, head_dim].\n// Non-causal softmax(Q\u00b7K^T / sqrt(head_dim))\u00b7V per head.\nint armbench_llamacpp_mha(const float* Q, const float* K, const float* V,\n float* out, int64_t M, int64_t S,\n int64_t n_heads, int64_t head_dim, int64_t kv_heads);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"mha.h\"\n\nnamespace {\nconstexpr int64_t kNHeads = 16;\nconstexpr int64_t kHeadDim = 128;\nconstexpr int64_t kKvHeads = 16;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=Q fp32 [M,n_heads,head_dim], [1]=K fp32 [S,kv_heads,head_dim],\n// [2]=V fp32 [S,kv_heads,head_dim]; var_axes: [0]=M, [1]=S\nint armbench_entry_mha(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_mha(\n reinterpret_cast(inputs[0]),\n reinterpret_cast(inputs[1]),\n reinterpret_cast(inputs[2]),\n reinterpret_cast(output),\n var_axes[0], var_axes[1], kNHeads, kHeadDim, kKvHeads);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"mha.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n\n// The non-flash attention path from llama.cpp's build_attn_mha:\n// kq = ggml_mul_mat(k, q) // [S, M, h]\n// kq = ggml_soft_max_ext(kq, mask=null, 1/sqrt(d), 0) // non-causal\n// kqv = ggml_mul_mat(cont(permute(v)), kq) // [d, M, h]\n// out = cont(permute(kqv)) // [d, h, M] = row-major [M, h, d]\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_mha(const float* Q, const float* K, const float* V,\n float* out, int64_t M, int64_t S,\n int64_t n_heads, int64_t head_dim, int64_t kv_heads)\n{\n const int64_t d = head_dim, h = n_heads, kvh = kv_heads;\n\n ggml_init_params ip_in = { 6 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n // ggml ne order is reversed vs numpy: [M, h, d] row-major \u2192 ne = [d, h, M].\n ggml_tensor* q = ggml_new_tensor_3d(ctx_in, GGML_TYPE_F32, d, h, M);\n q->data = const_cast(Q);\n ggml_tensor* k = ggml_new_tensor_3d(ctx_in, GGML_TYPE_F32, d, kvh, S);\n k->data = const_cast(K);\n ggml_tensor* v = ggml_new_tensor_3d(ctx_in, GGML_TYPE_F32, d, kvh, S);\n v->data = const_cast(V);\n\n const size_t mem =\n 2 * (size_t)S * M * h * sizeof(float) // kq + softmax\n + (size_t)S * d * kvh * sizeof(float) // v transposed (cont)\n + 2 * (size_t)d * M * h * sizeof(float) // kqv + merged\n + 32 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* qp = ggml_permute(ctx, q, 0, 2, 1, 3); // [d, M, h]\n ggml_tensor* kp = ggml_permute(ctx, k, 0, 2, 1, 3); // [d, S, kvh]\n ggml_tensor* kq = ggml_mul_mat(ctx, kp, qp); // [S, M, h]\n kq = ggml_soft_max_ext(ctx, kq, nullptr,\n 1.0f / sqrtf((float)d), 0.0f); // non-causal\n ggml_tensor* vp = ggml_cont(ctx, ggml_permute(ctx, v, 1, 2, 0, 3)); // [S, d, kvh]\n ggml_tensor* kqv = ggml_mul_mat(ctx, vp, kq); // [d, M, h]\n ggml_tensor* merged =\n ggml_cont(ctx, ggml_permute(ctx, kqv, 0, 2, 1, 3)); // [d, h, M]\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, merged);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, merged->data, (size_t)d * h * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" - } - ] -} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_fp32_e60_k4_d2048_ff1408.json b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_bf16_e60_k4_d2048_ff1408.json similarity index 79% rename from solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_fp32_e60_k4_d2048_ff1408.json rename to solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_bf16_e60_k4_d2048_ff1408.json index b9346070bfb68efd9d65147d9bfeecb684ac17d2..c60cd7398bbd1532d5e1db198d86c8baca44fb3f 100644 --- a/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_fp32_e60_k4_d2048_ff1408.json +++ b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_bf16_e60_k4_d2048_ff1408.json @@ -1,6 +1,6 @@ { - "name": "baseline-llamacpp-arm_moe_fp32_e60_k4_d2048_ff1408", - "definition": "moe_fp32_e60_k4_d2048_ff1408", + "name": "baseline-llamacpp-arm_moe_bf16_e60_k4_d2048_ff1408", + "definition": "moe_bf16_e60_k4_d2048_ff1408", "dataset": "llama.cpp", "author": "baseline-llamacpp-arm", "description": "llama.cpp (ggml) fp32 baseline for moe_fp32_e60_k4_d2048_ff1408. binding.cpp bakes the const axes as constexpr and implements armbench_entry_moe over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", @@ -25,15 +25,15 @@ "sources": [ { "path": "moe.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major [T, n_embd]; router_weight fp32 [n_expert, n_embd];\n// gate/up_proj [n_expert, n_ff, n_embd]; down_proj [n_expert, n_embd, n_ff];\n// out fp32 [T, n_embd]. For q8_0, hidden_states and the three projections are\n// ggml block_q8_0 rows over their last axis (34-byte {fp16 d; int8 qs[32]}\n// blocks, repacked by the Python adapter); router_weight stays fp32.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8);\n" + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major bf16 [T, n_embd]; router_weight bf16 [n_expert, n_embd];\n// gate/up_proj bf16 [n_expert, n_ff, n_embd]; down_proj bf16 [n_expert, n_embd, n_ff];\n// out fp32 [T, n_embd]. For q8_0, hidden_states and the three projections are\n// ggml block_q8_0 rows over their last axis (34-byte {fp16 d; int8 qs[32]}\n// blocks, repacked by the Python adapter); router_weight stays fp32 there.\nint armbench_llamacpp_moe(const void* hidden_states, const void* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8);\n" }, { "path": "binding.cpp", - "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1408;\nconstexpr int64_t kNExpert = 60;\nconstexpr int64_t kNExpertUsed = 4;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=hidden_states fp32 [T,n_embd], [1]=router_weight fp32\n// [n_expert,n_embd], [2]=gate_proj fp32 [n_expert,n_ff,n_embd], [3]=up_proj\n// fp32 [n_expert,n_ff,n_embd], [4]=down_proj fp32 [n_expert,n_embd,n_ff];\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n reinterpret_cast(inputs[1]),\n inputs[2], inputs[3], inputs[4],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed, /*is_q8=*/false);\n}\n} // extern \"C\"\n" + "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1408;\nconstexpr int64_t kNExpert = 60;\nconstexpr int64_t kNExpertUsed = 4;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=hidden_states bf16 [T,n_embd], [1]=router_weight bf16\n// [n_expert,n_embd], [2]=gate_proj bf16 [n_expert,n_ff,n_embd], [3]=up_proj\n// bf16 [n_expert,n_ff,n_embd], [4]=down_proj bf16 [n_expert,n_embd,n_ff];\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n inputs[1],\n inputs[2], inputs[3], inputs[4],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed, /*is_q8=*/false);\n}\n} // extern \"C\"\n" }, { "path": "kernel.cpp", - "content": "#include \"moe.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\nnamespace {\n\n// Dequantize block_q8_0 rows (34-byte {fp16 d; int8 qs[32]} blocks) to fp32.\n// Used only for the router matmul input in the q8_0 variant \u2014 the reference\n// routes on the dequantized hidden states while the expert matmuls consume the\n// original quantization.\nvoid dequant_q8_0_rows(const void* src, float* dst, int64_t rows, int64_t k)\n{\n const int64_t nb = k / 32;\n const uint8_t* p = reinterpret_cast(src);\n for (int64_t r = 0; r < rows; ++r) {\n const uint8_t* rp = p + (size_t)r * nb * 34;\n float* dp = dst + (size_t)r * k;\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = rp + (size_t)b * 34;\n uint16_t dbits;\n std::memcpy(&dbits, bp, sizeof(dbits));\n const float d = ggml_fp16_to_fp32(dbits);\n const int8_t* qs = reinterpret_cast(bp + 2);\n for (int j = 0; j < 32; ++j) dp[b * 32 + j] = d * (float)qs[j];\n }\n }\n}\n\n} // namespace\n\n// The build_moe_ffn sequence from llama.cpp (SOFTMAX gating + norm_w, the\n// qwen1.5-moe / olmoe configuration): softmax over all experts \u2192\n// ggml_argsort_top_k \u2192 ggml_get_rows \u2192 weight renorm \u2192 ggml_mul_mat_id\n// gate/up \u2192 silu\u00b7up \u2192 ggml_mul_mat_id down \u2192 weight and sum the expert views.\n//\n// For q8_0, gate/up consume the pre-quantized hidden states directly\n// (src1->type == vec_dot_type, so ggml does NOT re-quantize them); the down\n// projection's fp32 intermediate is quantized to q8_0 by ggml internally \u2014\n// that is llama.cpp's real inference behavior and the one place this baseline\n// deviates from the fp32-intermediate numpy reference.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8)\n{\n const int64_t T = n_tokens, d = n_embd, ff = n_ff;\n const int64_t e = n_expert, k = n_expert_used;\n const ggml_type wt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_F32;\n const size_t f = sizeof(float);\n\n ggml_init_params ip_in = { 8 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* hs = ggml_new_tensor_2d(ctx_in, wt, d, T);\n hs->data = const_cast(hidden_states);\n ggml_tensor* router = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, d, e);\n router->data = const_cast(router_weight);\n ggml_tensor* gate = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n gate->data = const_cast(gate_proj);\n ggml_tensor* up = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n up->data = const_cast(up_proj);\n ggml_tensor* down = ggml_new_tensor_3d(ctx_in, wt, ff, d, e);\n down->data = const_cast(down_proj);\n\n size_t mem = 0;\n mem += 3 * (size_t)e * T * f; // logits + probs + argsort indices\n mem += 8 * (size_t)k * T * f; // selected ids, weights, sums, renorm\n mem += 4 * (size_t)ff * k * T * f; // gate, up, silu, gated product\n mem += 2 * (size_t)d * k * T * f; // expert outputs + weighted\n mem += (size_t)k * d * T * f; // expert-sum add chain\n if (is_q8) {\n mem += (size_t)d * T * f; // dequantized hidden states\n mem += (size_t)ff * k * T * 34 / 32 + 64; // cplan: down-proj src1 \u2192 q8_0\n }\n mem += (size_t)e * ((size_t)k * T * 16 + 256); // cplan: mul_mat_id row maps\n mem += 64 * ggml_tensor_overhead() + ggml_graph_overhead();\n mem += (4u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n // Router input: fp32 hidden states (dequantized for the q8_0 variant).\n ggml_tensor* cur_f;\n if (is_q8) {\n cur_f = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, d, T);\n dequant_q8_0_rows(hidden_states, reinterpret_cast(cur_f->data), T, d);\n } else {\n cur_f = hs;\n }\n\n ggml_tensor* logits = ggml_mul_mat(ctx, router, cur_f); // [e, T]\n ggml_tensor* probs = ggml_soft_max(ctx, logits); // [e, T]\n ggml_tensor* sel = ggml_argsort_top_k(ctx, probs, k); // [k, T] i32\n\n ggml_tensor* weights =\n ggml_get_rows(ctx, ggml_reshape_3d(ctx, probs, 1, e, T), sel); // [1, k, T]\n weights = ggml_reshape_2d(ctx, weights, k, T);\n ggml_tensor* wsum = ggml_sum_rows(ctx, weights); // [1, T]\n weights = ggml_div(ctx, weights, wsum); // renormalize\n weights = ggml_reshape_3d(ctx, weights, 1, k, T);\n\n // Expert matmuls consume the supplied quantization directly for q8_0.\n ggml_tensor* cur = ggml_reshape_3d(ctx, is_q8 ? hs : cur_f, d, 1, T);\n ggml_tensor* g = ggml_mul_mat_id(ctx, gate, cur, sel); // [ff, k, T]\n ggml_tensor* u = ggml_mul_mat_id(ctx, up, cur, sel); // [ff, k, T]\n ggml_tensor* par = ggml_mul(ctx, ggml_silu(ctx, g), u); // [ff, k, T]\n ggml_tensor* experts = ggml_mul_mat_id(ctx, down, par, sel); // [d, k, T]\n experts = ggml_mul(ctx, experts, weights);\n\n // Sum over the k expert slots (view + add chain, as in build_moe_ffn).\n ggml_tensor* moe_out = ggml_view_2d(ctx, experts, d, T, experts->nb[2], 0);\n for (int64_t i = 1; i < k; ++i) {\n moe_out = ggml_add(\n ctx, moe_out,\n ggml_view_2d(ctx, experts, d, T, experts->nb[2], i * experts->nb[1]));\n }\n if (k == 1) moe_out = ggml_cont(ctx, moe_out);\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, moe_out);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, moe_out->data, (size_t)d * T * f);\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + "content": "#include \"moe.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\nnamespace {\n\n// Dequantize block_q8_0 rows (34-byte {fp16 d; int8 qs[32]} blocks) to fp32.\n// Used only for the router matmul input in the q8_0 variant \u2014 the reference\n// routes on the dequantized hidden states while the expert matmuls consume the\n// original quantization.\nvoid dequant_q8_0_rows(const void* src, float* dst, int64_t rows, int64_t k)\n{\n const int64_t nb = k / 32;\n const uint8_t* p = reinterpret_cast(src);\n for (int64_t r = 0; r < rows; ++r) {\n const uint8_t* rp = p + (size_t)r * nb * 34;\n float* dp = dst + (size_t)r * k;\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = rp + (size_t)b * 34;\n uint16_t dbits;\n std::memcpy(&dbits, bp, sizeof(dbits));\n const float d = ggml_fp16_to_fp32(dbits);\n const int8_t* qs = reinterpret_cast(bp + 2);\n for (int j = 0; j < 32; ++j) dp[b * 32 + j] = d * (float)qs[j];\n }\n }\n}\n\n} // namespace\n\n// The build_moe_ffn sequence from llama.cpp (SOFTMAX gating + norm_w, the\n// qwen1.5-moe / olmoe configuration): softmax over all experts \u2192\n// ggml_argsort_top_k \u2192 ggml_get_rows \u2192 weight renorm \u2192 ggml_mul_mat_id\n// gate/up \u2192 silu\u00b7up \u2192 ggml_mul_mat_id down \u2192 weight and sum the expert views.\n//\n// For q8_0, gate/up consume the pre-quantized hidden states directly\n// (src1->type == vec_dot_type, so ggml does NOT re-quantize them); the down\n// projection's fp32 intermediate is quantized to q8_0 by ggml internally \u2014\n// that is llama.cpp's real inference behavior and the one place this baseline\n// deviates from the fp32-intermediate numpy reference.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_moe(const void* hidden_states, const void* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8)\n{\n const int64_t T = n_tokens, d = n_embd, ff = n_ff;\n const int64_t e = n_expert, k = n_expert_used;\n const ggml_type wt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_BF16;\n const size_t f = sizeof(float);\n\n ggml_init_params ip_in = { 8 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* hs = ggml_new_tensor_2d(ctx_in, wt, d, T);\n hs->data = const_cast(hidden_states);\n ggml_tensor* router = ggml_new_tensor_2d(ctx_in, GGML_TYPE_BF16, d, e);\n router->data = const_cast(router_weight);\n ggml_tensor* gate = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n gate->data = const_cast(gate_proj);\n ggml_tensor* up = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n up->data = const_cast(up_proj);\n ggml_tensor* down = ggml_new_tensor_3d(ctx_in, wt, ff, d, e);\n down->data = const_cast(down_proj);\n\n size_t mem = 0;\n mem += 3 * (size_t)e * T * f; // logits + probs + argsort indices\n mem += 8 * (size_t)k * T * f; // selected ids, weights, sums, renorm\n mem += 4 * (size_t)ff * k * T * f; // gate, up, silu, gated product\n mem += 2 * (size_t)d * k * T * f; // expert outputs + weighted\n mem += (size_t)k * d * T * f; // expert-sum add chain\n if (is_q8) {\n mem += (size_t)d * T * f; // dequantized hidden states\n mem += (size_t)ff * k * T * 34 / 32 + 64; // cplan: down-proj src1 \u2192 q8_0\n }\n mem += (size_t)e * ((size_t)k * T * 16 + 256); // cplan: mul_mat_id row maps\n mem += 64 * ggml_tensor_overhead() + ggml_graph_overhead();\n mem += (4u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n // Router input: fp32 hidden states (dequantized for the q8_0 variant).\n ggml_tensor* cur_f;\n if (is_q8) {\n cur_f = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, d, T);\n dequant_q8_0_rows(hidden_states, reinterpret_cast(cur_f->data), T, d);\n } else {\n cur_f = hs;\n }\n\n ggml_tensor* logits = ggml_mul_mat(ctx, router, cur_f); // [e, T]\n ggml_tensor* probs = ggml_soft_max(ctx, logits); // [e, T]\n ggml_tensor* sel = ggml_argsort_top_k(ctx, probs, k); // [k, T] i32\n\n ggml_tensor* weights =\n ggml_get_rows(ctx, ggml_reshape_3d(ctx, probs, 1, e, T), sel); // [1, k, T]\n weights = ggml_reshape_2d(ctx, weights, k, T);\n ggml_tensor* wsum = ggml_sum_rows(ctx, weights); // [1, T]\n weights = ggml_div(ctx, weights, wsum); // renormalize\n weights = ggml_reshape_3d(ctx, weights, 1, k, T);\n\n // Expert matmuls consume the supplied quantization directly for q8_0.\n ggml_tensor* cur = ggml_reshape_3d(ctx, is_q8 ? hs : cur_f, d, 1, T);\n ggml_tensor* g = ggml_mul_mat_id(ctx, gate, cur, sel); // [ff, k, T]\n ggml_tensor* u = ggml_mul_mat_id(ctx, up, cur, sel); // [ff, k, T]\n ggml_tensor* par = ggml_mul(ctx, ggml_silu(ctx, g), u); // [ff, k, T]\n ggml_tensor* experts = ggml_mul_mat_id(ctx, down, par, sel); // [d, k, T]\n experts = ggml_mul(ctx, experts, weights);\n\n // Sum over the k expert slots (view + add chain, as in build_moe_ffn).\n ggml_tensor* moe_out = ggml_view_2d(ctx, experts, d, T, experts->nb[2], 0);\n for (int64_t i = 1; i < k; ++i) {\n moe_out = ggml_add(\n ctx, moe_out,\n ggml_view_2d(ctx, experts, d, T, experts->nb[2], i * experts->nb[1]));\n }\n if (k == 1) moe_out = ggml_cont(ctx, moe_out);\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, moe_out);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, moe_out->data, (size_t)d * T * f);\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" } ] } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_fp32_e64_k8_d2048_ff1024.json b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_bf16_e64_k8_d2048_ff1024.json similarity index 79% rename from solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_fp32_e64_k8_d2048_ff1024.json rename to solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_bf16_e64_k8_d2048_ff1024.json index d249d7d056187f40672bb52088055c14ec8a91cc..a11bad12365b4af7e822b9ecb672f267e86cb7d3 100644 --- a/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_fp32_e64_k8_d2048_ff1024.json +++ b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_bf16_e64_k8_d2048_ff1024.json @@ -1,6 +1,6 @@ { - "name": "baseline-llamacpp-arm_moe_fp32_e64_k8_d2048_ff1024", - "definition": "moe_fp32_e64_k8_d2048_ff1024", + "name": "baseline-llamacpp-arm_moe_bf16_e64_k8_d2048_ff1024", + "definition": "moe_bf16_e64_k8_d2048_ff1024", "dataset": "llama.cpp", "author": "baseline-llamacpp-arm", "description": "llama.cpp (ggml) fp32 baseline for moe_fp32_e64_k8_d2048_ff1024. binding.cpp bakes the const axes as constexpr and implements armbench_entry_moe over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", @@ -25,15 +25,15 @@ "sources": [ { "path": "moe.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major [T, n_embd]; router_weight fp32 [n_expert, n_embd];\n// gate/up_proj [n_expert, n_ff, n_embd]; down_proj [n_expert, n_embd, n_ff];\n// out fp32 [T, n_embd]. For q8_0, hidden_states and the three projections are\n// ggml block_q8_0 rows over their last axis (34-byte {fp16 d; int8 qs[32]}\n// blocks, repacked by the Python adapter); router_weight stays fp32.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8);\n" + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major bf16 [T, n_embd]; router_weight bf16 [n_expert, n_embd];\n// gate/up_proj bf16 [n_expert, n_ff, n_embd]; down_proj bf16 [n_expert, n_embd, n_ff];\n// out fp32 [T, n_embd]. For q8_0, hidden_states and the three projections are\n// ggml block_q8_0 rows over their last axis (34-byte {fp16 d; int8 qs[32]}\n// blocks, repacked by the Python adapter); router_weight stays fp32 there.\nint armbench_llamacpp_moe(const void* hidden_states, const void* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8);\n" }, { "path": "binding.cpp", - "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1024;\nconstexpr int64_t kNExpert = 64;\nconstexpr int64_t kNExpertUsed = 8;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=hidden_states fp32 [T,n_embd], [1]=router_weight fp32\n// [n_expert,n_embd], [2]=gate_proj fp32 [n_expert,n_ff,n_embd], [3]=up_proj\n// fp32 [n_expert,n_ff,n_embd], [4]=down_proj fp32 [n_expert,n_embd,n_ff];\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n reinterpret_cast(inputs[1]),\n inputs[2], inputs[3], inputs[4],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed, /*is_q8=*/false);\n}\n} // extern \"C\"\n" + "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1024;\nconstexpr int64_t kNExpert = 64;\nconstexpr int64_t kNExpertUsed = 8;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=hidden_states bf16 [T,n_embd], [1]=router_weight bf16\n// [n_expert,n_embd], [2]=gate_proj bf16 [n_expert,n_ff,n_embd], [3]=up_proj\n// bf16 [n_expert,n_ff,n_embd], [4]=down_proj bf16 [n_expert,n_embd,n_ff];\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n inputs[1],\n inputs[2], inputs[3], inputs[4],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed, /*is_q8=*/false);\n}\n} // extern \"C\"\n" }, { "path": "kernel.cpp", - "content": "#include \"moe.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\nnamespace {\n\n// Dequantize block_q8_0 rows (34-byte {fp16 d; int8 qs[32]} blocks) to fp32.\n// Used only for the router matmul input in the q8_0 variant \u2014 the reference\n// routes on the dequantized hidden states while the expert matmuls consume the\n// original quantization.\nvoid dequant_q8_0_rows(const void* src, float* dst, int64_t rows, int64_t k)\n{\n const int64_t nb = k / 32;\n const uint8_t* p = reinterpret_cast(src);\n for (int64_t r = 0; r < rows; ++r) {\n const uint8_t* rp = p + (size_t)r * nb * 34;\n float* dp = dst + (size_t)r * k;\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = rp + (size_t)b * 34;\n uint16_t dbits;\n std::memcpy(&dbits, bp, sizeof(dbits));\n const float d = ggml_fp16_to_fp32(dbits);\n const int8_t* qs = reinterpret_cast(bp + 2);\n for (int j = 0; j < 32; ++j) dp[b * 32 + j] = d * (float)qs[j];\n }\n }\n}\n\n} // namespace\n\n// The build_moe_ffn sequence from llama.cpp (SOFTMAX gating + norm_w, the\n// qwen1.5-moe / olmoe configuration): softmax over all experts \u2192\n// ggml_argsort_top_k \u2192 ggml_get_rows \u2192 weight renorm \u2192 ggml_mul_mat_id\n// gate/up \u2192 silu\u00b7up \u2192 ggml_mul_mat_id down \u2192 weight and sum the expert views.\n//\n// For q8_0, gate/up consume the pre-quantized hidden states directly\n// (src1->type == vec_dot_type, so ggml does NOT re-quantize them); the down\n// projection's fp32 intermediate is quantized to q8_0 by ggml internally \u2014\n// that is llama.cpp's real inference behavior and the one place this baseline\n// deviates from the fp32-intermediate numpy reference.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8)\n{\n const int64_t T = n_tokens, d = n_embd, ff = n_ff;\n const int64_t e = n_expert, k = n_expert_used;\n const ggml_type wt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_F32;\n const size_t f = sizeof(float);\n\n ggml_init_params ip_in = { 8 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* hs = ggml_new_tensor_2d(ctx_in, wt, d, T);\n hs->data = const_cast(hidden_states);\n ggml_tensor* router = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, d, e);\n router->data = const_cast(router_weight);\n ggml_tensor* gate = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n gate->data = const_cast(gate_proj);\n ggml_tensor* up = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n up->data = const_cast(up_proj);\n ggml_tensor* down = ggml_new_tensor_3d(ctx_in, wt, ff, d, e);\n down->data = const_cast(down_proj);\n\n size_t mem = 0;\n mem += 3 * (size_t)e * T * f; // logits + probs + argsort indices\n mem += 8 * (size_t)k * T * f; // selected ids, weights, sums, renorm\n mem += 4 * (size_t)ff * k * T * f; // gate, up, silu, gated product\n mem += 2 * (size_t)d * k * T * f; // expert outputs + weighted\n mem += (size_t)k * d * T * f; // expert-sum add chain\n if (is_q8) {\n mem += (size_t)d * T * f; // dequantized hidden states\n mem += (size_t)ff * k * T * 34 / 32 + 64; // cplan: down-proj src1 \u2192 q8_0\n }\n mem += (size_t)e * ((size_t)k * T * 16 + 256); // cplan: mul_mat_id row maps\n mem += 64 * ggml_tensor_overhead() + ggml_graph_overhead();\n mem += (4u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n // Router input: fp32 hidden states (dequantized for the q8_0 variant).\n ggml_tensor* cur_f;\n if (is_q8) {\n cur_f = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, d, T);\n dequant_q8_0_rows(hidden_states, reinterpret_cast(cur_f->data), T, d);\n } else {\n cur_f = hs;\n }\n\n ggml_tensor* logits = ggml_mul_mat(ctx, router, cur_f); // [e, T]\n ggml_tensor* probs = ggml_soft_max(ctx, logits); // [e, T]\n ggml_tensor* sel = ggml_argsort_top_k(ctx, probs, k); // [k, T] i32\n\n ggml_tensor* weights =\n ggml_get_rows(ctx, ggml_reshape_3d(ctx, probs, 1, e, T), sel); // [1, k, T]\n weights = ggml_reshape_2d(ctx, weights, k, T);\n ggml_tensor* wsum = ggml_sum_rows(ctx, weights); // [1, T]\n weights = ggml_div(ctx, weights, wsum); // renormalize\n weights = ggml_reshape_3d(ctx, weights, 1, k, T);\n\n // Expert matmuls consume the supplied quantization directly for q8_0.\n ggml_tensor* cur = ggml_reshape_3d(ctx, is_q8 ? hs : cur_f, d, 1, T);\n ggml_tensor* g = ggml_mul_mat_id(ctx, gate, cur, sel); // [ff, k, T]\n ggml_tensor* u = ggml_mul_mat_id(ctx, up, cur, sel); // [ff, k, T]\n ggml_tensor* par = ggml_mul(ctx, ggml_silu(ctx, g), u); // [ff, k, T]\n ggml_tensor* experts = ggml_mul_mat_id(ctx, down, par, sel); // [d, k, T]\n experts = ggml_mul(ctx, experts, weights);\n\n // Sum over the k expert slots (view + add chain, as in build_moe_ffn).\n ggml_tensor* moe_out = ggml_view_2d(ctx, experts, d, T, experts->nb[2], 0);\n for (int64_t i = 1; i < k; ++i) {\n moe_out = ggml_add(\n ctx, moe_out,\n ggml_view_2d(ctx, experts, d, T, experts->nb[2], i * experts->nb[1]));\n }\n if (k == 1) moe_out = ggml_cont(ctx, moe_out);\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, moe_out);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, moe_out->data, (size_t)d * T * f);\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + "content": "#include \"moe.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\nnamespace {\n\n// Dequantize block_q8_0 rows (34-byte {fp16 d; int8 qs[32]} blocks) to fp32.\n// Used only for the router matmul input in the q8_0 variant \u2014 the reference\n// routes on the dequantized hidden states while the expert matmuls consume the\n// original quantization.\nvoid dequant_q8_0_rows(const void* src, float* dst, int64_t rows, int64_t k)\n{\n const int64_t nb = k / 32;\n const uint8_t* p = reinterpret_cast(src);\n for (int64_t r = 0; r < rows; ++r) {\n const uint8_t* rp = p + (size_t)r * nb * 34;\n float* dp = dst + (size_t)r * k;\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = rp + (size_t)b * 34;\n uint16_t dbits;\n std::memcpy(&dbits, bp, sizeof(dbits));\n const float d = ggml_fp16_to_fp32(dbits);\n const int8_t* qs = reinterpret_cast(bp + 2);\n for (int j = 0; j < 32; ++j) dp[b * 32 + j] = d * (float)qs[j];\n }\n }\n}\n\n} // namespace\n\n// The build_moe_ffn sequence from llama.cpp (SOFTMAX gating + norm_w, the\n// qwen1.5-moe / olmoe configuration): softmax over all experts \u2192\n// ggml_argsort_top_k \u2192 ggml_get_rows \u2192 weight renorm \u2192 ggml_mul_mat_id\n// gate/up \u2192 silu\u00b7up \u2192 ggml_mul_mat_id down \u2192 weight and sum the expert views.\n//\n// For q8_0, gate/up consume the pre-quantized hidden states directly\n// (src1->type == vec_dot_type, so ggml does NOT re-quantize them); the down\n// projection's fp32 intermediate is quantized to q8_0 by ggml internally \u2014\n// that is llama.cpp's real inference behavior and the one place this baseline\n// deviates from the fp32-intermediate numpy reference.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_moe(const void* hidden_states, const void* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8)\n{\n const int64_t T = n_tokens, d = n_embd, ff = n_ff;\n const int64_t e = n_expert, k = n_expert_used;\n const ggml_type wt = is_q8 ? GGML_TYPE_Q8_0 : GGML_TYPE_BF16;\n const size_t f = sizeof(float);\n\n ggml_init_params ip_in = { 8 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* hs = ggml_new_tensor_2d(ctx_in, wt, d, T);\n hs->data = const_cast(hidden_states);\n ggml_tensor* router = ggml_new_tensor_2d(ctx_in, GGML_TYPE_BF16, d, e);\n router->data = const_cast(router_weight);\n ggml_tensor* gate = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n gate->data = const_cast(gate_proj);\n ggml_tensor* up = ggml_new_tensor_3d(ctx_in, wt, d, ff, e);\n up->data = const_cast(up_proj);\n ggml_tensor* down = ggml_new_tensor_3d(ctx_in, wt, ff, d, e);\n down->data = const_cast(down_proj);\n\n size_t mem = 0;\n mem += 3 * (size_t)e * T * f; // logits + probs + argsort indices\n mem += 8 * (size_t)k * T * f; // selected ids, weights, sums, renorm\n mem += 4 * (size_t)ff * k * T * f; // gate, up, silu, gated product\n mem += 2 * (size_t)d * k * T * f; // expert outputs + weighted\n mem += (size_t)k * d * T * f; // expert-sum add chain\n if (is_q8) {\n mem += (size_t)d * T * f; // dequantized hidden states\n mem += (size_t)ff * k * T * 34 / 32 + 64; // cplan: down-proj src1 \u2192 q8_0\n }\n mem += (size_t)e * ((size_t)k * T * 16 + 256); // cplan: mul_mat_id row maps\n mem += 64 * ggml_tensor_overhead() + ggml_graph_overhead();\n mem += (4u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n // Router input: fp32 hidden states (dequantized for the q8_0 variant).\n ggml_tensor* cur_f;\n if (is_q8) {\n cur_f = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, d, T);\n dequant_q8_0_rows(hidden_states, reinterpret_cast(cur_f->data), T, d);\n } else {\n cur_f = hs;\n }\n\n ggml_tensor* logits = ggml_mul_mat(ctx, router, cur_f); // [e, T]\n ggml_tensor* probs = ggml_soft_max(ctx, logits); // [e, T]\n ggml_tensor* sel = ggml_argsort_top_k(ctx, probs, k); // [k, T] i32\n\n ggml_tensor* weights =\n ggml_get_rows(ctx, ggml_reshape_3d(ctx, probs, 1, e, T), sel); // [1, k, T]\n weights = ggml_reshape_2d(ctx, weights, k, T);\n ggml_tensor* wsum = ggml_sum_rows(ctx, weights); // [1, T]\n weights = ggml_div(ctx, weights, wsum); // renormalize\n weights = ggml_reshape_3d(ctx, weights, 1, k, T);\n\n // Expert matmuls consume the supplied quantization directly for q8_0.\n ggml_tensor* cur = ggml_reshape_3d(ctx, is_q8 ? hs : cur_f, d, 1, T);\n ggml_tensor* g = ggml_mul_mat_id(ctx, gate, cur, sel); // [ff, k, T]\n ggml_tensor* u = ggml_mul_mat_id(ctx, up, cur, sel); // [ff, k, T]\n ggml_tensor* par = ggml_mul(ctx, ggml_silu(ctx, g), u); // [ff, k, T]\n ggml_tensor* experts = ggml_mul_mat_id(ctx, down, par, sel); // [d, k, T]\n experts = ggml_mul(ctx, experts, weights);\n\n // Sum over the k expert slots (view + add chain, as in build_moe_ffn).\n ggml_tensor* moe_out = ggml_view_2d(ctx, experts, d, T, experts->nb[2], 0);\n for (int64_t i = 1; i < k; ++i) {\n moe_out = ggml_add(\n ctx, moe_out,\n ggml_view_2d(ctx, experts, d, T, experts->nb[2], i * experts->nb[1]));\n }\n if (k == 1) moe_out = ggml_cont(ctx, moe_out);\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, moe_out);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, moe_out->data, (size_t)d * T * f);\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" } ] } diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json new file mode 100644 index 0000000000000000000000000000000000000000..e5f8cb2f50b6b799e16fe051e7f71eea2cf86626 --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_moe_q4_k_m_e60_k4_d2048_ff1536", + "definition": "moe_q4_k_m_e60_k4_d2048_ff1536", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) Q4_K baseline for moe_q4_k_m_e60_k4_d2048_ff1536. binding.cpp bakes the const axes as constexpr and implements armbench_entry_moe over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [], + "entry_point": "binding.cpp::armbench_entry_moe" + }, + "sources": [ + { + "path": "moe.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major [T, n_embd] bf16 (raw bit pattern -- NOT\n// quantized; weight-only Q4_K design). router_weight is fp32\n// [n_expert, n_embd] (also not quantized -- routing decisions are\n// categorical and must not flip from quantization rounding). gate_proj/\n// up_proj [n_expert, n_ff, n_embd] and down_proj [n_expert, n_embd, n_ff]\n// are ggml block_q4_K rows over their last axis (144-byte blocks, repacked\n// by the Python adapter). out fp32 [T, n_embd].\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1536;\nconstexpr int64_t kNExpert = 60;\nconstexpr int64_t kNExpertUsed = 4;\n} // namespace\n\nextern \"C\" {\n// [0]=hidden_states bf16, [1]=router_weight fp32,\n// [2]=gate_proj block_q4_K, [3]=NULL (gate_scales), [4]=NULL (gate_mins),\n// [5]=up_proj block_q4_K, [6]=NULL (up_scales), [7]=NULL (up_mins),\n// [8]=down_proj block_q4_K, [9]=NULL (down_scales), [10]=NULL (down_mins);\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n reinterpret_cast(inputs[1]),\n inputs[2], inputs[5], inputs[8],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"moe.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\n// The build_moe_ffn sequence from llama.cpp (SOFTMAX gating + norm_w, the\n// qwen1.5-moe / olmoe configuration): softmax over all experts ->\n// ggml_argsort_top_k -> ggml_get_rows -> weight renorm -> ggml_mul_mat_id\n// gate/up -> silu*up -> ggml_mul_mat_id down -> weight and sum the expert\n// views.\n//\n// hidden_states arrives as bf16 (never quantized -- weight-only Q4_K\n// design); it's widened to F32 once up front and used directly for the\n// router and all three expert matmuls. gate/up/down are real Q4_K weights;\n// ggml internally dynamically quantizes the F32 activations to Q8_K for\n// each of those matmuls (ggml_compute_forward_mul_mat[_id] requires\n// src1->type == F32 whenever src0 is a k-quant type) -- nothing else to do\n// here. router_weight stays plain F32, unquantized.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used)\n{\n const int64_t T = n_tokens, d = n_embd, ff = n_ff;\n const int64_t e = n_expert, k = n_expert_used;\n const size_t f = sizeof(float);\n\n ggml_init_params ip_in = { 8 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* router = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, d, e);\n router->data = const_cast(router_weight);\n ggml_tensor* gate = ggml_new_tensor_3d(ctx_in, GGML_TYPE_Q4_K, d, ff, e);\n gate->data = const_cast(gate_proj);\n ggml_tensor* up = ggml_new_tensor_3d(ctx_in, GGML_TYPE_Q4_K, d, ff, e);\n up->data = const_cast(up_proj);\n ggml_tensor* down = ggml_new_tensor_3d(ctx_in, GGML_TYPE_Q4_K, ff, d, e);\n down->data = const_cast(down_proj);\n\n size_t mem = 0;\n mem += (size_t)d * T * f; // widened hidden states\n mem += 3 * (size_t)e * T * f; // logits + probs + argsort indices\n mem += 8 * (size_t)k * T * f; // selected ids, weights, sums, renorm\n mem += 4 * (size_t)ff * k * T * f; // gate, up, silu, gated product\n mem += 2 * (size_t)d * k * T * f; // expert outputs + weighted\n mem += (size_t)k * d * T * f; // expert-sum add chain\n // cplan scratch: dynamic Q8_K conversion for router/gate/up (activation\n // width d) and down (activation width ff) matmuls; generous 2x-of-fp32.\n mem += (size_t)d * T * f * 2;\n mem += (size_t)ff * k * T * f * 2;\n mem += (size_t)e * ((size_t)k * T * 16 + 256); // cplan: mul_mat_id row maps\n mem += 64 * ggml_tensor_overhead() + ggml_graph_overhead();\n mem += (4u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n // Widen bf16 hidden states -> F32 once; used for router + all expert matmuls.\n ggml_tensor* cur_f = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, d, T);\n {\n const uint16_t* hbits = reinterpret_cast(hidden_states);\n float* hf = reinterpret_cast(cur_f->data);\n for (int64_t i = 0; i < d * T; ++i) hf[i] = bf16_to_f32(hbits[i]);\n }\n\n ggml_tensor* logits = ggml_mul_mat(ctx, router, cur_f); // [e, T]\n ggml_tensor* probs = ggml_soft_max(ctx, logits); // [e, T]\n ggml_tensor* sel = ggml_argsort_top_k(ctx, probs, k); // [k, T] i32\n\n ggml_tensor* weights =\n ggml_get_rows(ctx, ggml_reshape_3d(ctx, probs, 1, e, T), sel); // [1, k, T]\n weights = ggml_reshape_2d(ctx, weights, k, T);\n ggml_tensor* wsum = ggml_sum_rows(ctx, weights); // [1, T]\n weights = ggml_div(ctx, weights, wsum); // renormalize\n weights = ggml_reshape_3d(ctx, weights, 1, k, T);\n\n ggml_tensor* cur = ggml_reshape_3d(ctx, cur_f, d, 1, T);\n ggml_tensor* g = ggml_mul_mat_id(ctx, gate, cur, sel); // [ff, k, T]\n ggml_tensor* u = ggml_mul_mat_id(ctx, up, cur, sel); // [ff, k, T]\n ggml_tensor* par = ggml_mul(ctx, ggml_silu(ctx, g), u); // [ff, k, T]\n ggml_tensor* experts = ggml_mul_mat_id(ctx, down, par, sel); // [d, k, T]\n experts = ggml_mul(ctx, experts, weights);\n\n // Sum over the k expert slots (view + add chain, as in build_moe_ffn).\n ggml_tensor* moe_out = ggml_view_2d(ctx, experts, d, T, experts->nb[2], 0);\n for (int64_t i = 1; i < k; ++i) {\n moe_out = ggml_add(\n ctx, moe_out,\n ggml_view_2d(ctx, experts, d, T, experts->nb[2], i * experts->nb[1]));\n }\n if (k == 1) moe_out = ggml_cont(ctx, moe_out);\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, moe_out);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, moe_out->data, (size_t)d * T * f);\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json new file mode 100644 index 0000000000000000000000000000000000000000..ad67d12bb4964e93ca9a0a98dfe419ee5e907366 --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_moe_q4_k_m_e64_k8_d2048_ff1024", + "definition": "moe_q4_k_m_e64_k8_d2048_ff1024", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) Q4_K baseline for moe_q4_k_m_e64_k8_d2048_ff1024. binding.cpp bakes the const axes as constexpr and implements armbench_entry_moe over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [], + "entry_point": "binding.cpp::armbench_entry_moe" + }, + "sources": [ + { + "path": "moe.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major [T, n_embd] bf16 (raw bit pattern -- NOT\n// quantized; weight-only Q4_K design). router_weight is fp32\n// [n_expert, n_embd] (also not quantized -- routing decisions are\n// categorical and must not flip from quantization rounding). gate_proj/\n// up_proj [n_expert, n_ff, n_embd] and down_proj [n_expert, n_embd, n_ff]\n// are ggml block_q4_K rows over their last axis (144-byte blocks, repacked\n// by the Python adapter). out fp32 [T, n_embd].\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1024;\nconstexpr int64_t kNExpert = 64;\nconstexpr int64_t kNExpertUsed = 8;\n} // namespace\n\nextern \"C\" {\n// [0]=hidden_states bf16, [1]=router_weight fp32,\n// [2]=gate_proj block_q4_K, [3]=NULL (gate_scales), [4]=NULL (gate_mins),\n// [5]=up_proj block_q4_K, [6]=NULL (up_scales), [7]=NULL (up_mins),\n// [8]=down_proj block_q4_K, [9]=NULL (down_scales), [10]=NULL (down_mins);\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n reinterpret_cast(inputs[1]),\n inputs[2], inputs[5], inputs[8],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"moe.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n#include \n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\n// The build_moe_ffn sequence from llama.cpp (SOFTMAX gating + norm_w, the\n// qwen1.5-moe / olmoe configuration): softmax over all experts ->\n// ggml_argsort_top_k -> ggml_get_rows -> weight renorm -> ggml_mul_mat_id\n// gate/up -> silu*up -> ggml_mul_mat_id down -> weight and sum the expert\n// views.\n//\n// hidden_states arrives as bf16 (never quantized -- weight-only Q4_K\n// design); it's widened to F32 once up front and used directly for the\n// router and all three expert matmuls. gate/up/down are real Q4_K weights;\n// ggml internally dynamically quantizes the F32 activations to Q8_K for\n// each of those matmuls (ggml_compute_forward_mul_mat[_id] requires\n// src1->type == F32 whenever src0 is a k-quant type) -- nothing else to do\n// here. router_weight stays plain F32, unquantized.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used)\n{\n const int64_t T = n_tokens, d = n_embd, ff = n_ff;\n const int64_t e = n_expert, k = n_expert_used;\n const size_t f = sizeof(float);\n\n ggml_init_params ip_in = { 8 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* router = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, d, e);\n router->data = const_cast(router_weight);\n ggml_tensor* gate = ggml_new_tensor_3d(ctx_in, GGML_TYPE_Q4_K, d, ff, e);\n gate->data = const_cast(gate_proj);\n ggml_tensor* up = ggml_new_tensor_3d(ctx_in, GGML_TYPE_Q4_K, d, ff, e);\n up->data = const_cast(up_proj);\n ggml_tensor* down = ggml_new_tensor_3d(ctx_in, GGML_TYPE_Q4_K, ff, d, e);\n down->data = const_cast(down_proj);\n\n size_t mem = 0;\n mem += (size_t)d * T * f; // widened hidden states\n mem += 3 * (size_t)e * T * f; // logits + probs + argsort indices\n mem += 8 * (size_t)k * T * f; // selected ids, weights, sums, renorm\n mem += 4 * (size_t)ff * k * T * f; // gate, up, silu, gated product\n mem += 2 * (size_t)d * k * T * f; // expert outputs + weighted\n mem += (size_t)k * d * T * f; // expert-sum add chain\n // cplan scratch: dynamic Q8_K conversion for router/gate/up (activation\n // width d) and down (activation width ff) matmuls; generous 2x-of-fp32.\n mem += (size_t)d * T * f * 2;\n mem += (size_t)ff * k * T * f * 2;\n mem += (size_t)e * ((size_t)k * T * 16 + 256); // cplan: mul_mat_id row maps\n mem += 64 * ggml_tensor_overhead() + ggml_graph_overhead();\n mem += (4u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n // Widen bf16 hidden states -> F32 once; used for router + all expert matmuls.\n ggml_tensor* cur_f = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, d, T);\n {\n const uint16_t* hbits = reinterpret_cast(hidden_states);\n float* hf = reinterpret_cast(cur_f->data);\n for (int64_t i = 0; i < d * T; ++i) hf[i] = bf16_to_f32(hbits[i]);\n }\n\n ggml_tensor* logits = ggml_mul_mat(ctx, router, cur_f); // [e, T]\n ggml_tensor* probs = ggml_soft_max(ctx, logits); // [e, T]\n ggml_tensor* sel = ggml_argsort_top_k(ctx, probs, k); // [k, T] i32\n\n ggml_tensor* weights =\n ggml_get_rows(ctx, ggml_reshape_3d(ctx, probs, 1, e, T), sel); // [1, k, T]\n weights = ggml_reshape_2d(ctx, weights, k, T);\n ggml_tensor* wsum = ggml_sum_rows(ctx, weights); // [1, T]\n weights = ggml_div(ctx, weights, wsum); // renormalize\n weights = ggml_reshape_3d(ctx, weights, 1, k, T);\n\n ggml_tensor* cur = ggml_reshape_3d(ctx, cur_f, d, 1, T);\n ggml_tensor* g = ggml_mul_mat_id(ctx, gate, cur, sel); // [ff, k, T]\n ggml_tensor* u = ggml_mul_mat_id(ctx, up, cur, sel); // [ff, k, T]\n ggml_tensor* par = ggml_mul(ctx, ggml_silu(ctx, g), u); // [ff, k, T]\n ggml_tensor* experts = ggml_mul_mat_id(ctx, down, par, sel); // [d, k, T]\n experts = ggml_mul(ctx, experts, weights);\n\n // Sum over the k expert slots (view + add chain, as in build_moe_ffn).\n ggml_tensor* moe_out = ggml_view_2d(ctx, experts, d, T, experts->nb[2], 0);\n for (int64_t i = 1; i < k; ++i) {\n moe_out = ggml_add(\n ctx, moe_out,\n ggml_view_2d(ctx, experts, d, T, experts->nb[2], i * experts->nb[1]));\n }\n if (k == 1) moe_out = ggml_cont(ctx, moe_out);\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, moe_out);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, moe_out->data, (size_t)d * T * f);\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/rms_norm/rms_norm_bf16_d2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/rms_norm/rms_norm_bf16_d2048.json new file mode 100644 index 0000000000000000000000000000000000000000..422547ba1ad39b84b85010b7f8b43b07fdebef5b --- /dev/null +++ b/solutions/llama.cpp/baseline-llamacpp-arm/rms_norm/rms_norm_bf16_d2048.json @@ -0,0 +1,39 @@ +{ + "name": "baseline-llamacpp-arm_rms_norm_bf16_d2048", + "definition": "rms_norm_bf16_d2048", + "dataset": "llama.cpp", + "author": "baseline-llamacpp-arm", + "description": "llama.cpp (ggml) fp32 baseline for rms_norm_fp32_d2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_rms_norm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve", + "graviton4", + "aarch64-sve2", + "apple-m" + ], + "entry_point": "binding.cpp::armbench_entry_rms_norm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O3", + "-std=c++17" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "rms_norm.h", + "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) rms_norm baseline.\n// Called by armbench_entry_rms_norm (binding.cpp); implemented by kernel.cpp.\n// x is row-major bf16 [M, D], weight is bf16 [D], out is row-major fp32 [M, D]:\n// out[m] = x[m] / sqrt(mean(x[m]^2) + eps) * weight\nint armbench_llamacpp_rms_norm(const void* x, const void* weight, float* out,\n int64_t M, int64_t D, float eps);\n" + }, + { + "path": "binding.cpp", + "content": "#include \"rms_norm.h\"\n\nnamespace {\nconstexpr int64_t kD = 2048;\nconstexpr float kEps = 1e-6f; // matches the Definition reference\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=x bf16 [M,D], [1]=weight bf16 [D]; var_axes: [0]=M\nint armbench_entry_rms_norm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_rms_norm(\n inputs[0],\n inputs[1],\n reinterpret_cast(output),\n var_axes[0], kD, kEps);\n}\n} // extern \"C\"\n" + }, + { + "path": "kernel.cpp", + "content": "#include \"rms_norm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// ggml_rms_norm normalizes over ne0 (= D), then ggml_mul broadcasts the [D]\n// weight over rows \u2014 the same op pair llama.cpp's build_norm emits for\n// LLM_NORM_RMS.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_rms_norm(const void* x, const void* weight, float* out,\n int64_t M, int64_t D, float eps)\n{\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* xt = ggml_new_tensor_2d(ctx_in, GGML_TYPE_BF16, D, M);\n xt->data = const_cast(x);\n ggml_tensor* wt = ggml_new_tensor_1d(ctx_in, GGML_TYPE_BF16, D);\n wt->data = const_cast(weight);\n\n const size_t mem =\n 2 * (size_t)D * M * sizeof(float) // normalized x + weighted output\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* xn = ggml_rms_norm(ctx, xt, eps); // [D, M]\n ggml_tensor* y = ggml_mul(ctx, xn, wt); // [D, M] * [D] broadcast\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, y);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, y->data, (size_t)D * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/baseline-llamacpp-arm/rms_norm/rms_norm_fp32_d2048.json b/solutions/llama.cpp/baseline-llamacpp-arm/rms_norm/rms_norm_fp32_d2048.json deleted file mode 100644 index 212d7d08baf191308b80c5c96914cb8deeea478c..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/baseline-llamacpp-arm/rms_norm/rms_norm_fp32_d2048.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "baseline-llamacpp-arm_rms_norm_fp32_d2048", - "definition": "rms_norm_fp32_d2048", - "dataset": "llama.cpp", - "author": "baseline-llamacpp-arm", - "description": "llama.cpp (ggml) fp32 baseline for rms_norm_fp32_d2048. binding.cpp bakes the const axes as constexpr and implements armbench_entry_rms_norm over the void* ABI; kernel.cpp builds + runs the ggml graph against libggml*.a. Timing baseline for speedup computation.", - "spec": { - "language": "cpp", - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_rms_norm", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O3", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "rms_norm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) rms_norm baseline.\n// Called by armbench_entry_rms_norm (binding.cpp); implemented by kernel.cpp.\n// x is row-major fp32 [M, D], weight is fp32 [D], out is row-major fp32 [M, D]:\n// out[m] = x[m] / sqrt(mean(x[m]^2) + eps) * weight\nint armbench_llamacpp_rms_norm(const float* x, const float* weight, float* out,\n int64_t M, int64_t D, float eps);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"rms_norm.h\"\n\nnamespace {\nconstexpr int64_t kD = 2048;\nconstexpr float kEps = 1e-6f; // matches the Definition reference\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=x fp32 [M,D], [1]=weight fp32 [D]; var_axes: [0]=M\nint armbench_entry_rms_norm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_rms_norm(\n reinterpret_cast(inputs[0]),\n reinterpret_cast(inputs[1]),\n reinterpret_cast(output),\n var_axes[0], kD, kEps);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"rms_norm.h\"\n\n#include \"ggml.h\"\n#include \"ggml-cpu.h\"\n\n#include \n\n// ggml_rms_norm normalizes over ne0 (= D), then ggml_mul broadcasts the [D]\n// weight over rows \u2014 the same op pair llama.cpp's build_norm emits for\n// LLM_NORM_RMS.\n//\n// Like the ncnn baseline (layer create + create_pipeline + forward per entry\n// call), the whole ggml context/graph setup runs inside the timed region.\nint armbench_llamacpp_rms_norm(const float* x, const float* weight, float* out,\n int64_t M, int64_t D, float eps)\n{\n ggml_init_params ip_in = { 4 * ggml_tensor_overhead(), nullptr, /*no_alloc=*/true };\n ggml_context* ctx_in = ggml_init(ip_in);\n if (!ctx_in) return -1;\n ggml_tensor* xt = ggml_new_tensor_2d(ctx_in, GGML_TYPE_F32, D, M);\n xt->data = const_cast(x);\n ggml_tensor* wt = ggml_new_tensor_1d(ctx_in, GGML_TYPE_F32, D);\n wt->data = const_cast(weight);\n\n const size_t mem =\n 2 * (size_t)D * M * sizeof(float) // normalized x + weighted output\n + 16 * ggml_tensor_overhead()\n + ggml_graph_overhead()\n + (1u << 20);\n ggml_init_params ip = { mem, nullptr, /*no_alloc=*/false };\n ggml_context* ctx = ggml_init(ip);\n if (!ctx) { ggml_free(ctx_in); return -1; }\n\n ggml_tensor* xn = ggml_rms_norm(ctx, xt, eps); // [D, M]\n ggml_tensor* y = ggml_mul(ctx, xn, wt); // [D, M] * [D] broadcast\n\n ggml_cgraph* gf = ggml_new_graph(ctx);\n ggml_build_forward_expand(gf, y);\n const ggml_status st = ggml_graph_compute_with_ctx(ctx, gf, /*n_threads=*/1);\n\n int ret = -1;\n if (st == GGML_STATUS_SUCCESS) {\n std::memcpy(out, y->data, (size_t)D * M * sizeof(float));\n ret = 0;\n }\n ggml_free(ctx);\n ggml_free(ctx_in);\n return ret;\n}\n" - } - ] -} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n1024_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n1024_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..936d161ac87974ac93546d18f9e2ae7354c30517 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n1024_k2048.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_bf16_n1024_k2048", + "definition": "gemm_bf16_n1024_k2048", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_bf16_n1024_k2048. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm bf16 specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A/B are raw bf16 bit patterns (uint16_t) \u2014 bf16 shares fp32's exponent field,\n// so widening is an exact `(uint32_t)bits << 16` reinterpret (see kernel.cpp).\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 1024;\nconstexpr int K = 2048;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B: (N, K) bf16; output: (M, N) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n inner_gemm(A, output, B, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm bf16 (fc-style: C = A @ B^T, fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_gemm.\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \nusing namespace gemm_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint16_t* b_row = B + (long)n * K;\n float sum = 0.0f;\n for (int k = 0; k < K; ++k) {\n sum += bf16_to_f32(a_row[k]) * bf16_to_f32(b_row[k]);\n }\n out_row[n] = sum;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n1408_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n1408_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..869980702542622448508e661d90de81ab0c9976 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n1408_k2048.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_bf16_n1408_k2048", + "definition": "gemm_bf16_n1408_k2048", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_bf16_n1408_k2048. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm bf16 specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A/B are raw bf16 bit patterns (uint16_t) \u2014 bf16 shares fp32's exponent field,\n// so widening is an exact `(uint32_t)bits << 16` reinterpret (see kernel.cpp).\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 1408;\nconstexpr int K = 2048;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B: (N, K) bf16; output: (M, N) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n inner_gemm(A, output, B, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm bf16 (fc-style: C = A @ B^T, fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_gemm.\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \nusing namespace gemm_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint16_t* b_row = B + (long)n * K;\n float sum = 0.0f;\n for (int k = 0; k < K; ++k) {\n sum += bf16_to_f32(a_row[k]) * bf16_to_f32(b_row[k]);\n }\n out_row[n] = sum;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k1024.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k1024.json new file mode 100644 index 0000000000000000000000000000000000000000..91a8a5120f8983aecf59998d5678319a80c9bd6b --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k1024.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_bf16_n2048_k1024", + "definition": "gemm_bf16_n2048_k1024", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_bf16_n2048_k1024. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm bf16 specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A/B are raw bf16 bit patterns (uint16_t) \u2014 bf16 shares fp32's exponent field,\n// so widening is an exact `(uint32_t)bits << 16` reinterpret (see kernel.cpp).\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 2048;\nconstexpr int K = 1024;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B: (N, K) bf16; output: (M, N) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n inner_gemm(A, output, B, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm bf16 (fc-style: C = A @ B^T, fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_gemm.\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \nusing namespace gemm_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint16_t* b_row = B + (long)n * K;\n float sum = 0.0f;\n for (int k = 0; k < K; ++k) {\n sum += bf16_to_f32(a_row[k]) * bf16_to_f32(b_row[k]);\n }\n out_row[n] = sum;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k1408.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k1408.json new file mode 100644 index 0000000000000000000000000000000000000000..77d33fe9012365184a5d281497af024b83b05aa6 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k1408.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_bf16_n2048_k1408", + "definition": "gemm_bf16_n2048_k1408", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_bf16_n2048_k1408. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm bf16 specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A/B are raw bf16 bit patterns (uint16_t) \u2014 bf16 shares fp32's exponent field,\n// so widening is an exact `(uint32_t)bits << 16` reinterpret (see kernel.cpp).\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 2048;\nconstexpr int K = 1408;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B: (N, K) bf16; output: (M, N) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n inner_gemm(A, output, B, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm bf16 (fc-style: C = A @ B^T, fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_gemm.\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \nusing namespace gemm_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint16_t* b_row = B + (long)n * K;\n float sum = 0.0f;\n for (int k = 0; k < K; ++k) {\n sum += bf16_to_f32(a_row[k]) * bf16_to_f32(b_row[k]);\n }\n out_row[n] = sum;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..ea3f3c2677c70671a4c321e41abab2b56f310a37 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_bf16_n2048_k2048.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_bf16_n2048_k2048", + "definition": "gemm_bf16_n2048_k2048", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_bf16_n2048_k2048. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm bf16 specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A/B are raw bf16 bit patterns (uint16_t) \u2014 bf16 shares fp32's exponent field,\n// so widening is an exact `(uint32_t)bits << 16` reinterpret (see kernel.cpp).\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 2048;\nconstexpr int K = 2048;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B: (N, K) bf16; output: (M, N) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n inner_gemm(A, output, B, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm bf16 (fc-style: C = A @ B^T, fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_gemm.\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \nusing namespace gemm_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint16_t* B, int M)\n{\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint16_t* b_row = B + (long)n * K;\n float sum = 0.0f;\n for (int k = 0; k < K; ++k) {\n sum += bf16_to_f32(a_row[k]) * bf16_to_f32(b_row[k]);\n }\n out_row[n] = sum;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n1024_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n1024_k2048.json deleted file mode 100644 index abcc4d866163c7857f84a181a5262618f4463bbc..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n1024_k2048.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_gemm_fp32_n1024_k2048", - "definition": "gemm_fp32_n1024_k2048", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_gemm", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A · B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1024;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n#include \n#include \n#include \n#include \n\nstatic inline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F, mant = h & 0x3FF, f;\n if (exp == 0) {\n if (mant == 0) f = sign;\n else { exp = 127 - 15 + 1; while (!(mant & 0x400)) { mant <<= 1; exp--; }\n mant &= 0x3FF; f = sign | (exp << 23) | (mant << 13); }\n } else if (exp == 0x1F) { f = sign | 0x7F800000u | (mant << 13); }\n else { f = sign | ((exp - 15 + 127) << 23) | (mant << 13); }\n float o; std::memcpy(&o, &f, 4); return o;\n}\n// Dequant one block_q8_0 row: nb 34-byte blocks {fp16 d; int8 qs[32]} -> nb*32 floats.\nstatic inline void dq_row(const uint8_t* p, int64_t nb, float* dst) {\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = p + b * 34; uint16_t d16; std::memcpy(&d16, bp, 2);\n float d = f16_to_f32(d16); const int8_t* qs = (const int8_t*)(bp + 2);\n for (int j = 0; j < 32; ++j) dst[b * 32 + j] = d * (float)qs[j];\n }\n}\n\n// Naive scalar GEMM reference: C = A . B^T, A[M,K] B[N,K] -> C[M,N].\n// For q8_0, A and B are block_q8_0 rows (K/32 blocks); dequantize then matmul.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8) {\n int64_t nb = K / 32;\n std::vector Af((size_t)M * K), Bf((size_t)N * K);\n if (is_q8) {\n const uint8_t* a = (const uint8_t*)A; const uint8_t* b = (const uint8_t*)B;\n for (int64_t r = 0; r < M; ++r) dq_row(a + (size_t)r * nb * 34, nb, &Af[(size_t)r * K]);\n for (int64_t r = 0; r < N; ++r) dq_row(b + (size_t)r * nb * 34, nb, &Bf[(size_t)r * K]);\n } else {\n std::memcpy(Af.data(), A, (size_t)M * K * sizeof(float));\n std::memcpy(Bf.data(), B, (size_t)N * K * sizeof(float));\n }\n for (int64_t m = 0; m < M; ++m)\n for (int64_t n = 0; n < N; ++n) {\n const float* ar = &Af[(size_t)m * K]; const float* br = &Bf[(size_t)n * K];\n double acc = 0.0; for (int64_t k = 0; k < K; ++k) acc += (double)ar[k] * br[k];\n C[(size_t)m * N + n] = (float)acc;\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for gemm_fp32_n1024_k2048 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n1408_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n1408_k2048.json deleted file mode 100644 index 5c4d0b24574a4d3b9fc1823dfe9c5f500d5c122b..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n1408_k2048.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_gemm_fp32_n1408_k2048", - "definition": "gemm_fp32_n1408_k2048", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_gemm", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A · B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 1408;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n#include \n#include \n#include \n#include \n\nstatic inline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F, mant = h & 0x3FF, f;\n if (exp == 0) {\n if (mant == 0) f = sign;\n else { exp = 127 - 15 + 1; while (!(mant & 0x400)) { mant <<= 1; exp--; }\n mant &= 0x3FF; f = sign | (exp << 23) | (mant << 13); }\n } else if (exp == 0x1F) { f = sign | 0x7F800000u | (mant << 13); }\n else { f = sign | ((exp - 15 + 127) << 23) | (mant << 13); }\n float o; std::memcpy(&o, &f, 4); return o;\n}\n// Dequant one block_q8_0 row: nb 34-byte blocks {fp16 d; int8 qs[32]} -> nb*32 floats.\nstatic inline void dq_row(const uint8_t* p, int64_t nb, float* dst) {\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = p + b * 34; uint16_t d16; std::memcpy(&d16, bp, 2);\n float d = f16_to_f32(d16); const int8_t* qs = (const int8_t*)(bp + 2);\n for (int j = 0; j < 32; ++j) dst[b * 32 + j] = d * (float)qs[j];\n }\n}\n\n// Naive scalar GEMM reference: C = A . B^T, A[M,K] B[N,K] -> C[M,N].\n// For q8_0, A and B are block_q8_0 rows (K/32 blocks); dequantize then matmul.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8) {\n int64_t nb = K / 32;\n std::vector Af((size_t)M * K), Bf((size_t)N * K);\n if (is_q8) {\n const uint8_t* a = (const uint8_t*)A; const uint8_t* b = (const uint8_t*)B;\n for (int64_t r = 0; r < M; ++r) dq_row(a + (size_t)r * nb * 34, nb, &Af[(size_t)r * K]);\n for (int64_t r = 0; r < N; ++r) dq_row(b + (size_t)r * nb * 34, nb, &Bf[(size_t)r * K]);\n } else {\n std::memcpy(Af.data(), A, (size_t)M * K * sizeof(float));\n std::memcpy(Bf.data(), B, (size_t)N * K * sizeof(float));\n }\n for (int64_t m = 0; m < M; ++m)\n for (int64_t n = 0; n < N; ++n) {\n const float* ar = &Af[(size_t)m * K]; const float* br = &Bf[(size_t)n * K];\n double acc = 0.0; for (int64_t k = 0; k < K; ++k) acc += (double)ar[k] * br[k];\n C[(size_t)m * N + n] = (float)acc;\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for gemm_fp32_n1408_k2048 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k1024.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k1024.json deleted file mode 100644 index 60e8e527f5203423f68048747b72625968f1ddaf..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k1024.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_gemm_fp32_n2048_k1024", - "definition": "gemm_fp32_n2048_k1024", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_gemm", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A · B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1024;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n#include \n#include \n#include \n#include \n\nstatic inline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F, mant = h & 0x3FF, f;\n if (exp == 0) {\n if (mant == 0) f = sign;\n else { exp = 127 - 15 + 1; while (!(mant & 0x400)) { mant <<= 1; exp--; }\n mant &= 0x3FF; f = sign | (exp << 23) | (mant << 13); }\n } else if (exp == 0x1F) { f = sign | 0x7F800000u | (mant << 13); }\n else { f = sign | ((exp - 15 + 127) << 23) | (mant << 13); }\n float o; std::memcpy(&o, &f, 4); return o;\n}\n// Dequant one block_q8_0 row: nb 34-byte blocks {fp16 d; int8 qs[32]} -> nb*32 floats.\nstatic inline void dq_row(const uint8_t* p, int64_t nb, float* dst) {\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = p + b * 34; uint16_t d16; std::memcpy(&d16, bp, 2);\n float d = f16_to_f32(d16); const int8_t* qs = (const int8_t*)(bp + 2);\n for (int j = 0; j < 32; ++j) dst[b * 32 + j] = d * (float)qs[j];\n }\n}\n\n// Naive scalar GEMM reference: C = A . B^T, A[M,K] B[N,K] -> C[M,N].\n// For q8_0, A and B are block_q8_0 rows (K/32 blocks); dequantize then matmul.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8) {\n int64_t nb = K / 32;\n std::vector Af((size_t)M * K), Bf((size_t)N * K);\n if (is_q8) {\n const uint8_t* a = (const uint8_t*)A; const uint8_t* b = (const uint8_t*)B;\n for (int64_t r = 0; r < M; ++r) dq_row(a + (size_t)r * nb * 34, nb, &Af[(size_t)r * K]);\n for (int64_t r = 0; r < N; ++r) dq_row(b + (size_t)r * nb * 34, nb, &Bf[(size_t)r * K]);\n } else {\n std::memcpy(Af.data(), A, (size_t)M * K * sizeof(float));\n std::memcpy(Bf.data(), B, (size_t)N * K * sizeof(float));\n }\n for (int64_t m = 0; m < M; ++m)\n for (int64_t n = 0; n < N; ++n) {\n const float* ar = &Af[(size_t)m * K]; const float* br = &Bf[(size_t)n * K];\n double acc = 0.0; for (int64_t k = 0; k < K; ++k) acc += (double)ar[k] * br[k];\n C[(size_t)m * N + n] = (float)acc;\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for gemm_fp32_n2048_k1024 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k1408.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k1408.json deleted file mode 100644 index 77434015dac905c81ffbe21873e1cb3ccf493f4e..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k1408.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_gemm_fp32_n2048_k1408", - "definition": "gemm_fp32_n2048_k1408", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_gemm", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A · B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 1408;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n#include \n#include \n#include \n#include \n\nstatic inline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F, mant = h & 0x3FF, f;\n if (exp == 0) {\n if (mant == 0) f = sign;\n else { exp = 127 - 15 + 1; while (!(mant & 0x400)) { mant <<= 1; exp--; }\n mant &= 0x3FF; f = sign | (exp << 23) | (mant << 13); }\n } else if (exp == 0x1F) { f = sign | 0x7F800000u | (mant << 13); }\n else { f = sign | ((exp - 15 + 127) << 23) | (mant << 13); }\n float o; std::memcpy(&o, &f, 4); return o;\n}\n// Dequant one block_q8_0 row: nb 34-byte blocks {fp16 d; int8 qs[32]} -> nb*32 floats.\nstatic inline void dq_row(const uint8_t* p, int64_t nb, float* dst) {\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = p + b * 34; uint16_t d16; std::memcpy(&d16, bp, 2);\n float d = f16_to_f32(d16); const int8_t* qs = (const int8_t*)(bp + 2);\n for (int j = 0; j < 32; ++j) dst[b * 32 + j] = d * (float)qs[j];\n }\n}\n\n// Naive scalar GEMM reference: C = A . B^T, A[M,K] B[N,K] -> C[M,N].\n// For q8_0, A and B are block_q8_0 rows (K/32 blocks); dequantize then matmul.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8) {\n int64_t nb = K / 32;\n std::vector Af((size_t)M * K), Bf((size_t)N * K);\n if (is_q8) {\n const uint8_t* a = (const uint8_t*)A; const uint8_t* b = (const uint8_t*)B;\n for (int64_t r = 0; r < M; ++r) dq_row(a + (size_t)r * nb * 34, nb, &Af[(size_t)r * K]);\n for (int64_t r = 0; r < N; ++r) dq_row(b + (size_t)r * nb * 34, nb, &Bf[(size_t)r * K]);\n } else {\n std::memcpy(Af.data(), A, (size_t)M * K * sizeof(float));\n std::memcpy(Bf.data(), B, (size_t)N * K * sizeof(float));\n }\n for (int64_t m = 0; m < M; ++m)\n for (int64_t n = 0; n < N; ++n) {\n const float* ar = &Af[(size_t)m * K]; const float* br = &Bf[(size_t)n * K];\n double acc = 0.0; for (int64_t k = 0; k < K; ++k) acc += (double)ar[k] * br[k];\n C[(size_t)m * N + n] = (float)acc;\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for gemm_fp32_n2048_k1408 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k2048.json deleted file mode 100644 index af462a494a51aac15dd429798524cf851a692653..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/gemm/gemm_fp32_n2048_k2048.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_gemm_fp32_n2048_k2048", - "definition": "gemm_fp32_n2048_k2048", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_gemm", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "gemm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) gemm baseline.\n// Called by armbench_entry_gemm (binding.cpp); implemented by kernel.cpp.\n// A is row-major [M, K], B is row-major [N, K], C = A · B^T row-major [M, N].\n// For q8_0, A and B are ggml block_q8_0 rows: (K/32) 34-byte blocks per row,\n// each block = {fp16 d; int8 qs[32]} (repacked by the Python adapter).\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"gemm.h\"\n\nnamespace {\nconstexpr int64_t kN = 2048;\nconstexpr int64_t kK = 2048;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=A fp32 [M,K], [1]=B fp32 [N,K]; var_axes: [0]=M\nint armbench_entry_gemm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_gemm(inputs[0], inputs[1],\n reinterpret_cast(output),\n var_axes[0], kN, kK, /*is_q8=*/false);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"gemm.h\"\n#include \n#include \n#include \n#include \n\nstatic inline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F, mant = h & 0x3FF, f;\n if (exp == 0) {\n if (mant == 0) f = sign;\n else { exp = 127 - 15 + 1; while (!(mant & 0x400)) { mant <<= 1; exp--; }\n mant &= 0x3FF; f = sign | (exp << 23) | (mant << 13); }\n } else if (exp == 0x1F) { f = sign | 0x7F800000u | (mant << 13); }\n else { f = sign | ((exp - 15 + 127) << 23) | (mant << 13); }\n float o; std::memcpy(&o, &f, 4); return o;\n}\n// Dequant one block_q8_0 row: nb 34-byte blocks {fp16 d; int8 qs[32]} -> nb*32 floats.\nstatic inline void dq_row(const uint8_t* p, int64_t nb, float* dst) {\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = p + b * 34; uint16_t d16; std::memcpy(&d16, bp, 2);\n float d = f16_to_f32(d16); const int8_t* qs = (const int8_t*)(bp + 2);\n for (int j = 0; j < 32; ++j) dst[b * 32 + j] = d * (float)qs[j];\n }\n}\n\n// Naive scalar GEMM reference: C = A . B^T, A[M,K] B[N,K] -> C[M,N].\n// For q8_0, A and B are block_q8_0 rows (K/32 blocks); dequantize then matmul.\nint armbench_llamacpp_gemm(const void* A, const void* B, float* C,\n int64_t M, int64_t N, int64_t K, bool is_q8) {\n int64_t nb = K / 32;\n std::vector Af((size_t)M * K), Bf((size_t)N * K);\n if (is_q8) {\n const uint8_t* a = (const uint8_t*)A; const uint8_t* b = (const uint8_t*)B;\n for (int64_t r = 0; r < M; ++r) dq_row(a + (size_t)r * nb * 34, nb, &Af[(size_t)r * K]);\n for (int64_t r = 0; r < N; ++r) dq_row(b + (size_t)r * nb * 34, nb, &Bf[(size_t)r * K]);\n } else {\n std::memcpy(Af.data(), A, (size_t)M * K * sizeof(float));\n std::memcpy(Bf.data(), B, (size_t)N * K * sizeof(float));\n }\n for (int64_t m = 0; m < M; ++m)\n for (int64_t n = 0; n < N; ++n) {\n const float* ar = &Af[(size_t)m * K]; const float* br = &Bf[(size_t)n * K];\n double acc = 0.0; for (int64_t k = 0; k < K; ++k) acc += (double)ar[k] * br[k];\n C[(size_t)m * N + n] = (float)acc;\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for gemm_fp32_n2048_k2048 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n1024_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n1024_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..d4269aa97ce2b96b4573ff1f616e10eaa3e2e730 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n1024_k2048.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_q4_k_m_n1024_k2048", + "definition": "gemm_q4_k_m_n1024_k2048", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_q4_k_m_n1024_k2048. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm Q4_K (weight-only) specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A is a raw bf16 bit pattern (uint16_t) -- activations stay at the bf16\n// baseline tier (real GGML never stores activations statically in a\n// k-quant format either -- see kernel.cpp for the dynamic quantization this\n// implies). B is Q4_K-quantized, exposed as three flat (non-bit-packed-scale)\n// tensors:\n// B_q4: [N, K/2] uint8 -- byte i holds element 2i (low nibble),\n// element 2i+1 (high nibble), plain\n// sequential order (not ggml's own block-\n// interleaved order -- this is a simplified\n// Definition-level ABI, not GGML's bit-exact\n// block_q4_K struct).\n// B_scales: [N, K/32] raw fp16 bit pattern (uint16_t) -- one value per\n// 32-element sub-block, already combining\n// GGML's per-superblock `d` and per-sub-block\n// 6-bit `sc` into one number.\n// B_mins: [N, K/32] raw fp16 bit pattern (uint16_t) -- same, combining\n// `dmin*m`.\n// Dequant is `w[l] = B_scales[sb]*nibble(l) - B_mins[sb]`.\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 1024;\nconstexpr int K = 2048;\nconstexpr int K_half = 1024;\nconstexpr int K_sub = 64;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B_q4: (N, K/2) uint8;\n// B_scales/B_mins: (N, K/32) raw fp16 bits; output: (M, N) float32.\nvoid inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B_q4*, B_scales*, B_mins*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output,\n const uint8_t* B_q4, const uint16_t* B_scales,\n const uint16_t* B_mins, int M)\n{\n inner_gemm(A, output, B_q4, B_scales, B_mins, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm Q4_K (weight-only, genuine low-bit dot product).\n// LLM target: replace this file with an optimised inner_gemm (SVE2/NEON\n// nibble-unpack + int8 dot-product intrinsics are the intended optimization\n// surface here).\n//\n// Unlike Definition.reference (which computes a clean, implementation-\n// agnostic dequant-then-fp32-multiply ground truth), this kernel mirrors\n// real GGML's ggml_vec_dot_q4_K_q8_K: the bf16 activation is dynamically\n// quantized into 256-element blocks (one scale, int8 values -- same idea as\n// ggml's Q8_K), then for each 32-element sub-block an integer dot product\n// against the unpacked Q4_K nibbles is computed and scale-corrected before\n// accumulating into a running fp32 total.\n//\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \n#include \n#include \n#include \nusing namespace gemm_def;\n\nnamespace {\n\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n\n// Proper IEEE-754 half->single conversion (fp16, not bf16 -- B_scales/B_mins\n// are real fp16, whose exponent field does NOT alias fp32's, so this needs\n// full mantissa/exponent remapping, unlike bf16_to_f32 above).\ninline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F;\n uint32_t mant = h & 0x3FF;\n uint32_t bits;\n if (exp == 0) {\n if (mant == 0) {\n bits = sign;\n } else {\n exp = 1;\n while ((mant & 0x400) == 0) { mant <<= 1; --exp; }\n mant &= 0x3FF;\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n } else if (exp == 0x1F) {\n bits = sign | 0x7F800000u | (mant << 13);\n } else {\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n float f;\n std::memcpy(&f, &bits, sizeof(f));\n return f;\n}\n\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M)\n{\n constexpr int K_super = K / 256;\n\n std::vector h(K);\n std::vector d_act(K_super);\n std::vector q8(K);\n\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n for (int k = 0; k < K; ++k) h[k] = bf16_to_f32(a_row[k]);\n\n // Dynamically quantize the activation row into 256-element blocks\n // (Q8_K-style: one scale, int8 values in [-127, 127]).\n for (int sb = 0; sb < K_super; ++sb) {\n float amax = 0.0f;\n for (int l = 0; l < 256; ++l) {\n float v = std::fabs(h[sb * 256 + l]);\n if (v > amax) amax = v;\n }\n const float d = amax / 127.0f;\n d_act[sb] = d;\n const float id = d > 0.0f ? 1.0f / d : 0.0f;\n for (int l = 0; l < 256; ++l) {\n int q = (int)std::lround(h[sb * 256 + l] * id);\n if (q > 127) q = 127;\n if (q < -127) q = -127;\n q8[sb * 256 + l] = (int8_t)q;\n }\n }\n\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint8_t* b_row = B_q4 + (long)n * K_half;\n const uint16_t* sc_row = B_scales + (long)n * K_sub;\n const uint16_t* mn_row = B_mins + (long)n * K_sub;\n\n float acc = 0.0f;\n for (int sb32 = 0; sb32 < K_sub; ++sb32) {\n const float scale = f16_to_f32(sc_row[sb32]);\n const float minv = f16_to_f32(mn_row[sb32]);\n const float dact = d_act[sb32 / 8]; // 8 sub-blocks per 256-elem superblock\n\n int32_t sumi = 0;\n int32_t bsum = 0;\n const int base = sb32 * 32;\n for (int l = 0; l < 32; ++l) {\n const int k = base + l;\n const uint8_t byte = b_row[k / 2];\n const int nib = (k % 2 == 0) ? (byte & 0xF) : (byte >> 4);\n const int8_t qv = q8[k];\n sumi += nib * qv;\n bsum += qv;\n }\n acc += dact * (scale * (float)sumi - minv * (float)bsum);\n }\n out_row[n] = acc;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n1408_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n1408_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..556cb35f75147546ed621692c75e7ef2e2832728 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n1408_k2048.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_q4_k_m_n1408_k2048", + "definition": "gemm_q4_k_m_n1408_k2048", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_q4_k_m_n1408_k2048. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm Q4_K (weight-only) specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A is a raw bf16 bit pattern (uint16_t) -- activations stay at the bf16\n// baseline tier (real GGML never stores activations statically in a\n// k-quant format either -- see kernel.cpp for the dynamic quantization this\n// implies). B is Q4_K-quantized, exposed as three flat (non-bit-packed-scale)\n// tensors:\n// B_q4: [N, K/2] uint8 -- byte i holds element 2i (low nibble),\n// element 2i+1 (high nibble), plain\n// sequential order (not ggml's own block-\n// interleaved order -- this is a simplified\n// Definition-level ABI, not GGML's bit-exact\n// block_q4_K struct).\n// B_scales: [N, K/32] raw fp16 bit pattern (uint16_t) -- one value per\n// 32-element sub-block, already combining\n// GGML's per-superblock `d` and per-sub-block\n// 6-bit `sc` into one number.\n// B_mins: [N, K/32] raw fp16 bit pattern (uint16_t) -- same, combining\n// `dmin*m`.\n// Dequant is `w[l] = B_scales[sb]*nibble(l) - B_mins[sb]`.\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 1408;\nconstexpr int K = 2048;\nconstexpr int K_half = 1024;\nconstexpr int K_sub = 64;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B_q4: (N, K/2) uint8;\n// B_scales/B_mins: (N, K/32) raw fp16 bits; output: (M, N) float32.\nvoid inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B_q4*, B_scales*, B_mins*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output,\n const uint8_t* B_q4, const uint16_t* B_scales,\n const uint16_t* B_mins, int M)\n{\n inner_gemm(A, output, B_q4, B_scales, B_mins, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm Q4_K (weight-only, genuine low-bit dot product).\n// LLM target: replace this file with an optimised inner_gemm (SVE2/NEON\n// nibble-unpack + int8 dot-product intrinsics are the intended optimization\n// surface here).\n//\n// Unlike Definition.reference (which computes a clean, implementation-\n// agnostic dequant-then-fp32-multiply ground truth), this kernel mirrors\n// real GGML's ggml_vec_dot_q4_K_q8_K: the bf16 activation is dynamically\n// quantized into 256-element blocks (one scale, int8 values -- same idea as\n// ggml's Q8_K), then for each 32-element sub-block an integer dot product\n// against the unpacked Q4_K nibbles is computed and scale-corrected before\n// accumulating into a running fp32 total.\n//\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \n#include \n#include \n#include \nusing namespace gemm_def;\n\nnamespace {\n\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n\n// Proper IEEE-754 half->single conversion (fp16, not bf16 -- B_scales/B_mins\n// are real fp16, whose exponent field does NOT alias fp32's, so this needs\n// full mantissa/exponent remapping, unlike bf16_to_f32 above).\ninline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F;\n uint32_t mant = h & 0x3FF;\n uint32_t bits;\n if (exp == 0) {\n if (mant == 0) {\n bits = sign;\n } else {\n exp = 1;\n while ((mant & 0x400) == 0) { mant <<= 1; --exp; }\n mant &= 0x3FF;\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n } else if (exp == 0x1F) {\n bits = sign | 0x7F800000u | (mant << 13);\n } else {\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n float f;\n std::memcpy(&f, &bits, sizeof(f));\n return f;\n}\n\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M)\n{\n constexpr int K_super = K / 256;\n\n std::vector h(K);\n std::vector d_act(K_super);\n std::vector q8(K);\n\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n for (int k = 0; k < K; ++k) h[k] = bf16_to_f32(a_row[k]);\n\n // Dynamically quantize the activation row into 256-element blocks\n // (Q8_K-style: one scale, int8 values in [-127, 127]).\n for (int sb = 0; sb < K_super; ++sb) {\n float amax = 0.0f;\n for (int l = 0; l < 256; ++l) {\n float v = std::fabs(h[sb * 256 + l]);\n if (v > amax) amax = v;\n }\n const float d = amax / 127.0f;\n d_act[sb] = d;\n const float id = d > 0.0f ? 1.0f / d : 0.0f;\n for (int l = 0; l < 256; ++l) {\n int q = (int)std::lround(h[sb * 256 + l] * id);\n if (q > 127) q = 127;\n if (q < -127) q = -127;\n q8[sb * 256 + l] = (int8_t)q;\n }\n }\n\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint8_t* b_row = B_q4 + (long)n * K_half;\n const uint16_t* sc_row = B_scales + (long)n * K_sub;\n const uint16_t* mn_row = B_mins + (long)n * K_sub;\n\n float acc = 0.0f;\n for (int sb32 = 0; sb32 < K_sub; ++sb32) {\n const float scale = f16_to_f32(sc_row[sb32]);\n const float minv = f16_to_f32(mn_row[sb32]);\n const float dact = d_act[sb32 / 8]; // 8 sub-blocks per 256-elem superblock\n\n int32_t sumi = 0;\n int32_t bsum = 0;\n const int base = sb32 * 32;\n for (int l = 0; l < 32; ++l) {\n const int k = base + l;\n const uint8_t byte = b_row[k / 2];\n const int nib = (k % 2 == 0) ? (byte & 0xF) : (byte >> 4);\n const int8_t qv = q8[k];\n sumi += nib * qv;\n bsum += qv;\n }\n acc += dact * (scale * (float)sumi - minv * (float)bsum);\n }\n out_row[n] = acc;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k1024.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k1024.json new file mode 100644 index 0000000000000000000000000000000000000000..25ec45b165a2f70d7dc249b7e78266638c9563e7 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k1024.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_q4_k_m_n2048_k1024", + "definition": "gemm_q4_k_m_n2048_k1024", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_q4_k_m_n2048_k1024. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm Q4_K (weight-only) specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A is a raw bf16 bit pattern (uint16_t) -- activations stay at the bf16\n// baseline tier (real GGML never stores activations statically in a\n// k-quant format either -- see kernel.cpp for the dynamic quantization this\n// implies). B is Q4_K-quantized, exposed as three flat (non-bit-packed-scale)\n// tensors:\n// B_q4: [N, K/2] uint8 -- byte i holds element 2i (low nibble),\n// element 2i+1 (high nibble), plain\n// sequential order (not ggml's own block-\n// interleaved order -- this is a simplified\n// Definition-level ABI, not GGML's bit-exact\n// block_q4_K struct).\n// B_scales: [N, K/32] raw fp16 bit pattern (uint16_t) -- one value per\n// 32-element sub-block, already combining\n// GGML's per-superblock `d` and per-sub-block\n// 6-bit `sc` into one number.\n// B_mins: [N, K/32] raw fp16 bit pattern (uint16_t) -- same, combining\n// `dmin*m`.\n// Dequant is `w[l] = B_scales[sb]*nibble(l) - B_mins[sb]`.\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 2048;\nconstexpr int K = 1024;\nconstexpr int K_half = 512;\nconstexpr int K_sub = 32;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B_q4: (N, K/2) uint8;\n// B_scales/B_mins: (N, K/32) raw fp16 bits; output: (M, N) float32.\nvoid inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B_q4*, B_scales*, B_mins*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output,\n const uint8_t* B_q4, const uint16_t* B_scales,\n const uint16_t* B_mins, int M)\n{\n inner_gemm(A, output, B_q4, B_scales, B_mins, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm Q4_K (weight-only, genuine low-bit dot product).\n// LLM target: replace this file with an optimised inner_gemm (SVE2/NEON\n// nibble-unpack + int8 dot-product intrinsics are the intended optimization\n// surface here).\n//\n// Unlike Definition.reference (which computes a clean, implementation-\n// agnostic dequant-then-fp32-multiply ground truth), this kernel mirrors\n// real GGML's ggml_vec_dot_q4_K_q8_K: the bf16 activation is dynamically\n// quantized into 256-element blocks (one scale, int8 values -- same idea as\n// ggml's Q8_K), then for each 32-element sub-block an integer dot product\n// against the unpacked Q4_K nibbles is computed and scale-corrected before\n// accumulating into a running fp32 total.\n//\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \n#include \n#include \n#include \nusing namespace gemm_def;\n\nnamespace {\n\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n\n// Proper IEEE-754 half->single conversion (fp16, not bf16 -- B_scales/B_mins\n// are real fp16, whose exponent field does NOT alias fp32's, so this needs\n// full mantissa/exponent remapping, unlike bf16_to_f32 above).\ninline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F;\n uint32_t mant = h & 0x3FF;\n uint32_t bits;\n if (exp == 0) {\n if (mant == 0) {\n bits = sign;\n } else {\n exp = 1;\n while ((mant & 0x400) == 0) { mant <<= 1; --exp; }\n mant &= 0x3FF;\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n } else if (exp == 0x1F) {\n bits = sign | 0x7F800000u | (mant << 13);\n } else {\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n float f;\n std::memcpy(&f, &bits, sizeof(f));\n return f;\n}\n\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M)\n{\n constexpr int K_super = K / 256;\n\n std::vector h(K);\n std::vector d_act(K_super);\n std::vector q8(K);\n\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n for (int k = 0; k < K; ++k) h[k] = bf16_to_f32(a_row[k]);\n\n // Dynamically quantize the activation row into 256-element blocks\n // (Q8_K-style: one scale, int8 values in [-127, 127]).\n for (int sb = 0; sb < K_super; ++sb) {\n float amax = 0.0f;\n for (int l = 0; l < 256; ++l) {\n float v = std::fabs(h[sb * 256 + l]);\n if (v > amax) amax = v;\n }\n const float d = amax / 127.0f;\n d_act[sb] = d;\n const float id = d > 0.0f ? 1.0f / d : 0.0f;\n for (int l = 0; l < 256; ++l) {\n int q = (int)std::lround(h[sb * 256 + l] * id);\n if (q > 127) q = 127;\n if (q < -127) q = -127;\n q8[sb * 256 + l] = (int8_t)q;\n }\n }\n\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint8_t* b_row = B_q4 + (long)n * K_half;\n const uint16_t* sc_row = B_scales + (long)n * K_sub;\n const uint16_t* mn_row = B_mins + (long)n * K_sub;\n\n float acc = 0.0f;\n for (int sb32 = 0; sb32 < K_sub; ++sb32) {\n const float scale = f16_to_f32(sc_row[sb32]);\n const float minv = f16_to_f32(mn_row[sb32]);\n const float dact = d_act[sb32 / 8]; // 8 sub-blocks per 256-elem superblock\n\n int32_t sumi = 0;\n int32_t bsum = 0;\n const int base = sb32 * 32;\n for (int l = 0; l < 32; ++l) {\n const int k = base + l;\n const uint8_t byte = b_row[k / 2];\n const int nib = (k % 2 == 0) ? (byte & 0xF) : (byte >> 4);\n const int8_t qv = q8[k];\n sumi += nib * qv;\n bsum += qv;\n }\n acc += dact * (scale * (float)sumi - minv * (float)bsum);\n }\n out_row[n] = acc;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k1536.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k1536.json new file mode 100644 index 0000000000000000000000000000000000000000..9dea3894ca9508df84d6d401bbbfe62fceddf1ac --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k1536.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_q4_k_m_n2048_k1536", + "definition": "gemm_q4_k_m_n2048_k1536", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_q4_k_m_n2048_k1536. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm Q4_K (weight-only) specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A is a raw bf16 bit pattern (uint16_t) -- activations stay at the bf16\n// baseline tier (real GGML never stores activations statically in a\n// k-quant format either -- see kernel.cpp for the dynamic quantization this\n// implies). B is Q4_K-quantized, exposed as three flat (non-bit-packed-scale)\n// tensors:\n// B_q4: [N, K/2] uint8 -- byte i holds element 2i (low nibble),\n// element 2i+1 (high nibble), plain\n// sequential order (not ggml's own block-\n// interleaved order -- this is a simplified\n// Definition-level ABI, not GGML's bit-exact\n// block_q4_K struct).\n// B_scales: [N, K/32] raw fp16 bit pattern (uint16_t) -- one value per\n// 32-element sub-block, already combining\n// GGML's per-superblock `d` and per-sub-block\n// 6-bit `sc` into one number.\n// B_mins: [N, K/32] raw fp16 bit pattern (uint16_t) -- same, combining\n// `dmin*m`.\n// Dequant is `w[l] = B_scales[sb]*nibble(l) - B_mins[sb]`.\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 2048;\nconstexpr int K = 1536;\nconstexpr int K_half = 768;\nconstexpr int K_sub = 48;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B_q4: (N, K/2) uint8;\n// B_scales/B_mins: (N, K/32) raw fp16 bits; output: (M, N) float32.\nvoid inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B_q4*, B_scales*, B_mins*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output,\n const uint8_t* B_q4, const uint16_t* B_scales,\n const uint16_t* B_mins, int M)\n{\n inner_gemm(A, output, B_q4, B_scales, B_mins, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm Q4_K (weight-only, genuine low-bit dot product).\n// LLM target: replace this file with an optimised inner_gemm (SVE2/NEON\n// nibble-unpack + int8 dot-product intrinsics are the intended optimization\n// surface here).\n//\n// Unlike Definition.reference (which computes a clean, implementation-\n// agnostic dequant-then-fp32-multiply ground truth), this kernel mirrors\n// real GGML's ggml_vec_dot_q4_K_q8_K: the bf16 activation is dynamically\n// quantized into 256-element blocks (one scale, int8 values -- same idea as\n// ggml's Q8_K), then for each 32-element sub-block an integer dot product\n// against the unpacked Q4_K nibbles is computed and scale-corrected before\n// accumulating into a running fp32 total.\n//\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \n#include \n#include \n#include \nusing namespace gemm_def;\n\nnamespace {\n\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n\n// Proper IEEE-754 half->single conversion (fp16, not bf16 -- B_scales/B_mins\n// are real fp16, whose exponent field does NOT alias fp32's, so this needs\n// full mantissa/exponent remapping, unlike bf16_to_f32 above).\ninline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F;\n uint32_t mant = h & 0x3FF;\n uint32_t bits;\n if (exp == 0) {\n if (mant == 0) {\n bits = sign;\n } else {\n exp = 1;\n while ((mant & 0x400) == 0) { mant <<= 1; --exp; }\n mant &= 0x3FF;\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n } else if (exp == 0x1F) {\n bits = sign | 0x7F800000u | (mant << 13);\n } else {\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n float f;\n std::memcpy(&f, &bits, sizeof(f));\n return f;\n}\n\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M)\n{\n constexpr int K_super = K / 256;\n\n std::vector h(K);\n std::vector d_act(K_super);\n std::vector q8(K);\n\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n for (int k = 0; k < K; ++k) h[k] = bf16_to_f32(a_row[k]);\n\n // Dynamically quantize the activation row into 256-element blocks\n // (Q8_K-style: one scale, int8 values in [-127, 127]).\n for (int sb = 0; sb < K_super; ++sb) {\n float amax = 0.0f;\n for (int l = 0; l < 256; ++l) {\n float v = std::fabs(h[sb * 256 + l]);\n if (v > amax) amax = v;\n }\n const float d = amax / 127.0f;\n d_act[sb] = d;\n const float id = d > 0.0f ? 1.0f / d : 0.0f;\n for (int l = 0; l < 256; ++l) {\n int q = (int)std::lround(h[sb * 256 + l] * id);\n if (q > 127) q = 127;\n if (q < -127) q = -127;\n q8[sb * 256 + l] = (int8_t)q;\n }\n }\n\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint8_t* b_row = B_q4 + (long)n * K_half;\n const uint16_t* sc_row = B_scales + (long)n * K_sub;\n const uint16_t* mn_row = B_mins + (long)n * K_sub;\n\n float acc = 0.0f;\n for (int sb32 = 0; sb32 < K_sub; ++sb32) {\n const float scale = f16_to_f32(sc_row[sb32]);\n const float minv = f16_to_f32(mn_row[sb32]);\n const float dact = d_act[sb32 / 8]; // 8 sub-blocks per 256-elem superblock\n\n int32_t sumi = 0;\n int32_t bsum = 0;\n const int base = sb32 * 32;\n for (int l = 0; l < 32; ++l) {\n const int k = base + l;\n const uint8_t byte = b_row[k / 2];\n const int nib = (k % 2 == 0) ? (byte & 0xF) : (byte >> 4);\n const int8_t qv = q8[k];\n sumi += nib * qv;\n bsum += qv;\n }\n acc += dact * (scale * (float)sumi - minv * (float)bsum);\n }\n out_row[n] = acc;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k2048.json b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k2048.json new file mode 100644 index 0000000000000000000000000000000000000000..082ec45e5ad675c0ab7bbf6eeac5592d5fcedb6a --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/gemm/gemm_q4_k_m_n2048_k2048.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_gemm_q4_k_m_n2048_k2048", + "definition": "gemm_q4_k_m_n2048_k2048", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer gemm for gemm_q4_k_m_n2048_k2048. Constexpr-baked dims; armbench_entry_gemm calls inner_gemm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "gemm.cpp::armbench_entry_gemm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "gemm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this gemm Q4_K (weight-only) specialisation.\n// C[m, n] = sum_k A[m, k] * B[n, k] (B is the [N, K] \"weight\" matrix, transposed)\n// A is a raw bf16 bit pattern (uint16_t) -- activations stay at the bf16\n// baseline tier (real GGML never stores activations statically in a\n// k-quant format either -- see kernel.cpp for the dynamic quantization this\n// implies). B is Q4_K-quantized, exposed as three flat (non-bit-packed-scale)\n// tensors:\n// B_q4: [N, K/2] uint8 -- byte i holds element 2i (low nibble),\n// element 2i+1 (high nibble), plain\n// sequential order (not ggml's own block-\n// interleaved order -- this is a simplified\n// Definition-level ABI, not GGML's bit-exact\n// block_q4_K struct).\n// B_scales: [N, K/32] raw fp16 bit pattern (uint16_t) -- one value per\n// 32-element sub-block, already combining\n// GGML's per-superblock `d` and per-sub-block\n// 6-bit `sc` into one number.\n// B_mins: [N, K/32] raw fp16 bit pattern (uint16_t) -- same, combining\n// `dmin*m`.\n// Dequant is `w[l] = B_scales[sb]*nibble(l) - B_mins[sb]`.\n// Output accumulates/returns in fp32.\nnamespace gemm_def {\nconstexpr int N = 2048;\nconstexpr int K = 2048;\nconstexpr int K_half = 1024;\nconstexpr int K_sub = 64;\n} // namespace gemm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. A: (M, K) bf16; B_q4: (N, K/2) uint8;\n// B_scales/B_mins: (N, K/32) raw fp16 bits; output: (M, N) float32.\nvoid inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "gemm.cpp", + "content": "// Binding harness: forwards straight to inner_gemm (no derived dims needed).\n// ABI: armbench_entry_gemm(A*, output*, B_q4*, B_scales*, B_mins*, M)\n#include \"gemm.h\"\nusing namespace gemm_def;\n\nextern \"C\" int armbench_entry_gemm(const uint16_t* A, float* output,\n const uint8_t* B_q4, const uint16_t* B_scales,\n const uint16_t* B_mins, int M)\n{\n inner_gemm(A, output, B_q4, B_scales, B_mins, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar gemm Q4_K (weight-only, genuine low-bit dot product).\n// LLM target: replace this file with an optimised inner_gemm (SVE2/NEON\n// nibble-unpack + int8 dot-product intrinsics are the intended optimization\n// surface here).\n//\n// Unlike Definition.reference (which computes a clean, implementation-\n// agnostic dequant-then-fp32-multiply ground truth), this kernel mirrors\n// real GGML's ggml_vec_dot_q4_K_q8_K: the bf16 activation is dynamically\n// quantized into 256-element blocks (one scale, int8 values -- same idea as\n// ggml's Q8_K), then for each 32-element sub-block an integer dot product\n// against the unpacked Q4_K nibbles is computed and scale-corrected before\n// accumulating into a running fp32 total.\n//\n// All per-definition constants live in gemm_def:: (gemm.h).\n#include \"gemm.h\"\n#include \n#include \n#include \n#include \nusing namespace gemm_def;\n\nnamespace {\n\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n\n// Proper IEEE-754 half->single conversion (fp16, not bf16 -- B_scales/B_mins\n// are real fp16, whose exponent field does NOT alias fp32's, so this needs\n// full mantissa/exponent remapping, unlike bf16_to_f32 above).\ninline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F;\n uint32_t mant = h & 0x3FF;\n uint32_t bits;\n if (exp == 0) {\n if (mant == 0) {\n bits = sign;\n } else {\n exp = 1;\n while ((mant & 0x400) == 0) { mant <<= 1; --exp; }\n mant &= 0x3FF;\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n } else if (exp == 0x1F) {\n bits = sign | 0x7F800000u | (mant << 13);\n } else {\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n float f;\n std::memcpy(&f, &bits, sizeof(f));\n return f;\n}\n\n} // namespace\n\nextern \"C\" void inner_gemm(const uint16_t* A, float* output, const uint8_t* B_q4,\n const uint16_t* B_scales, const uint16_t* B_mins, int M)\n{\n constexpr int K_super = K / 256;\n\n std::vector h(K);\n std::vector d_act(K_super);\n std::vector q8(K);\n\n for (int m = 0; m < M; ++m) {\n const uint16_t* a_row = A + (long)m * K;\n for (int k = 0; k < K; ++k) h[k] = bf16_to_f32(a_row[k]);\n\n // Dynamically quantize the activation row into 256-element blocks\n // (Q8_K-style: one scale, int8 values in [-127, 127]).\n for (int sb = 0; sb < K_super; ++sb) {\n float amax = 0.0f;\n for (int l = 0; l < 256; ++l) {\n float v = std::fabs(h[sb * 256 + l]);\n if (v > amax) amax = v;\n }\n const float d = amax / 127.0f;\n d_act[sb] = d;\n const float id = d > 0.0f ? 1.0f / d : 0.0f;\n for (int l = 0; l < 256; ++l) {\n int q = (int)std::lround(h[sb * 256 + l] * id);\n if (q > 127) q = 127;\n if (q < -127) q = -127;\n q8[sb * 256 + l] = (int8_t)q;\n }\n }\n\n float* out_row = output + (long)m * N;\n for (int n = 0; n < N; ++n) {\n const uint8_t* b_row = B_q4 + (long)n * K_half;\n const uint16_t* sc_row = B_scales + (long)n * K_sub;\n const uint16_t* mn_row = B_mins + (long)n * K_sub;\n\n float acc = 0.0f;\n for (int sb32 = 0; sb32 < K_sub; ++sb32) {\n const float scale = f16_to_f32(sc_row[sb32]);\n const float minv = f16_to_f32(mn_row[sb32]);\n const float dact = d_act[sb32 / 8]; // 8 sub-blocks per 256-elem superblock\n\n int32_t sumi = 0;\n int32_t bsum = 0;\n const int base = sb32 * 32;\n for (int l = 0; l < 32; ++l) {\n const int k = base + l;\n const uint8_t byte = b_row[k / 2];\n const int nib = (k % 2 == 0) ? (byte & 0xF) : (byte >> 4);\n const int8_t qv = q8[k];\n sumi += nib * qv;\n bsum += qv;\n }\n acc += dact * (scale * (float)sumi - minv * (float)bsum);\n }\n out_row[n] = acc;\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/mha/mha_bf16_h16_d128_kvh16.json b/solutions/llama.cpp/reference-scalar/mha/mha_bf16_h16_d128_kvh16.json new file mode 100644 index 0000000000000000000000000000000000000000..0d8f7007fe9c7bebb2e851fedc16df9e8683ab62 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/mha/mha_bf16_h16_d128_kvh16.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_mha_bf16_h16_d128_kvh16", + "definition": "mha_bf16_h16_d128_kvh16", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer mha for mha_bf16_h16_d128_kvh16. Constexpr-baked dims; armbench_entry_mha calls inner_mha. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "mha.cpp::armbench_entry_mha", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "mha.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this mha bf16 specialisation.\n// Non-causal softmax(Q\u00b7K^T / sqrt(head_dim))\u00b7V per head.\n// Q/K/V are raw bf16 bit patterns (uint16_t); output accumulates/returns in\n// fp32.\nnamespace mha_def {\nconstexpr int NHeads = 16;\nconstexpr int HeadDim = 128;\nconstexpr int KvHeads = 16;\n} // namespace mha_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M, S are the var dims. Q: (M, n_heads, head_dim) bf16; K/V: (S, kv_heads,\n// head_dim) bf16; output: (M, n_heads, head_dim) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_mha(const uint16_t* Q, float* output, const uint16_t* K, const uint16_t* V,\n int M, int S);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "mha.cpp", + "content": "// Binding harness: forwards straight to inner_mha (no derived dims needed).\n// ABI: armbench_entry_mha(Q*, output*, K*, V*, M, S)\n#include \"mha.h\"\nusing namespace mha_def;\n\nextern \"C\" int armbench_entry_mha(const uint16_t* Q, float* output, const uint16_t* K,\n const uint16_t* V, int M, int S)\n{\n inner_mha(Q, output, K, V, M, S);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar mha bf16 (fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_mha.\n// All per-definition constants live in mha_def:: (mha.h).\n// Assumes NHeads == KvHeads (standard MHA, no GQA head-repeat) \u2014 matches this\n// definition's reference implementation exactly.\n#include \"mha.h\"\n#include \n#include \n#include \nusing namespace mha_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_mha(const uint16_t* Q, float* output, const uint16_t* K,\n const uint16_t* V, int M, int S)\n{\n const float scale = 1.0f / std::sqrt((float)HeadDim);\n std::vector scores(S);\n\n for (int h = 0; h < NHeads; ++h) {\n for (int m = 0; m < M; ++m) {\n const uint16_t* q_row = Q + ((long)m * NHeads + h) * HeadDim;\n\n float max_score = -INFINITY;\n for (int s = 0; s < S; ++s) {\n const uint16_t* k_row = K + ((long)s * KvHeads + h) * HeadDim;\n float dot = 0.0f;\n for (int d = 0; d < HeadDim; ++d) {\n dot += bf16_to_f32(q_row[d]) * bf16_to_f32(k_row[d]);\n }\n scores[s] = dot * scale;\n if (scores[s] > max_score) max_score = scores[s];\n }\n\n float sum = 0.0f;\n for (int s = 0; s < S; ++s) {\n scores[s] = std::exp(scores[s] - max_score);\n sum += scores[s];\n }\n\n float* out_row = output + ((long)m * NHeads + h) * HeadDim;\n for (int d = 0; d < HeadDim; ++d) out_row[d] = 0.0f;\n for (int s = 0; s < S; ++s) {\n const float w = scores[s] / sum;\n const uint16_t* v_row = V + ((long)s * KvHeads + h) * HeadDim;\n for (int d = 0; d < HeadDim; ++d) {\n out_row[d] += w * bf16_to_f32(v_row[d]);\n }\n }\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/mha/mha_fp32_h16_d128_kvh16.json b/solutions/llama.cpp/reference-scalar/mha/mha_fp32_h16_d128_kvh16.json deleted file mode 100644 index 6aff5804d349e02189084ea7dd4c7c9caa20e52f..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/mha/mha_fp32_h16_d128_kvh16.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_mha_fp32_h16_d128_kvh16", - "definition": "mha_fp32_h16_d128_kvh16", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_mha", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "mha.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) mha baseline.\n// Called by armbench_entry_mha (binding.cpp); implemented by kernel.cpp.\n// Q is row-major fp32 [M, n_heads, head_dim]; K/V are row-major fp32\n// [S, kv_heads, head_dim]; out is row-major fp32 [M, n_heads, head_dim].\n// Non-causal softmax(Q·K^T / sqrt(head_dim))·V per head.\nint armbench_llamacpp_mha(const float* Q, const float* K, const float* V,\n float* out, int64_t M, int64_t S,\n int64_t n_heads, int64_t head_dim, int64_t kv_heads);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"mha.h\"\n\nnamespace {\nconstexpr int64_t kNHeads = 16;\nconstexpr int64_t kHeadDim = 128;\nconstexpr int64_t kKvHeads = 16;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=Q fp32 [M,n_heads,head_dim], [1]=K fp32 [S,kv_heads,head_dim],\n// [2]=V fp32 [S,kv_heads,head_dim]; var_axes: [0]=M, [1]=S\nint armbench_entry_mha(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_mha(\n reinterpret_cast(inputs[0]),\n reinterpret_cast(inputs[1]),\n reinterpret_cast(inputs[2]),\n reinterpret_cast(output),\n var_axes[0], var_axes[1], kNHeads, kHeadDim, kKvHeads);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"mha.h\"\n#include \n#include \n// Naive scalar non-causal MHA reference: softmax(Q.K^T / sqrt(head_dim)) . V per head.\n// Q[M,H,D] row-major; K/V[S,KVH,D]; out[M,H,D]. GQA: query head h -> kv head h*KVH/H.\nint armbench_llamacpp_mha(const float* Q, const float* K, const float* V,\n float* out, int64_t M, int64_t S,\n int64_t n_heads, int64_t head_dim, int64_t kv_heads) {\n float scale = 1.0f / std::sqrt((float)head_dim);\n std::vector sc((size_t)S);\n for (int64_t h = 0; h < n_heads; ++h) {\n int64_t kvh = (kv_heads == n_heads) ? h : (h * kv_heads / n_heads);\n for (int64_t m = 0; m < M; ++m) {\n const float* q = Q + ((size_t)m * n_heads + h) * head_dim;\n float mx = -1e30f;\n for (int64_t s = 0; s < S; ++s) {\n const float* k = K + ((size_t)s * kv_heads + kvh) * head_dim;\n double acc = 0.0; for (int64_t d = 0; d < head_dim; ++d) acc += (double)q[d] * k[d];\n sc[s] = (float)acc * scale; if (sc[s] > mx) mx = sc[s];\n }\n double sum = 0.0;\n for (int64_t s = 0; s < S; ++s) { sc[s] = std::exp(sc[s] - mx); sum += sc[s]; }\n float inv = (float)(1.0 / sum);\n float* orow = out + ((size_t)m * n_heads + h) * head_dim;\n for (int64_t d = 0; d < head_dim; ++d) {\n double acc = 0.0;\n for (int64_t s = 0; s < S; ++s)\n acc += (double)sc[s] * inv * V[((size_t)s * kv_heads + kvh) * head_dim + d];\n orow[d] = (float)acc;\n }\n }\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for mha_fp32_h16_d128_kvh16 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/moe/moe_bf16_e60_k4_d2048_ff1408.json b/solutions/llama.cpp/reference-scalar/moe/moe_bf16_e60_k4_d2048_ff1408.json new file mode 100644 index 0000000000000000000000000000000000000000..d9205abf034a373ec1d91745ea5d2ff06dcca70b --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/moe/moe_bf16_e60_k4_d2048_ff1408.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_moe_bf16_e60_k4_d2048_ff1408", + "definition": "moe_bf16_e60_k4_d2048_ff1408", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer moe for moe_bf16_e60_k4_d2048_ff1408. Constexpr-baked dims; armbench_entry_moe calls inner_moe. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "moe.cpp::armbench_entry_moe", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "moe.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this moe bf16 specialisation.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states/router_weight/gate_proj/up_proj/down_proj are raw bf16 bit\n// patterns (uint16_t); output accumulates/returns in fp32.\nnamespace moe_def {\nconstexpr int NEmbd = 2048;\nconstexpr int NFf = 1408;\nconstexpr int NExpert = 60;\nconstexpr int NExpertUsed = 4;\n} // namespace moe_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// n_tokens is the only var dim. hidden_states: (n_tokens, n_embd) bf16;\n// router_weight: (n_expert, n_embd) bf16; gate/up_proj: (n_expert, n_ff,\n// n_embd) bf16; down_proj: (n_expert, n_embd, n_ff) bf16;\n// output: (n_tokens, n_embd) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_moe(const uint16_t* hidden_states, float* output,\n const uint16_t* router_weight, const uint16_t* gate_proj,\n const uint16_t* up_proj, const uint16_t* down_proj,\n int n_tokens);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "moe.cpp", + "content": "// Binding harness: forwards straight to inner_moe (no derived dims needed).\n// ABI: armbench_entry_moe(hidden_states*, output*, router_weight*, gate_proj*,\n// up_proj*, down_proj*, n_tokens)\n#include \"moe.h\"\nusing namespace moe_def;\n\nextern \"C\" int armbench_entry_moe(const uint16_t* hidden_states, float* output,\n const uint16_t* router_weight, const uint16_t* gate_proj,\n const uint16_t* up_proj, const uint16_t* down_proj,\n int n_tokens)\n{\n inner_moe(hidden_states, output, router_weight, gate_proj, up_proj, down_proj, n_tokens);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar moe bf16 (fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_moe.\n// All per-definition constants live in moe_def:: (moe.h).\n#include \"moe.h\"\n#include \n#include \n#include \n#include \nusing namespace moe_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_moe(const uint16_t* hidden_states, float* output,\n const uint16_t* router_weight, const uint16_t* gate_proj,\n const uint16_t* up_proj, const uint16_t* down_proj,\n int n_tokens)\n{\n std::vector h(NEmbd);\n std::vector logits(NExpert);\n std::vector probs(NExpert);\n std::vector used(NExpert);\n std::vector top_idx(NExpertUsed);\n std::vector top_w(NExpertUsed);\n std::vector gu(NFf);\n\n for (int t = 0; t < n_tokens; ++t) {\n const uint16_t* hs_row = hidden_states + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) h[d] = bf16_to_f32(hs_row[d]);\n\n // Router logits + softmax over all experts.\n for (int e = 0; e < NExpert; ++e) {\n const uint16_t* rw = router_weight + (long)e * NEmbd;\n float dot = 0.0f;\n for (int d = 0; d < NEmbd; ++d) dot += h[d] * bf16_to_f32(rw[d]);\n logits[e] = dot;\n }\n float max_logit = logits[0];\n for (int e = 1; e < NExpert; ++e) if (logits[e] > max_logit) max_logit = logits[e];\n float sum_exp = 0.0f;\n for (int e = 0; e < NExpert; ++e) {\n probs[e] = std::exp(logits[e] - max_logit);\n sum_exp += probs[e];\n }\n for (int e = 0; e < NExpert; ++e) probs[e] /= sum_exp;\n\n // Top-k selection (repeated argmax over unselected experts) + renormalize.\n std::fill(used.begin(), used.end(), false);\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n int best = -1;\n for (int e = 0; e < NExpert; ++e) {\n if (!used[e] && (best < 0 || probs[e] > probs[best])) best = e;\n }\n used[best] = true;\n top_idx[ki] = best;\n top_w[ki] = probs[best];\n }\n float wsum = 0.0f;\n for (int ki = 0; ki < NExpertUsed; ++ki) wsum += top_w[ki];\n for (int ki = 0; ki < NExpertUsed; ++ki) top_w[ki] /= wsum;\n\n float* out_row = output + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) out_row[d] = 0.0f;\n\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n const int e = top_idx[ki];\n const uint16_t* gate_e = gate_proj + (long)e * NFf * NEmbd;\n const uint16_t* up_e = up_proj + (long)e * NFf * NEmbd;\n const uint16_t* down_e = down_proj + (long)e * NEmbd * NFf;\n\n for (int f = 0; f < NFf; ++f) {\n const uint16_t* gate_row = gate_e + (long)f * NEmbd;\n const uint16_t* up_row = up_e + (long)f * NEmbd;\n float gv = 0.0f, uv = 0.0f;\n for (int d = 0; d < NEmbd; ++d) {\n gv += bf16_to_f32(gate_row[d]) * h[d];\n uv += bf16_to_f32(up_row[d]) * h[d];\n }\n const float silu = gv / (1.0f + std::exp(-gv));\n gu[f] = silu * uv;\n }\n\n for (int d = 0; d < NEmbd; ++d) {\n float acc = 0.0f;\n const uint16_t* down_row = down_e + (long)d * NFf;\n for (int f = 0; f < NFf; ++f) {\n acc += bf16_to_f32(down_row[f]) * gu[f];\n }\n out_row[d] += top_w[ki] * acc;\n }\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/moe/moe_bf16_e64_k8_d2048_ff1024.json b/solutions/llama.cpp/reference-scalar/moe/moe_bf16_e64_k8_d2048_ff1024.json new file mode 100644 index 0000000000000000000000000000000000000000..76f4c5cba80c96d8b712bf457bd4a1066edc319b --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/moe/moe_bf16_e64_k8_d2048_ff1024.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_moe_bf16_e64_k8_d2048_ff1024", + "definition": "moe_bf16_e64_k8_d2048_ff1024", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer moe for moe_bf16_e64_k8_d2048_ff1024. Constexpr-baked dims; armbench_entry_moe calls inner_moe. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "moe.cpp::armbench_entry_moe", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "moe.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this moe bf16 specialisation.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states/router_weight/gate_proj/up_proj/down_proj are raw bf16 bit\n// patterns (uint16_t); output accumulates/returns in fp32.\nnamespace moe_def {\nconstexpr int NEmbd = 2048;\nconstexpr int NFf = 1024;\nconstexpr int NExpert = 64;\nconstexpr int NExpertUsed = 8;\n} // namespace moe_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// n_tokens is the only var dim. hidden_states: (n_tokens, n_embd) bf16;\n// router_weight: (n_expert, n_embd) bf16; gate/up_proj: (n_expert, n_ff,\n// n_embd) bf16; down_proj: (n_expert, n_embd, n_ff) bf16;\n// output: (n_tokens, n_embd) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_moe(const uint16_t* hidden_states, float* output,\n const uint16_t* router_weight, const uint16_t* gate_proj,\n const uint16_t* up_proj, const uint16_t* down_proj,\n int n_tokens);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "moe.cpp", + "content": "// Binding harness: forwards straight to inner_moe (no derived dims needed).\n// ABI: armbench_entry_moe(hidden_states*, output*, router_weight*, gate_proj*,\n// up_proj*, down_proj*, n_tokens)\n#include \"moe.h\"\nusing namespace moe_def;\n\nextern \"C\" int armbench_entry_moe(const uint16_t* hidden_states, float* output,\n const uint16_t* router_weight, const uint16_t* gate_proj,\n const uint16_t* up_proj, const uint16_t* down_proj,\n int n_tokens)\n{\n inner_moe(hidden_states, output, router_weight, gate_proj, up_proj, down_proj, n_tokens);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar moe bf16 (fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_moe.\n// All per-definition constants live in moe_def:: (moe.h).\n#include \"moe.h\"\n#include \n#include \n#include \n#include \nusing namespace moe_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_moe(const uint16_t* hidden_states, float* output,\n const uint16_t* router_weight, const uint16_t* gate_proj,\n const uint16_t* up_proj, const uint16_t* down_proj,\n int n_tokens)\n{\n std::vector h(NEmbd);\n std::vector logits(NExpert);\n std::vector probs(NExpert);\n std::vector used(NExpert);\n std::vector top_idx(NExpertUsed);\n std::vector top_w(NExpertUsed);\n std::vector gu(NFf);\n\n for (int t = 0; t < n_tokens; ++t) {\n const uint16_t* hs_row = hidden_states + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) h[d] = bf16_to_f32(hs_row[d]);\n\n // Router logits + softmax over all experts.\n for (int e = 0; e < NExpert; ++e) {\n const uint16_t* rw = router_weight + (long)e * NEmbd;\n float dot = 0.0f;\n for (int d = 0; d < NEmbd; ++d) dot += h[d] * bf16_to_f32(rw[d]);\n logits[e] = dot;\n }\n float max_logit = logits[0];\n for (int e = 1; e < NExpert; ++e) if (logits[e] > max_logit) max_logit = logits[e];\n float sum_exp = 0.0f;\n for (int e = 0; e < NExpert; ++e) {\n probs[e] = std::exp(logits[e] - max_logit);\n sum_exp += probs[e];\n }\n for (int e = 0; e < NExpert; ++e) probs[e] /= sum_exp;\n\n // Top-k selection (repeated argmax over unselected experts) + renormalize.\n std::fill(used.begin(), used.end(), false);\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n int best = -1;\n for (int e = 0; e < NExpert; ++e) {\n if (!used[e] && (best < 0 || probs[e] > probs[best])) best = e;\n }\n used[best] = true;\n top_idx[ki] = best;\n top_w[ki] = probs[best];\n }\n float wsum = 0.0f;\n for (int ki = 0; ki < NExpertUsed; ++ki) wsum += top_w[ki];\n for (int ki = 0; ki < NExpertUsed; ++ki) top_w[ki] /= wsum;\n\n float* out_row = output + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) out_row[d] = 0.0f;\n\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n const int e = top_idx[ki];\n const uint16_t* gate_e = gate_proj + (long)e * NFf * NEmbd;\n const uint16_t* up_e = up_proj + (long)e * NFf * NEmbd;\n const uint16_t* down_e = down_proj + (long)e * NEmbd * NFf;\n\n for (int f = 0; f < NFf; ++f) {\n const uint16_t* gate_row = gate_e + (long)f * NEmbd;\n const uint16_t* up_row = up_e + (long)f * NEmbd;\n float gv = 0.0f, uv = 0.0f;\n for (int d = 0; d < NEmbd; ++d) {\n gv += bf16_to_f32(gate_row[d]) * h[d];\n uv += bf16_to_f32(up_row[d]) * h[d];\n }\n const float silu = gv / (1.0f + std::exp(-gv));\n gu[f] = silu * uv;\n }\n\n for (int d = 0; d < NEmbd; ++d) {\n float acc = 0.0f;\n const uint16_t* down_row = down_e + (long)d * NFf;\n for (int f = 0; f < NFf; ++f) {\n acc += bf16_to_f32(down_row[f]) * gu[f];\n }\n out_row[d] += top_w[ki] * acc;\n }\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/moe/moe_fp32_e60_k4_d2048_ff1408.json b/solutions/llama.cpp/reference-scalar/moe/moe_fp32_e60_k4_d2048_ff1408.json deleted file mode 100644 index 31295a25be9ec089af3beafb3740cfbb055be822..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/moe/moe_fp32_e60_k4_d2048_ff1408.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_moe_fp32_e60_k4_d2048_ff1408", - "definition": "moe_fp32_e60_k4_d2048_ff1408", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_moe", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "moe.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major [T, n_embd]; router_weight fp32 [n_expert, n_embd];\n// gate/up_proj [n_expert, n_ff, n_embd]; down_proj [n_expert, n_embd, n_ff];\n// out fp32 [T, n_embd]. For q8_0, hidden_states and the three projections are\n// ggml block_q8_0 rows over their last axis (34-byte {fp16 d; int8 qs[32]}\n// blocks, repacked by the Python adapter); router_weight stays fp32.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1408;\nconstexpr int64_t kNExpert = 60;\nconstexpr int64_t kNExpertUsed = 4;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=hidden_states fp32 [T,n_embd], [1]=router_weight fp32\n// [n_expert,n_embd], [2]=gate_proj fp32 [n_expert,n_ff,n_embd], [3]=up_proj\n// fp32 [n_expert,n_ff,n_embd], [4]=down_proj fp32 [n_expert,n_embd,n_ff];\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n reinterpret_cast(inputs[1]),\n inputs[2], inputs[3], inputs[4],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed, /*is_q8=*/false);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"moe.h\"\n#include \n#include \n#include \n#include \n#include \n\nstatic inline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F, mant = h & 0x3FF, f;\n if (exp == 0) {\n if (mant == 0) f = sign;\n else { exp = 127 - 15 + 1; while (!(mant & 0x400)) { mant <<= 1; exp--; }\n mant &= 0x3FF; f = sign | (exp << 23) | (mant << 13); }\n } else if (exp == 0x1F) { f = sign | 0x7F800000u | (mant << 13); }\n else { f = sign | ((exp - 15 + 127) << 23) | (mant << 13); }\n float o; std::memcpy(&o, &f, 4); return o;\n}\n// Dequant one block_q8_0 row: nb 34-byte blocks {fp16 d; int8 qs[32]} -> nb*32 floats.\nstatic inline void dq_row(const uint8_t* p, int64_t nb, float* dst) {\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = p + b * 34; uint16_t d16; std::memcpy(&d16, bp, 2);\n float d = f16_to_f32(d16); const int8_t* qs = (const int8_t*)(bp + 2);\n for (int j = 0; j < 32; ++j) dst[b * 32 + j] = d * (float)qs[j];\n }\n}\n\n// Naive scalar SwiGLU MoE reference (softmax gating, top-k, renorm top-k weights):\n// probs = softmax(hidden @ router^T); pick top-k experts; w /= sum(w);\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x)).\n// q8_0: hidden + gate/up/down are block_q8_0 over their last axis; router stays fp32.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t T, int64_t d, int64_t ff,\n int64_t E, int64_t K, bool is_q8) {\n int64_t nbd = d / 32, nbf = ff / 32;\n const uint8_t* hs8 = (const uint8_t*)hidden_states;\n const uint8_t* g8 = (const uint8_t*)gate_proj;\n const uint8_t* u8 = (const uint8_t*)up_proj;\n const uint8_t* dn8 = (const uint8_t*)down_proj;\n const float* hsf = (const float*)hidden_states;\n const float* gf = (const float*)gate_proj;\n const float* uf = (const float*)up_proj;\n const float* dnf = (const float*)down_proj;\n\n std::vector hs(d), row(d > ff ? d : ff), gu(ff), logits(E), probs(E);\n for (int64_t t = 0; t < T; ++t) {\n if (is_q8) dq_row(hs8 + (size_t)t * nbd * 34, nbd, hs.data());\n else std::memcpy(hs.data(), hsf + (size_t)t * d, d * sizeof(float));\n\n float mx = -1e30f;\n for (int64_t e = 0; e < E; ++e) {\n const float* rw = router_weight + (size_t)e * d;\n double acc = 0.0; for (int64_t j = 0; j < d; ++j) acc += (double)hs[j] * rw[j];\n logits[e] = (float)acc; if (logits[e] > mx) mx = logits[e];\n }\n double sum = 0.0;\n for (int64_t e = 0; e < E; ++e) { probs[e] = std::exp(logits[e] - mx); sum += probs[e]; }\n for (int64_t e = 0; e < E; ++e) probs[e] = (float)(probs[e] / sum);\n\n std::vector idx(E); for (int64_t e = 0; e < E; ++e) idx[e] = e;\n std::partial_sort(idx.begin(), idx.begin() + K, idx.end(),\n [&](int64_t a, int64_t b){ return probs[a] > probs[b]; });\n double wsum = 0.0; for (int64_t ki = 0; ki < K; ++ki) wsum += probs[idx[ki]];\n\n float* orow = out + (size_t)t * d;\n for (int64_t dd = 0; dd < d; ++dd) orow[dd] = 0.0f;\n for (int64_t ki = 0; ki < K; ++ki) {\n int64_t e = idx[ki]; float w = (float)(probs[e] / wsum);\n for (int64_t f = 0; f < ff; ++f) {\n const float* gr; const float* ur;\n if (is_q8) { dq_row(g8 + ((size_t)e * ff + f) * nbd * 34, nbd, row.data()); gr = row.data(); }\n else gr = gf + ((size_t)e * ff + f) * d;\n double ga = 0.0; for (int64_t j = 0; j < d; ++j) ga += (double)gr[j] * hs[j];\n float g = (float)ga;\n std::vector urow;\n if (is_q8) { urow.resize(d); dq_row(u8 + ((size_t)e * ff + f) * nbd * 34, nbd, urow.data()); ur = urow.data(); }\n else ur = uf + ((size_t)e * ff + f) * d;\n double ua = 0.0; for (int64_t j = 0; j < d; ++j) ua += (double)ur[j] * hs[j];\n float u = (float)ua;\n float silu = g / (1.0f + std::exp(-g));\n gu[f] = silu * u;\n }\n for (int64_t dd = 0; dd < d; ++dd) {\n const float* dr;\n if (is_q8) { dq_row(dn8 + ((size_t)e * d + dd) * nbf * 34, nbf, row.data()); dr = row.data(); }\n else dr = dnf + ((size_t)e * d + dd) * ff;\n double a = 0.0; for (int64_t f = 0; f < ff; ++f) a += (double)dr[f] * gu[f];\n orow[dd] += w * (float)a;\n }\n }\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for moe_fp32_e60_k4_d2048_ff1408 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/moe/moe_fp32_e64_k8_d2048_ff1024.json b/solutions/llama.cpp/reference-scalar/moe/moe_fp32_e64_k8_d2048_ff1024.json deleted file mode 100644 index 1534d652844d75d7aa5349b665d6a70337fa5c9b..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/moe/moe_fp32_e64_k8_d2048_ff1024.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_moe_fp32_e64_k8_d2048_ff1024", - "definition": "moe_fp32_e64_k8_d2048_ff1024", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_moe", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "moe.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) moe baseline.\n// Called by armbench_entry_moe (binding.cpp); implemented by kernel.cpp.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is row-major [T, n_embd]; router_weight fp32 [n_expert, n_embd];\n// gate/up_proj [n_expert, n_ff, n_embd]; down_proj [n_expert, n_embd, n_ff];\n// out fp32 [T, n_embd]. For q8_0, hidden_states and the three projections are\n// ggml block_q8_0 rows over their last axis (34-byte {fp16 d; int8 qs[32]}\n// blocks, repacked by the Python adapter); router_weight stays fp32.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t n_tokens, int64_t n_embd, int64_t n_ff,\n int64_t n_expert, int64_t n_expert_used, bool is_q8);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"moe.h\"\n\nnamespace {\nconstexpr int64_t kNEmbd = 2048;\nconstexpr int64_t kNFf = 1024;\nconstexpr int64_t kNExpert = 64;\nconstexpr int64_t kNExpertUsed = 8;\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=hidden_states fp32 [T,n_embd], [1]=router_weight fp32\n// [n_expert,n_embd], [2]=gate_proj fp32 [n_expert,n_ff,n_embd], [3]=up_proj\n// fp32 [n_expert,n_ff,n_embd], [4]=down_proj fp32 [n_expert,n_embd,n_ff];\n// var_axes: [0]=n_tokens\nint armbench_entry_moe(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_moe(\n inputs[0],\n reinterpret_cast(inputs[1]),\n inputs[2], inputs[3], inputs[4],\n reinterpret_cast(output),\n var_axes[0], kNEmbd, kNFf, kNExpert, kNExpertUsed, /*is_q8=*/false);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"moe.h\"\n#include \n#include \n#include \n#include \n#include \n\nstatic inline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F, mant = h & 0x3FF, f;\n if (exp == 0) {\n if (mant == 0) f = sign;\n else { exp = 127 - 15 + 1; while (!(mant & 0x400)) { mant <<= 1; exp--; }\n mant &= 0x3FF; f = sign | (exp << 23) | (mant << 13); }\n } else if (exp == 0x1F) { f = sign | 0x7F800000u | (mant << 13); }\n else { f = sign | ((exp - 15 + 127) << 23) | (mant << 13); }\n float o; std::memcpy(&o, &f, 4); return o;\n}\n// Dequant one block_q8_0 row: nb 34-byte blocks {fp16 d; int8 qs[32]} -> nb*32 floats.\nstatic inline void dq_row(const uint8_t* p, int64_t nb, float* dst) {\n for (int64_t b = 0; b < nb; ++b) {\n const uint8_t* bp = p + b * 34; uint16_t d16; std::memcpy(&d16, bp, 2);\n float d = f16_to_f32(d16); const int8_t* qs = (const int8_t*)(bp + 2);\n for (int j = 0; j < 32; ++j) dst[b * 32 + j] = d * (float)qs[j];\n }\n}\n\n// Naive scalar SwiGLU MoE reference (softmax gating, top-k, renorm top-k weights):\n// probs = softmax(hidden @ router^T); pick top-k experts; w /= sum(w);\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x)).\n// q8_0: hidden + gate/up/down are block_q8_0 over their last axis; router stays fp32.\nint armbench_llamacpp_moe(const void* hidden_states, const float* router_weight,\n const void* gate_proj, const void* up_proj,\n const void* down_proj, float* out,\n int64_t T, int64_t d, int64_t ff,\n int64_t E, int64_t K, bool is_q8) {\n int64_t nbd = d / 32, nbf = ff / 32;\n const uint8_t* hs8 = (const uint8_t*)hidden_states;\n const uint8_t* g8 = (const uint8_t*)gate_proj;\n const uint8_t* u8 = (const uint8_t*)up_proj;\n const uint8_t* dn8 = (const uint8_t*)down_proj;\n const float* hsf = (const float*)hidden_states;\n const float* gf = (const float*)gate_proj;\n const float* uf = (const float*)up_proj;\n const float* dnf = (const float*)down_proj;\n\n std::vector hs(d), row(d > ff ? d : ff), gu(ff), logits(E), probs(E);\n for (int64_t t = 0; t < T; ++t) {\n if (is_q8) dq_row(hs8 + (size_t)t * nbd * 34, nbd, hs.data());\n else std::memcpy(hs.data(), hsf + (size_t)t * d, d * sizeof(float));\n\n float mx = -1e30f;\n for (int64_t e = 0; e < E; ++e) {\n const float* rw = router_weight + (size_t)e * d;\n double acc = 0.0; for (int64_t j = 0; j < d; ++j) acc += (double)hs[j] * rw[j];\n logits[e] = (float)acc; if (logits[e] > mx) mx = logits[e];\n }\n double sum = 0.0;\n for (int64_t e = 0; e < E; ++e) { probs[e] = std::exp(logits[e] - mx); sum += probs[e]; }\n for (int64_t e = 0; e < E; ++e) probs[e] = (float)(probs[e] / sum);\n\n std::vector idx(E); for (int64_t e = 0; e < E; ++e) idx[e] = e;\n std::partial_sort(idx.begin(), idx.begin() + K, idx.end(),\n [&](int64_t a, int64_t b){ return probs[a] > probs[b]; });\n double wsum = 0.0; for (int64_t ki = 0; ki < K; ++ki) wsum += probs[idx[ki]];\n\n float* orow = out + (size_t)t * d;\n for (int64_t dd = 0; dd < d; ++dd) orow[dd] = 0.0f;\n for (int64_t ki = 0; ki < K; ++ki) {\n int64_t e = idx[ki]; float w = (float)(probs[e] / wsum);\n for (int64_t f = 0; f < ff; ++f) {\n const float* gr; const float* ur;\n if (is_q8) { dq_row(g8 + ((size_t)e * ff + f) * nbd * 34, nbd, row.data()); gr = row.data(); }\n else gr = gf + ((size_t)e * ff + f) * d;\n double ga = 0.0; for (int64_t j = 0; j < d; ++j) ga += (double)gr[j] * hs[j];\n float g = (float)ga;\n std::vector urow;\n if (is_q8) { urow.resize(d); dq_row(u8 + ((size_t)e * ff + f) * nbd * 34, nbd, urow.data()); ur = urow.data(); }\n else ur = uf + ((size_t)e * ff + f) * d;\n double ua = 0.0; for (int64_t j = 0; j < d; ++j) ua += (double)ur[j] * hs[j];\n float u = (float)ua;\n float silu = g / (1.0f + std::exp(-g));\n gu[f] = silu * u;\n }\n for (int64_t dd = 0; dd < d; ++dd) {\n const float* dr;\n if (is_q8) { dq_row(dn8 + ((size_t)e * d + dd) * nbf * 34, nbf, row.data()); dr = row.data(); }\n else dr = dnf + ((size_t)e * d + dd) * ff;\n double a = 0.0; for (int64_t f = 0; f < ff; ++f) a += (double)dr[f] * gu[f];\n orow[dd] += w * (float)a;\n }\n }\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for moe_fp32_e64_k8_d2048_ff1024 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/solutions/llama.cpp/reference-scalar/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json b/solutions/llama.cpp/reference-scalar/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json new file mode 100644 index 0000000000000000000000000000000000000000..8286fadb9906110f651773c86ed71100c95fe8fb --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/moe/moe_q4_k_m_e60_k4_d2048_ff1536.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_moe_q4_k_m_e60_k4_d2048_ff1536", + "definition": "moe_q4_k_m_e60_k4_d2048_ff1536", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer moe for moe_q4_k_m_e60_k4_d2048_ff1536. Constexpr-baked dims; armbench_entry_moe calls inner_moe. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "moe.cpp::armbench_entry_moe", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "moe.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this moe Q4_K (weight-only) specialisation.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is a raw bf16 bit pattern (uint16_t) -- never quantized.\n// router_weight is plain float32 -- also never quantized (routing decisions\n// are categorical top-k; quantization rounding could flip which experts get\n// selected, so routing stays at the highest available precision).\n// gate_proj/up_proj/down_proj are each Q4_K-quantized, exposed as three flat\n// tensors per weight (see gemm_q4_k_m.h.tmpl for the exact byte layout):\n// _q4 [n_expert, rows, cols/2] uint8\n// _scales [n_expert, rows, cols/32] raw fp16 bits (uint16_t)\n// _mins [n_expert, rows, cols/32] raw fp16 bits (uint16_t)\n// where (rows, cols) = (n_ff, n_embd) for gate/up, (n_embd, n_ff) for down.\n// Output accumulates/returns in fp32.\nnamespace moe_def {\nconstexpr int NEmbd = 2048;\nconstexpr int NFf = 1536;\nconstexpr int NExpert = 60;\nconstexpr int NExpertUsed = 4;\nconstexpr int NEmbdHalf = 1024;\nconstexpr int NEmbdSub = 64;\nconstexpr int NFfHalf = 768;\nconstexpr int NFfSub = 48;\n} // namespace moe_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// n_tokens is the only var dim.\nvoid inner_moe(const uint16_t* hidden_states, float* output,\n const float* router_weight,\n const uint8_t* gate_proj_q4, const uint16_t* gate_proj_scales,\n const uint16_t* gate_proj_mins,\n const uint8_t* up_proj_q4, const uint16_t* up_proj_scales,\n const uint16_t* up_proj_mins,\n const uint8_t* down_proj_q4, const uint16_t* down_proj_scales,\n const uint16_t* down_proj_mins,\n int n_tokens);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "moe.cpp", + "content": "// Binding harness: forwards straight to inner_moe (no derived dims needed).\n// ABI: armbench_entry_moe(hidden_states*, output*, router_weight*,\n// gate_proj_q4*, gate_proj_scales*, gate_proj_mins*,\n// up_proj_q4*, up_proj_scales*, up_proj_mins*,\n// down_proj_q4*, down_proj_scales*, down_proj_mins*, n_tokens)\n#include \"moe.h\"\nusing namespace moe_def;\n\nextern \"C\" int armbench_entry_moe(\n const uint16_t* hidden_states, float* output, const float* router_weight,\n const uint8_t* gate_proj_q4, const uint16_t* gate_proj_scales, const uint16_t* gate_proj_mins,\n const uint8_t* up_proj_q4, const uint16_t* up_proj_scales, const uint16_t* up_proj_mins,\n const uint8_t* down_proj_q4, const uint16_t* down_proj_scales, const uint16_t* down_proj_mins,\n int n_tokens)\n{\n inner_moe(hidden_states, output, router_weight,\n gate_proj_q4, gate_proj_scales, gate_proj_mins,\n up_proj_q4, up_proj_scales, up_proj_mins,\n down_proj_q4, down_proj_scales, down_proj_mins,\n n_tokens);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar moe Q4_K (weight-only, genuine low-bit dot product).\n// LLM target: replace this file with an optimised inner_moe (SVE2/NEON\n// nibble-unpack + int8 dot-product intrinsics are the intended optimization\n// surface here).\n//\n// Router logits use hidden_states (widened bf16) and router_weight (plain\n// fp32) directly, with NO quantization anywhere in the routing path --\n// routing decisions are categorical top-k and must not flip from\n// quantization rounding. gate/up/down all mirror real GGML's\n// ggml_vec_dot_q4_K_q8_K: the relevant fp32 activation vector (hidden state\n// for gate/up, the gated silu(gate)*up intermediate for down) is dynamically\n// quantized into 256-element blocks (one scale, int8 values), then each\n// 32-element sub-block does an integer dot product against the unpacked\n// Q4_K nibbles, scale-corrected and accumulated in fp32. This matches\n// gemm_q4_k_m.kernel.cpp.tmpl's dot-product core, applied once per expert\n// weight matrix.\n//\n// All per-definition constants live in moe_def:: (moe.h).\n#include \"moe.h\"\n#include \n#include \n#include \n#include \n#include \nusing namespace moe_def;\n\nnamespace {\n\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n\n// Proper IEEE-754 half->single conversion (fp16, not bf16).\ninline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F;\n uint32_t mant = h & 0x3FF;\n uint32_t bits;\n if (exp == 0) {\n if (mant == 0) {\n bits = sign;\n } else {\n exp = 1;\n while ((mant & 0x400) == 0) { mant <<= 1; --exp; }\n mant &= 0x3FF;\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n } else if (exp == 0x1F) {\n bits = sign | 0x7F800000u | (mant << 13);\n } else {\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n float f;\n std::memcpy(&f, &bits, sizeof(f));\n return f;\n}\n\n// Dynamically quantize a fp32 vector into 256-element Q8_K-style blocks:\n// one scale per block, int8 values in [-127, 127]. len must be a multiple\n// of 256 (guaranteed here -- n_embd/n_ff are both chosen divisible by 256).\nvoid quantize_q8k(const float* x, int len, std::vector& d_out, std::vector& q8_out) {\n const int nblk = len / 256;\n d_out.resize(nblk);\n q8_out.resize(len);\n for (int sb = 0; sb < nblk; ++sb) {\n float amax = 0.0f;\n for (int l = 0; l < 256; ++l) {\n const float v = std::fabs(x[sb * 256 + l]);\n if (v > amax) amax = v;\n }\n const float d = amax / 127.0f;\n d_out[sb] = d;\n const float id = d > 0.0f ? 1.0f / d : 0.0f;\n for (int l = 0; l < 256; ++l) {\n int q = (int)std::lround(x[sb * 256 + l] * id);\n if (q > 127) q = 127;\n if (q < -127) q = -127;\n q8_out[sb * 256 + l] = (int8_t)q;\n }\n }\n}\n\n// Dot product of one Q4_K-quantized weight row [K elements, K%256==0]\n// against a pre-quantized Q8_K-style activation of the same length.\nfloat q4k_dot(const uint8_t* w_q4, const uint16_t* w_scales, const uint16_t* w_mins,\n const std::vector& d_act, const std::vector& q8, int K)\n{\n const int K_sub = K / 32;\n float acc = 0.0f;\n for (int sb32 = 0; sb32 < K_sub; ++sb32) {\n const float scale = f16_to_f32(w_scales[sb32]);\n const float minv = f16_to_f32(w_mins[sb32]);\n const float dact = d_act[sb32 / 8]; // 8 sub-blocks per 256-elem superblock\n\n int32_t sumi = 0;\n int32_t bsum = 0;\n const int base = sb32 * 32;\n for (int l = 0; l < 32; ++l) {\n const int k = base + l;\n const uint8_t byte = w_q4[k / 2];\n const int nib = (k % 2 == 0) ? (byte & 0xF) : (byte >> 4);\n const int8_t qv = q8[k];\n sumi += nib * qv;\n bsum += qv;\n }\n acc += dact * (scale * (float)sumi - minv * (float)bsum);\n }\n return acc;\n}\n\n} // namespace\n\nextern \"C\" void inner_moe(\n const uint16_t* hidden_states, float* output, const float* router_weight,\n const uint8_t* gate_proj_q4, const uint16_t* gate_proj_scales, const uint16_t* gate_proj_mins,\n const uint8_t* up_proj_q4, const uint16_t* up_proj_scales, const uint16_t* up_proj_mins,\n const uint8_t* down_proj_q4, const uint16_t* down_proj_scales, const uint16_t* down_proj_mins,\n int n_tokens)\n{\n std::vector h(NEmbd);\n std::vector logits(NExpert);\n std::vector probs(NExpert);\n std::vector used(NExpert);\n std::vector top_idx(NExpertUsed);\n std::vector top_w(NExpertUsed);\n\n std::vector d_act_h;\n std::vector q8_h;\n std::vector gu(NFf);\n std::vector d_act_gu;\n std::vector q8_gu;\n\n for (int t = 0; t < n_tokens; ++t) {\n const uint16_t* hs_row = hidden_states + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) h[d] = bf16_to_f32(hs_row[d]);\n\n // Router: plain fp32 dot product, no quantization anywhere.\n for (int e = 0; e < NExpert; ++e) {\n const float* rw = router_weight + (long)e * NEmbd;\n float dot = 0.0f;\n for (int d = 0; d < NEmbd; ++d) dot += h[d] * rw[d];\n logits[e] = dot;\n }\n float max_logit = logits[0];\n for (int e = 1; e < NExpert; ++e) if (logits[e] > max_logit) max_logit = logits[e];\n float sum_exp = 0.0f;\n for (int e = 0; e < NExpert; ++e) {\n probs[e] = std::exp(logits[e] - max_logit);\n sum_exp += probs[e];\n }\n for (int e = 0; e < NExpert; ++e) probs[e] /= sum_exp;\n\n // Top-k selection (repeated argmax over unselected experts) + renormalize.\n std::fill(used.begin(), used.end(), false);\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n int best = -1;\n for (int e = 0; e < NExpert; ++e) {\n if (!used[e] && (best < 0 || probs[e] > probs[best])) best = e;\n }\n used[best] = true;\n top_idx[ki] = best;\n top_w[ki] = probs[best];\n }\n float wsum = 0.0f;\n for (int ki = 0; ki < NExpertUsed; ++ki) wsum += top_w[ki];\n for (int ki = 0; ki < NExpertUsed; ++ki) top_w[ki] /= wsum;\n\n float* out_row = output + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) out_row[d] = 0.0f;\n\n // Quantize the hidden state once per token -- shared by gate & up\n // for every selected expert (same activation vector each time).\n quantize_q8k(h.data(), NEmbd, d_act_h, q8_h);\n\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n const int e = top_idx[ki];\n const uint8_t* gate_q4_e = gate_proj_q4 + (long)e * NFf * NEmbdHalf;\n const uint16_t* gate_sc_e = gate_proj_scales + (long)e * NFf * NEmbdSub;\n const uint16_t* gate_mn_e = gate_proj_mins + (long)e * NFf * NEmbdSub;\n const uint8_t* up_q4_e = up_proj_q4 + (long)e * NFf * NEmbdHalf;\n const uint16_t* up_sc_e = up_proj_scales + (long)e * NFf * NEmbdSub;\n const uint16_t* up_mn_e = up_proj_mins + (long)e * NFf * NEmbdSub;\n const uint8_t* down_q4_e = down_proj_q4 + (long)e * NEmbd * NFfHalf;\n const uint16_t* down_sc_e = down_proj_scales + (long)e * NEmbd * NFfSub;\n const uint16_t* down_mn_e = down_proj_mins + (long)e * NEmbd * NFfSub;\n\n for (int fi = 0; fi < NFf; ++fi) {\n const uint8_t* gate_row_q4 = gate_q4_e + (long)fi * NEmbdHalf;\n const uint16_t* gate_row_sc = gate_sc_e + (long)fi * NEmbdSub;\n const uint16_t* gate_row_mn = gate_mn_e + (long)fi * NEmbdSub;\n const uint8_t* up_row_q4 = up_q4_e + (long)fi * NEmbdHalf;\n const uint16_t* up_row_sc = up_sc_e + (long)fi * NEmbdSub;\n const uint16_t* up_row_mn = up_mn_e + (long)fi * NEmbdSub;\n\n const float gv = q4k_dot(gate_row_q4, gate_row_sc, gate_row_mn, d_act_h, q8_h, NEmbd);\n const float uv = q4k_dot(up_row_q4, up_row_sc, up_row_mn, d_act_h, q8_h, NEmbd);\n const float silu = gv / (1.0f + std::exp(-gv));\n gu[fi] = silu * uv;\n }\n\n quantize_q8k(gu.data(), NFf, d_act_gu, q8_gu);\n\n for (int d = 0; d < NEmbd; ++d) {\n const uint8_t* down_row_q4 = down_q4_e + (long)d * NFfHalf;\n const uint16_t* down_row_sc = down_sc_e + (long)d * NFfSub;\n const uint16_t* down_row_mn = down_mn_e + (long)d * NFfSub;\n const float acc = q4k_dot(down_row_q4, down_row_sc, down_row_mn, d_act_gu, q8_gu, NFf);\n out_row[d] += top_w[ki] * acc;\n }\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json b/solutions/llama.cpp/reference-scalar/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json new file mode 100644 index 0000000000000000000000000000000000000000..eff14f4abd3da1e0f82d6294c523702a75a4efbe --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/moe/moe_q4_k_m_e64_k8_d2048_ff1024.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_moe_q4_k_m_e64_k8_d2048_ff1024", + "definition": "moe_q4_k_m_e64_k8_d2048_ff1024", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer moe for moe_q4_k_m_e64_k8_d2048_ff1024. Constexpr-baked dims; armbench_entry_moe calls inner_moe. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "moe.cpp::armbench_entry_moe", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "moe.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this moe Q4_K (weight-only) specialisation.\n// SwiGLU MoE with softmax-then-top-k routing and normalized top-k weights:\n// probs = softmax(hidden @ router^T); top-k experts; w /= sum(w)\n// out = sum_k w_k * down_e @ (silu(gate_e @ x) * (up_e @ x))\n// hidden_states is a raw bf16 bit pattern (uint16_t) -- never quantized.\n// router_weight is plain float32 -- also never quantized (routing decisions\n// are categorical top-k; quantization rounding could flip which experts get\n// selected, so routing stays at the highest available precision).\n// gate_proj/up_proj/down_proj are each Q4_K-quantized, exposed as three flat\n// tensors per weight (see gemm_q4_k_m.h.tmpl for the exact byte layout):\n// _q4 [n_expert, rows, cols/2] uint8\n// _scales [n_expert, rows, cols/32] raw fp16 bits (uint16_t)\n// _mins [n_expert, rows, cols/32] raw fp16 bits (uint16_t)\n// where (rows, cols) = (n_ff, n_embd) for gate/up, (n_embd, n_ff) for down.\n// Output accumulates/returns in fp32.\nnamespace moe_def {\nconstexpr int NEmbd = 2048;\nconstexpr int NFf = 1024;\nconstexpr int NExpert = 64;\nconstexpr int NExpertUsed = 8;\nconstexpr int NEmbdHalf = 1024;\nconstexpr int NEmbdSub = 64;\nconstexpr int NFfHalf = 512;\nconstexpr int NFfSub = 32;\n} // namespace moe_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// n_tokens is the only var dim.\nvoid inner_moe(const uint16_t* hidden_states, float* output,\n const float* router_weight,\n const uint8_t* gate_proj_q4, const uint16_t* gate_proj_scales,\n const uint16_t* gate_proj_mins,\n const uint8_t* up_proj_q4, const uint16_t* up_proj_scales,\n const uint16_t* up_proj_mins,\n const uint8_t* down_proj_q4, const uint16_t* down_proj_scales,\n const uint16_t* down_proj_mins,\n int n_tokens);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "moe.cpp", + "content": "// Binding harness: forwards straight to inner_moe (no derived dims needed).\n// ABI: armbench_entry_moe(hidden_states*, output*, router_weight*,\n// gate_proj_q4*, gate_proj_scales*, gate_proj_mins*,\n// up_proj_q4*, up_proj_scales*, up_proj_mins*,\n// down_proj_q4*, down_proj_scales*, down_proj_mins*, n_tokens)\n#include \"moe.h\"\nusing namespace moe_def;\n\nextern \"C\" int armbench_entry_moe(\n const uint16_t* hidden_states, float* output, const float* router_weight,\n const uint8_t* gate_proj_q4, const uint16_t* gate_proj_scales, const uint16_t* gate_proj_mins,\n const uint8_t* up_proj_q4, const uint16_t* up_proj_scales, const uint16_t* up_proj_mins,\n const uint8_t* down_proj_q4, const uint16_t* down_proj_scales, const uint16_t* down_proj_mins,\n int n_tokens)\n{\n inner_moe(hidden_states, output, router_weight,\n gate_proj_q4, gate_proj_scales, gate_proj_mins,\n up_proj_q4, up_proj_scales, up_proj_mins,\n down_proj_q4, down_proj_scales, down_proj_mins,\n n_tokens);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar moe Q4_K (weight-only, genuine low-bit dot product).\n// LLM target: replace this file with an optimised inner_moe (SVE2/NEON\n// nibble-unpack + int8 dot-product intrinsics are the intended optimization\n// surface here).\n//\n// Router logits use hidden_states (widened bf16) and router_weight (plain\n// fp32) directly, with NO quantization anywhere in the routing path --\n// routing decisions are categorical top-k and must not flip from\n// quantization rounding. gate/up/down all mirror real GGML's\n// ggml_vec_dot_q4_K_q8_K: the relevant fp32 activation vector (hidden state\n// for gate/up, the gated silu(gate)*up intermediate for down) is dynamically\n// quantized into 256-element blocks (one scale, int8 values), then each\n// 32-element sub-block does an integer dot product against the unpacked\n// Q4_K nibbles, scale-corrected and accumulated in fp32. This matches\n// gemm_q4_k_m.kernel.cpp.tmpl's dot-product core, applied once per expert\n// weight matrix.\n//\n// All per-definition constants live in moe_def:: (moe.h).\n#include \"moe.h\"\n#include \n#include \n#include \n#include \n#include \nusing namespace moe_def;\n\nnamespace {\n\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift.\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n\n// Proper IEEE-754 half->single conversion (fp16, not bf16).\ninline float f16_to_f32(uint16_t h) {\n uint32_t sign = (uint32_t)(h & 0x8000) << 16;\n uint32_t exp = (h >> 10) & 0x1F;\n uint32_t mant = h & 0x3FF;\n uint32_t bits;\n if (exp == 0) {\n if (mant == 0) {\n bits = sign;\n } else {\n exp = 1;\n while ((mant & 0x400) == 0) { mant <<= 1; --exp; }\n mant &= 0x3FF;\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n } else if (exp == 0x1F) {\n bits = sign | 0x7F800000u | (mant << 13);\n } else {\n bits = sign | ((exp + 112u) << 23) | (mant << 13);\n }\n float f;\n std::memcpy(&f, &bits, sizeof(f));\n return f;\n}\n\n// Dynamically quantize a fp32 vector into 256-element Q8_K-style blocks:\n// one scale per block, int8 values in [-127, 127]. len must be a multiple\n// of 256 (guaranteed here -- n_embd/n_ff are both chosen divisible by 256).\nvoid quantize_q8k(const float* x, int len, std::vector& d_out, std::vector& q8_out) {\n const int nblk = len / 256;\n d_out.resize(nblk);\n q8_out.resize(len);\n for (int sb = 0; sb < nblk; ++sb) {\n float amax = 0.0f;\n for (int l = 0; l < 256; ++l) {\n const float v = std::fabs(x[sb * 256 + l]);\n if (v > amax) amax = v;\n }\n const float d = amax / 127.0f;\n d_out[sb] = d;\n const float id = d > 0.0f ? 1.0f / d : 0.0f;\n for (int l = 0; l < 256; ++l) {\n int q = (int)std::lround(x[sb * 256 + l] * id);\n if (q > 127) q = 127;\n if (q < -127) q = -127;\n q8_out[sb * 256 + l] = (int8_t)q;\n }\n }\n}\n\n// Dot product of one Q4_K-quantized weight row [K elements, K%256==0]\n// against a pre-quantized Q8_K-style activation of the same length.\nfloat q4k_dot(const uint8_t* w_q4, const uint16_t* w_scales, const uint16_t* w_mins,\n const std::vector& d_act, const std::vector& q8, int K)\n{\n const int K_sub = K / 32;\n float acc = 0.0f;\n for (int sb32 = 0; sb32 < K_sub; ++sb32) {\n const float scale = f16_to_f32(w_scales[sb32]);\n const float minv = f16_to_f32(w_mins[sb32]);\n const float dact = d_act[sb32 / 8]; // 8 sub-blocks per 256-elem superblock\n\n int32_t sumi = 0;\n int32_t bsum = 0;\n const int base = sb32 * 32;\n for (int l = 0; l < 32; ++l) {\n const int k = base + l;\n const uint8_t byte = w_q4[k / 2];\n const int nib = (k % 2 == 0) ? (byte & 0xF) : (byte >> 4);\n const int8_t qv = q8[k];\n sumi += nib * qv;\n bsum += qv;\n }\n acc += dact * (scale * (float)sumi - minv * (float)bsum);\n }\n return acc;\n}\n\n} // namespace\n\nextern \"C\" void inner_moe(\n const uint16_t* hidden_states, float* output, const float* router_weight,\n const uint8_t* gate_proj_q4, const uint16_t* gate_proj_scales, const uint16_t* gate_proj_mins,\n const uint8_t* up_proj_q4, const uint16_t* up_proj_scales, const uint16_t* up_proj_mins,\n const uint8_t* down_proj_q4, const uint16_t* down_proj_scales, const uint16_t* down_proj_mins,\n int n_tokens)\n{\n std::vector h(NEmbd);\n std::vector logits(NExpert);\n std::vector probs(NExpert);\n std::vector used(NExpert);\n std::vector top_idx(NExpertUsed);\n std::vector top_w(NExpertUsed);\n\n std::vector d_act_h;\n std::vector q8_h;\n std::vector gu(NFf);\n std::vector d_act_gu;\n std::vector q8_gu;\n\n for (int t = 0; t < n_tokens; ++t) {\n const uint16_t* hs_row = hidden_states + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) h[d] = bf16_to_f32(hs_row[d]);\n\n // Router: plain fp32 dot product, no quantization anywhere.\n for (int e = 0; e < NExpert; ++e) {\n const float* rw = router_weight + (long)e * NEmbd;\n float dot = 0.0f;\n for (int d = 0; d < NEmbd; ++d) dot += h[d] * rw[d];\n logits[e] = dot;\n }\n float max_logit = logits[0];\n for (int e = 1; e < NExpert; ++e) if (logits[e] > max_logit) max_logit = logits[e];\n float sum_exp = 0.0f;\n for (int e = 0; e < NExpert; ++e) {\n probs[e] = std::exp(logits[e] - max_logit);\n sum_exp += probs[e];\n }\n for (int e = 0; e < NExpert; ++e) probs[e] /= sum_exp;\n\n // Top-k selection (repeated argmax over unselected experts) + renormalize.\n std::fill(used.begin(), used.end(), false);\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n int best = -1;\n for (int e = 0; e < NExpert; ++e) {\n if (!used[e] && (best < 0 || probs[e] > probs[best])) best = e;\n }\n used[best] = true;\n top_idx[ki] = best;\n top_w[ki] = probs[best];\n }\n float wsum = 0.0f;\n for (int ki = 0; ki < NExpertUsed; ++ki) wsum += top_w[ki];\n for (int ki = 0; ki < NExpertUsed; ++ki) top_w[ki] /= wsum;\n\n float* out_row = output + (long)t * NEmbd;\n for (int d = 0; d < NEmbd; ++d) out_row[d] = 0.0f;\n\n // Quantize the hidden state once per token -- shared by gate & up\n // for every selected expert (same activation vector each time).\n quantize_q8k(h.data(), NEmbd, d_act_h, q8_h);\n\n for (int ki = 0; ki < NExpertUsed; ++ki) {\n const int e = top_idx[ki];\n const uint8_t* gate_q4_e = gate_proj_q4 + (long)e * NFf * NEmbdHalf;\n const uint16_t* gate_sc_e = gate_proj_scales + (long)e * NFf * NEmbdSub;\n const uint16_t* gate_mn_e = gate_proj_mins + (long)e * NFf * NEmbdSub;\n const uint8_t* up_q4_e = up_proj_q4 + (long)e * NFf * NEmbdHalf;\n const uint16_t* up_sc_e = up_proj_scales + (long)e * NFf * NEmbdSub;\n const uint16_t* up_mn_e = up_proj_mins + (long)e * NFf * NEmbdSub;\n const uint8_t* down_q4_e = down_proj_q4 + (long)e * NEmbd * NFfHalf;\n const uint16_t* down_sc_e = down_proj_scales + (long)e * NEmbd * NFfSub;\n const uint16_t* down_mn_e = down_proj_mins + (long)e * NEmbd * NFfSub;\n\n for (int fi = 0; fi < NFf; ++fi) {\n const uint8_t* gate_row_q4 = gate_q4_e + (long)fi * NEmbdHalf;\n const uint16_t* gate_row_sc = gate_sc_e + (long)fi * NEmbdSub;\n const uint16_t* gate_row_mn = gate_mn_e + (long)fi * NEmbdSub;\n const uint8_t* up_row_q4 = up_q4_e + (long)fi * NEmbdHalf;\n const uint16_t* up_row_sc = up_sc_e + (long)fi * NEmbdSub;\n const uint16_t* up_row_mn = up_mn_e + (long)fi * NEmbdSub;\n\n const float gv = q4k_dot(gate_row_q4, gate_row_sc, gate_row_mn, d_act_h, q8_h, NEmbd);\n const float uv = q4k_dot(up_row_q4, up_row_sc, up_row_mn, d_act_h, q8_h, NEmbd);\n const float silu = gv / (1.0f + std::exp(-gv));\n gu[fi] = silu * uv;\n }\n\n quantize_q8k(gu.data(), NFf, d_act_gu, q8_gu);\n\n for (int d = 0; d < NEmbd; ++d) {\n const uint8_t* down_row_q4 = down_q4_e + (long)d * NFfHalf;\n const uint16_t* down_row_sc = down_sc_e + (long)d * NFfSub;\n const uint16_t* down_row_mn = down_mn_e + (long)d * NFfSub;\n const float acc = q4k_dot(down_row_q4, down_row_sc, down_row_mn, d_act_gu, q8_gu, NFf);\n out_row[d] += top_w[ki] * acc;\n }\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/rms_norm/rms_norm_bf16_d2048.json b/solutions/llama.cpp/reference-scalar/rms_norm/rms_norm_bf16_d2048.json new file mode 100644 index 0000000000000000000000000000000000000000..b94b59bcc06b352115ed110c5deb4f0820ebb5d7 --- /dev/null +++ b/solutions/llama.cpp/reference-scalar/rms_norm/rms_norm_bf16_d2048.json @@ -0,0 +1,36 @@ +{ + "name": "reference-scalar_rms_norm_bf16_d2048", + "definition": "rms_norm_bf16_d2048", + "dataset": "llama.cpp", + "author": "reference-scalar", + "description": "Scalar raw-pointer rms_norm for rms_norm_bf16_d2048. Constexpr-baked dims; armbench_entry_rms_norm calls inner_rms_norm. Ground-truth correctness baseline.", + "spec": { + "language": "cpp", + "target_hardware": [ + "graviton3", + "aarch64-sve" + ], + "entry_point": "rms_norm.cpp::armbench_entry_rms_norm", + "dependencies": [], + "isa_features": [], + "compile_flags": [ + "-O2", + "-std=c++14" + ], + "link_flags": [] + }, + "sources": [ + { + "path": "rms_norm.h", + "content": "#pragma once\n#include \n\n// Per-definition constants for this rms_norm bf16 specialisation.\n// out[m] = x[m] / sqrt(mean(x[m]^2) + eps) * weight\n// x/weight are raw bf16 bit patterns (uint16_t); output accumulates/returns\n// in fp32.\nnamespace rms_norm_def {\nconstexpr int D = 2048;\nconstexpr float Eps = 1e-6f; // matches the Definition's reference implementation\n} // namespace rms_norm_def\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// LLM target: implement this in kernel.cpp.\n// M is the only var dim. x: (M, D) bf16; weight: (D) bf16; output: (M, D) float32.\n// Bytes are raw bf16 bit patterns \u2014 reinterpret_cast if your\n// target ISA has native bf16 support, or widen manually to fp32 first.\nvoid inner_rms_norm(const uint16_t* x, float* output, const uint16_t* weight, int M);\n#ifdef __cplusplus\n}\n#endif\n" + }, + { + "path": "rms_norm.cpp", + "content": "// Binding harness: forwards straight to inner_rms_norm (no derived dims needed).\n// ABI: armbench_entry_rms_norm(x*, output*, weight*, M)\n#include \"rms_norm.h\"\nusing namespace rms_norm_def;\n\nextern \"C\" int armbench_entry_rms_norm(const uint16_t* x, float* output, const uint16_t* weight, int M)\n{\n inner_rms_norm(x, output, weight, M);\n return 0;\n}\n" + }, + { + "path": "kernel.cpp", + "content": "// Reference-scalar rms_norm bf16 (fp32 accumulate/output).\n// LLM target: replace this file with an optimised inner_rms_norm.\n// All per-definition constants live in rms_norm_def:: (rms_norm.h).\n#include \"rms_norm.h\"\n#include \n#include \nusing namespace rms_norm_def;\n\nnamespace {\n// bf16 shares fp32's exponent field, so widening is an exact bit-shift \u2014 no\n// rounding/subnormal handling needed (unlike fp16->fp32).\ninline float bf16_to_f32(uint16_t bits) {\n uint32_t b = (uint32_t)bits << 16;\n float f;\n std::memcpy(&f, &b, sizeof(f));\n return f;\n}\n} // namespace\n\nextern \"C\" void inner_rms_norm(const uint16_t* x, float* output, const uint16_t* weight, int M)\n{\n for (int m = 0; m < M; ++m) {\n const uint16_t* x_row = x + (long)m * D;\n float* out_row = output + (long)m * D;\n\n double sq_sum = 0.0;\n for (int d = 0; d < D; ++d) {\n const float xv = bf16_to_f32(x_row[d]);\n sq_sum += (double)xv * (double)xv;\n }\n const float rms = std::sqrt((float)(sq_sum / D) + Eps);\n\n for (int d = 0; d < D; ++d) {\n out_row[d] = (bf16_to_f32(x_row[d]) / rms) * bf16_to_f32(weight[d]);\n }\n }\n}\n" + } + ] +} diff --git a/solutions/llama.cpp/reference-scalar/rms_norm/rms_norm_fp32_d2048.json b/solutions/llama.cpp/reference-scalar/rms_norm/rms_norm_fp32_d2048.json deleted file mode 100644 index 1e2f6889a514340a06dfd47a00f0cb1809750a0a..0000000000000000000000000000000000000000 --- a/solutions/llama.cpp/reference-scalar/rms_norm/rms_norm_fp32_d2048.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "reference-scalar_rms_norm_fp32_d2048", - "definition": "rms_norm_fp32_d2048", - "dataset": "llama.cpp", - "author": "reference-scalar", - "spec": { - "target_hardware": [ - "graviton3", - "aarch64-sve", - "graviton4", - "aarch64-sve2", - "apple-m" - ], - "entry_point": "binding.cpp::armbench_entry_rms_norm", - "dependencies": [], - "isa_features": [], - "compile_flags": [ - "-O2", - "-std=c++17" - ], - "link_flags": [] - }, - "sources": [ - { - "path": "rms_norm.h", - "content": "#pragma once\n#include \n\n// Harness contract for the llama.cpp (ggml) rms_norm baseline.\n// Called by armbench_entry_rms_norm (binding.cpp); implemented by kernel.cpp.\n// x is row-major fp32 [M, D], weight is fp32 [D], out is row-major fp32 [M, D]:\n// out[m] = x[m] / sqrt(mean(x[m]^2) + eps) * weight\nint armbench_llamacpp_rms_norm(const float* x, const float* weight, float* out,\n int64_t M, int64_t D, float eps);\n" - }, - { - "path": "binding.cpp", - "content": "#include \"rms_norm.h\"\n\nnamespace {\nconstexpr int64_t kD = 2048;\nconstexpr float kEps = 1e-6f; // matches the Definition reference\n} // namespace\n\nextern \"C\" {\n// inputs: [0]=x fp32 [M,D], [1]=weight fp32 [D]; var_axes: [0]=M\nint armbench_entry_rms_norm(const void* const* inputs, void* output,\n const int64_t* var_axes)\n{\n return armbench_llamacpp_rms_norm(\n reinterpret_cast(inputs[0]),\n reinterpret_cast(inputs[1]),\n reinterpret_cast(output),\n var_axes[0], kD, kEps);\n}\n} // extern \"C\"\n" - }, - { - "path": "kernel.cpp", - "content": "#include \"rms_norm.h\"\n#include \n// Naive scalar RMSNorm reference: out[m] = x[m]/sqrt(mean(x[m]^2)+eps) * weight.\nint armbench_llamacpp_rms_norm(const float* x, const float* weight, float* out,\n int64_t M, int64_t D, float eps) {\n for (int64_t m = 0; m < M; ++m) {\n const float* xr = x + m * D; float* orow = out + m * D;\n double ss = 0.0; for (int64_t d = 0; d < D; ++d) ss += (double)xr[d] * xr[d];\n float r = 1.0f / std::sqrt((float)(ss / (double)D) + eps);\n for (int64_t d = 0; d < D; ++d) orow[d] = xr[d] * r * weight[d];\n }\n return 0;\n}\n" - } - ], - "description": "Naive scalar reference for rms_norm_fp32_d2048 (no ggml/SIMD)." -} \ No newline at end of file diff --git a/workloads/gemm/gemm_fp32_n1024_k2048.jsonl b/workloads/gemm/gemm_bf16_n1024_k2048.jsonl similarity index 100% rename from workloads/gemm/gemm_fp32_n1024_k2048.jsonl rename to workloads/gemm/gemm_bf16_n1024_k2048.jsonl diff --git a/workloads/gemm/gemm_fp32_n1408_k2048.jsonl b/workloads/gemm/gemm_bf16_n1408_k2048.jsonl similarity index 100% rename from workloads/gemm/gemm_fp32_n1408_k2048.jsonl rename to workloads/gemm/gemm_bf16_n1408_k2048.jsonl diff --git a/workloads/gemm/gemm_fp32_n2048_k1024.jsonl b/workloads/gemm/gemm_bf16_n2048_k1024.jsonl similarity index 100% rename from workloads/gemm/gemm_fp32_n2048_k1024.jsonl rename to workloads/gemm/gemm_bf16_n2048_k1024.jsonl diff --git a/workloads/gemm/gemm_fp32_n2048_k1408.jsonl b/workloads/gemm/gemm_bf16_n2048_k1408.jsonl similarity index 100% rename from workloads/gemm/gemm_fp32_n2048_k1408.jsonl rename to workloads/gemm/gemm_bf16_n2048_k1408.jsonl diff --git a/workloads/gemm/gemm_fp32_n2048_k2048.jsonl b/workloads/gemm/gemm_bf16_n2048_k2048.jsonl similarity index 100% rename from workloads/gemm/gemm_fp32_n2048_k2048.jsonl rename to workloads/gemm/gemm_bf16_n2048_k2048.jsonl diff --git a/workloads/gemm/gemm_q4_k_m_n1024_k2048.jsonl b/workloads/gemm/gemm_q4_k_m_n1024_k2048.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..06f642e395ab1bb1ddfbb83cae73384236ff317a --- /dev/null +++ b/workloads/gemm/gemm_q4_k_m_n1024_k2048.jsonl @@ -0,0 +1,24 @@ +{"axes": {"M": 1}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "30be18dddacb47e781dd0a560265e10d", "tags": {"from": "gen_workload"}} +{"axes": {"M": 6}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "6d034bbce8574fc3860d48b63bbce87a", "tags": {"from": "gen_workload"}} +{"axes": {"M": 9}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "923023f1f63741df8b2783c0ebf4c2e9", "tags": {"from": "gen_workload"}} +{"axes": {"M": 12}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "091a3036c683415dac58efaa09acd484", "tags": {"from": "gen_workload"}} +{"axes": {"M": 13}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "7d107f050ebf4ec79d5055eaf2eaee58", "tags": {"from": "gen_workload"}} +{"axes": {"M": 14}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "bfd9a8d2822c4fafa5b01725bb40f887", "tags": {"from": "gen_workload"}} +{"axes": {"M": 15}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "e76ad45018e6463c94316556855685ce", "tags": {"from": "gen_workload"}} +{"axes": {"M": 16}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "a76c39da210d4c4c81a1b25f06a52103", "tags": {"from": "gen_workload"}} +{"axes": {"M": 17}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "042fdcc0f1d04fecac4d863a21bff056", "tags": {"from": "gen_workload"}} +{"axes": {"M": 18}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "65c583f88d80409a9608c73505618028", "tags": {"from": "gen_workload"}} +{"axes": {"M": 19}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "6417e7b32d5f428b9ae2a18e173a6d36", "tags": {"from": "gen_workload"}} +{"axes": {"M": 20}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "d9269192b2394cc0bcc7adede78eb53b", "tags": {"from": "gen_workload"}} +{"axes": {"M": 21}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "7d98a242ce564db498d43f441e0b5457", "tags": {"from": "gen_workload"}} +{"axes": {"M": 22}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "26860f16fe324d23af3699e227def405", "tags": {"from": "gen_workload"}} +{"axes": {"M": 23}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "0445af868e964edda21745cc812c7a86", "tags": {"from": "gen_workload"}} +{"axes": {"M": 24}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "7525bba03cd14376a52fc317d40e290f", "tags": {"from": "gen_workload"}} +{"axes": {"M": 25}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "2ac3aeb616ad420f98bb1adf11855872", "tags": {"from": "gen_workload"}} +{"axes": {"M": 26}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "7e4780c1878144f68d8ebf1a48e901ab", "tags": {"from": "gen_workload"}} +{"axes": {"M": 27}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "ad7161cff8d344f6a99046a8285fb31e", "tags": {"from": "gen_workload"}} +{"axes": {"M": 28}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "2ea65ccc89964909a611b7607a4404bf", "tags": {"from": "gen_workload"}} +{"axes": {"M": 11}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "72fca6c49a49484cb5fb2aba99d6ef58", "tags": {"from": "gen_workload"}} +{"axes": {"M": 29}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "cb933eeb9f5a4b28b84e42b7523f3c72", "tags": {"from": "gen_workload"}} +{"axes": {"M": 30}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "07830476876b48c997d5decac0ec7448", "tags": {"from": "gen_workload"}} +{"axes": {"M": 31}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "5335bea58a724641be85b34322310a18", "tags": {"from": "gen_workload"}} diff --git a/workloads/gemm/gemm_q4_k_m_n1408_k2048.jsonl b/workloads/gemm/gemm_q4_k_m_n1408_k2048.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..d1e35c1c875fd3253cc970284edf3cd50f967eba --- /dev/null +++ b/workloads/gemm/gemm_q4_k_m_n1408_k2048.jsonl @@ -0,0 +1,24 @@ +{"axes": {"M": 1}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "f0d6e14e716d48008622bd3483fde424", "tags": {"from": "gen_workload"}} +{"axes": {"M": 6}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "c67a09ec3b3a446bb565e163262907ff", "tags": {"from": "gen_workload"}} +{"axes": {"M": 9}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "d9d1b2a04e6b45159643d20d6488f8d1", "tags": {"from": "gen_workload"}} +{"axes": {"M": 12}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "f7bef55ab9514793861e0c119df8e52d", "tags": {"from": "gen_workload"}} +{"axes": {"M": 13}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "d628e4d6e08d4733bdc333f3e3ad7feb", "tags": {"from": "gen_workload"}} +{"axes": {"M": 14}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "91ecd3c48c5344368331625ce2ddc5ea", "tags": {"from": "gen_workload"}} +{"axes": {"M": 15}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "9e4162f132d64df19dfb8d3664319046", "tags": {"from": "gen_workload"}} +{"axes": {"M": 16}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "648f1681a2474f45aafadfe9afdcf6c2", "tags": {"from": "gen_workload"}} +{"axes": {"M": 17}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "80bfd656a4ea4e079342c3744c2390e6", "tags": {"from": "gen_workload"}} +{"axes": {"M": 18}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "b33c70f7e0a84c539001e81918272b00", "tags": {"from": "gen_workload"}} +{"axes": {"M": 19}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "1bb609c0ccca4848b183d5f3dd6b7dcc", "tags": {"from": "gen_workload"}} +{"axes": {"M": 20}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "78c8b903504343fe9fff99c243a74e6f", "tags": {"from": "gen_workload"}} +{"axes": {"M": 21}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "e456ba99e87c4b9ea09e7bda9c53c772", "tags": {"from": "gen_workload"}} +{"axes": {"M": 22}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "aca54e31e18e4c9997e92c657718cc6b", "tags": {"from": "gen_workload"}} +{"axes": {"M": 23}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "b4bbef5bf1ac4bc9bf77275bddeb8055", "tags": {"from": "gen_workload"}} +{"axes": {"M": 24}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "9c81ce02b6f44b938f7703a1b180e624", "tags": {"from": "gen_workload"}} +{"axes": {"M": 25}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "11374ddb507743f38374200ddf919f33", "tags": {"from": "gen_workload"}} +{"axes": {"M": 26}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "3c70c928048c4aa0bfd1109458fb952f", "tags": {"from": "gen_workload"}} +{"axes": {"M": 27}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "933760cdacde426299b11922be300db7", "tags": {"from": "gen_workload"}} +{"axes": {"M": 28}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "f2272e7a95504867813e0a09458b73a8", "tags": {"from": "gen_workload"}} +{"axes": {"M": 11}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "d2e7634ac03f4278be3bd9483b408ade", "tags": {"from": "gen_workload"}} +{"axes": {"M": 29}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "8e361cec210d4290aa7327025f3d9420", "tags": {"from": "gen_workload"}} +{"axes": {"M": 30}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "1b471b0debdd487680050283c7079a7e", "tags": {"from": "gen_workload"}} +{"axes": {"M": 31}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "9916c7591c9d4dfc94fa380b69bf6de4", "tags": {"from": "gen_workload"}} diff --git a/workloads/gemm/gemm_q4_k_m_n2048_k1024.jsonl b/workloads/gemm/gemm_q4_k_m_n2048_k1024.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..48fa596894691471a2d028a9a4c93420f197bdad --- /dev/null +++ b/workloads/gemm/gemm_q4_k_m_n2048_k1024.jsonl @@ -0,0 +1,24 @@ +{"axes": {"M": 1}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "4ae781b7aef84b6cb687d2db05902797", "tags": {"from": "gen_workload"}} +{"axes": {"M": 6}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "42ac8360a1e2468899bc2608abd36450", "tags": {"from": "gen_workload"}} +{"axes": {"M": 9}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "226013eb6a29424cb1d062a1e1ee5e68", "tags": {"from": "gen_workload"}} +{"axes": {"M": 12}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "e0b430e4b45f4b1e87eae779d9da6127", "tags": {"from": "gen_workload"}} +{"axes": {"M": 13}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "1afb24e199da49d3af3f155016128953", "tags": {"from": "gen_workload"}} +{"axes": {"M": 14}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "731178bd96b04fae9b02b8f5639fc2a2", "tags": {"from": "gen_workload"}} +{"axes": {"M": 15}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "9c564e01aae6464d9c1ad5d82c37c325", "tags": {"from": "gen_workload"}} +{"axes": {"M": 16}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "39fb082b431a487fa53d686006273cff", "tags": {"from": "gen_workload"}} +{"axes": {"M": 17}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "b418b87c48334aa09dab0a6b8cc8e882", "tags": {"from": "gen_workload"}} +{"axes": {"M": 18}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "d88adb96d4a24caf884a458b5d0f3288", "tags": {"from": "gen_workload"}} +{"axes": {"M": 19}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "c5ff93ae65094748bfeda25b532e5a5a", "tags": {"from": "gen_workload"}} +{"axes": {"M": 20}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "6291d4b41d2c49198ac01e0ac78e636b", "tags": {"from": "gen_workload"}} +{"axes": {"M": 21}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "1eaa730302b04f40af2edab8bd9ca458", "tags": {"from": "gen_workload"}} +{"axes": {"M": 22}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "fe4452170973404991726954de846bba", "tags": {"from": "gen_workload"}} +{"axes": {"M": 23}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "bade6198ad1d4f59928fe34fa02b1a05", "tags": {"from": "gen_workload"}} +{"axes": {"M": 24}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "edd88928de5244ca981602a799679395", "tags": {"from": "gen_workload"}} +{"axes": {"M": 25}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "432e8b4b0510437abbd70d2c44bfa5da", "tags": {"from": "gen_workload"}} +{"axes": {"M": 26}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "bcbebb34e3944f0bbaeee939dddd57d9", "tags": {"from": "gen_workload"}} +{"axes": {"M": 27}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "e9e1e2cab4a14d4e81f63cedf512126d", "tags": {"from": "gen_workload"}} +{"axes": {"M": 28}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "9132a24ff8bc43dc9d0d173259e29794", "tags": {"from": "gen_workload"}} +{"axes": {"M": 11}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "a69a675b162d4dcbb4d65375a2d65ff3", "tags": {"from": "gen_workload"}} +{"axes": {"M": 29}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "fcae77ed28e84c098d761b0d0baf50ab", "tags": {"from": "gen_workload"}} +{"axes": {"M": 30}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "352d5de2bf9347178c33f13a9906843c", "tags": {"from": "gen_workload"}} +{"axes": {"M": 31}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "00e6ce20d0e64798a650a627e58e9f46", "tags": {"from": "gen_workload"}} diff --git a/workloads/gemm/gemm_q4_k_m_n2048_k1536.jsonl b/workloads/gemm/gemm_q4_k_m_n2048_k1536.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..c3716ef59a9c4c879830b41db9b6d1e335f03c0a --- /dev/null +++ b/workloads/gemm/gemm_q4_k_m_n2048_k1536.jsonl @@ -0,0 +1,24 @@ +{"axes": {"M": 1}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "8883bea4404841ce841e61a69d30c5dc", "tags": {"from": "gen_workload"}} +{"axes": {"M": 6}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "76885af734474f1891e1d505c23de831", "tags": {"from": "gen_workload"}} +{"axes": {"M": 9}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "e50af6c7fabe4244b1f3259c69492c86", "tags": {"from": "gen_workload"}} +{"axes": {"M": 12}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "7cda17b43aa4470fb749bcbacec5c28c", "tags": {"from": "gen_workload"}} +{"axes": {"M": 13}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "c133f3ccd4ce485fb934543d4ff4d73e", "tags": {"from": "gen_workload"}} +{"axes": {"M": 14}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "4d4716f38ad2401d979bcc57f8461a4f", "tags": {"from": "gen_workload"}} +{"axes": {"M": 15}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "fc711415f71c4aae905059e9afc79ec6", "tags": {"from": "gen_workload"}} +{"axes": {"M": 16}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "4d949e7d4f1b44bbab29c3464d657d7a", "tags": {"from": "gen_workload"}} +{"axes": {"M": 17}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "08baaefa2eaf4aeeba0f12bd75b07399", "tags": {"from": "gen_workload"}} +{"axes": {"M": 18}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "8bd92e9cfd6748c9a18693c8de180e9a", "tags": {"from": "gen_workload"}} +{"axes": {"M": 19}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "e716a1d9d73f490294aaa78efb8397ab", "tags": {"from": "gen_workload"}} +{"axes": {"M": 20}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "3f830613c45245099db2212e2d1ab36a", "tags": {"from": "gen_workload"}} +{"axes": {"M": 21}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "e8112c868586461f8759c66843262fac", "tags": {"from": "gen_workload"}} +{"axes": {"M": 22}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "3156ae59ec08446d82949b838c992b27", "tags": {"from": "gen_workload"}} +{"axes": {"M": 23}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "fe1970515e594f38aa6c7095d9a186d4", "tags": {"from": "gen_workload"}} +{"axes": {"M": 24}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "3a6b58865f9d45f7961af7bce6e7ca96", "tags": {"from": "gen_workload"}} +{"axes": {"M": 25}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "db14d309cb5540d88039777f5737356b", "tags": {"from": "gen_workload"}} +{"axes": {"M": 26}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "2908afbaeaa448149d4aca687c2e8230", "tags": {"from": "gen_workload"}} +{"axes": {"M": 27}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "dd3a2069d081405bb323e522cad2a90a", "tags": {"from": "gen_workload"}} +{"axes": {"M": 28}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "6792cf7755eb452e89bdaf34af274950", "tags": {"from": "gen_workload"}} +{"axes": {"M": 11}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "5fecf1adad914d71bd58655431c8482e", "tags": {"from": "gen_workload"}} +{"axes": {"M": 29}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "2cebd60c86934af5b0e5df019785e2d7", "tags": {"from": "gen_workload"}} +{"axes": {"M": 30}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "f4adb0ed1ddf4192a79ad61c024aed6e", "tags": {"from": "gen_workload"}} +{"axes": {"M": 31}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "b835788dd2f74739a13f9de0258dd318", "tags": {"from": "gen_workload"}} diff --git a/workloads/gemm/gemm_q4_k_m_n2048_k2048.jsonl b/workloads/gemm/gemm_q4_k_m_n2048_k2048.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..4f21c9fb7f961d931876e75dd0e5e0f8aa3bb7d9 --- /dev/null +++ b/workloads/gemm/gemm_q4_k_m_n2048_k2048.jsonl @@ -0,0 +1,24 @@ +{"axes": {"M": 1}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "8a2fb572afda4e9493075d4868b09f1a", "tags": {"from": "gen_workload"}} +{"axes": {"M": 6}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "258de3e6fb8a47f4b4ed1bcd990a3165", "tags": {"from": "gen_workload"}} +{"axes": {"M": 9}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "4b50ddd3faa748c2984c5a033541caa0", "tags": {"from": "gen_workload"}} +{"axes": {"M": 12}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "b86ba539d9d243058582c6a7775a7692", "tags": {"from": "gen_workload"}} +{"axes": {"M": 13}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "a59724319e2d47b6b73c35df6676cd50", "tags": {"from": "gen_workload"}} +{"axes": {"M": 14}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "68cb0dc7537a49128e00f2a290071165", "tags": {"from": "gen_workload"}} +{"axes": {"M": 15}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "6cf195ad2a9b4aa080bf6cae52334a7c", "tags": {"from": "gen_workload"}} +{"axes": {"M": 16}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "bdb11d3b18cc4d6485b668b44828983d", "tags": {"from": "gen_workload"}} +{"axes": {"M": 17}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "264e604af01c4a74859bed9c77988c20", "tags": {"from": "gen_workload"}} +{"axes": {"M": 18}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "066aa1530cc142828a82d095a1e670e6", "tags": {"from": "gen_workload"}} +{"axes": {"M": 19}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "739b8f454f7b43eb88486cf8056459ef", "tags": {"from": "gen_workload"}} +{"axes": {"M": 20}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "70384149b09044ca8daef1626c608a6c", "tags": {"from": "gen_workload"}} +{"axes": {"M": 21}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "33a9891a4ace4a24a415c0ef8b768548", "tags": {"from": "gen_workload"}} +{"axes": {"M": 22}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "dbfb345dcdb14168b9832f8d1c36d38b", "tags": {"from": "gen_workload"}} +{"axes": {"M": 23}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "4b617b1e3a8049419ddfb94a07a43bfd", "tags": {"from": "gen_workload"}} +{"axes": {"M": 24}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "77657dfb13c343a3b08483f0a9a73091", "tags": {"from": "gen_workload"}} +{"axes": {"M": 25}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "a5ae426d4537422d96a969b49d74d1c8", "tags": {"from": "gen_workload"}} +{"axes": {"M": 26}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "ea59825a19dc40e88f9c93add81f969c", "tags": {"from": "gen_workload"}} +{"axes": {"M": 27}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "f77b28fa29f14d4e8857e58612794f62", "tags": {"from": "gen_workload"}} +{"axes": {"M": 28}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "cced441836154d318b3030d644eadf33", "tags": {"from": "gen_workload"}} +{"axes": {"M": 11}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "b6c27b83d74c49b599583052cfcf01ee", "tags": {"from": "gen_workload"}} +{"axes": {"M": 29}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "3e8b11bf1490465ab97cde71a18fa1dd", "tags": {"from": "gen_workload"}} +{"axes": {"M": 30}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "7ba8e94c49f543efb820529ef8eccdd4", "tags": {"from": "gen_workload"}} +{"axes": {"M": 31}, "inputs": {"A": {"type": "random"}, "B_q4": {"type": "random"}, "B_scales": {"type": "random"}, "B_mins": {"type": "random"}}, "uuid": "8fda192b05d04e52a9619bc27f1300e6", "tags": {"from": "gen_workload"}} diff --git a/workloads/mha/mha_fp32_h16_d128_kvh16.jsonl b/workloads/mha/mha_bf16_h16_d128_kvh16.jsonl similarity index 100% rename from workloads/mha/mha_fp32_h16_d128_kvh16.jsonl rename to workloads/mha/mha_bf16_h16_d128_kvh16.jsonl diff --git a/workloads/moe/moe_fp32_e60_k4_d2048_ff1408.jsonl b/workloads/moe/moe_bf16_e60_k4_d2048_ff1408.jsonl similarity index 100% rename from workloads/moe/moe_fp32_e60_k4_d2048_ff1408.jsonl rename to workloads/moe/moe_bf16_e60_k4_d2048_ff1408.jsonl diff --git a/workloads/moe/moe_fp32_e64_k8_d2048_ff1024.jsonl b/workloads/moe/moe_bf16_e64_k8_d2048_ff1024.jsonl similarity index 100% rename from workloads/moe/moe_fp32_e64_k8_d2048_ff1024.jsonl rename to workloads/moe/moe_bf16_e64_k8_d2048_ff1024.jsonl diff --git a/workloads/moe/moe_q4_k_m_e60_k4_d2048_ff1536.jsonl b/workloads/moe/moe_q4_k_m_e60_k4_d2048_ff1536.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..f0723bea2b2257970465d6a3f2a2e84a53db74e5 --- /dev/null +++ b/workloads/moe/moe_q4_k_m_e60_k4_d2048_ff1536.jsonl @@ -0,0 +1,20 @@ +{"axes": {"n_tokens": 1}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "f351c56f70404c708d596916123f8997", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 11}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "e45c2ab1272e4a3287594994845201e3", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 12}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "42a95ef10e8447e290b4c507a4f965cf", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 13}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "01eb5ea522cf44bf8c107a2d36ffbe4a", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 14}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "9b4737991f9d4d49bbdcafdb1ee505c5", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 15}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "ba5858d92e994fb0a77642db5371aeef", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 16}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "dd050dcf985c4c35b3b5be6871c1dd35", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 17}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "c1c4a056fdc348e88eeea59300fe367e", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 18}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "dd04dffafe25476d9b2fcff78bcb5bc3", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 19}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "6b4067aabd3c4bc0b2f7e55877ca20b5", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 20}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "162e39be736b45e0a296d073a3f3f9b1", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 21}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "3b4c8a9c2dda4243a34e1f13d81cde52", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 22}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "9e7f653269bd441283a096b7c5cac9fa", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 23}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "4a3f1bebcffb4fcf9959cfaaf044b2ab", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 24}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "cc08526d3cd744119b94725bb284cfff", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 25}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "568f4bb28e4e4c599c01aebc6437399a", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 26}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "11844aed89e841cf827ffd8ec84a5b15", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 29}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "bd0cb2a2cfad4c6d844f9e4bd4966796", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 30}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "6964a1defd5744d287501d5b63002488", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 31}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "1b1403c22ab04b47bbb68338cbd54d58", "tags": {"from": "gen_workload"}} diff --git a/workloads/moe/moe_q4_k_m_e64_k8_d2048_ff1024.jsonl b/workloads/moe/moe_q4_k_m_e64_k8_d2048_ff1024.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..3a77109a1d0b89b359251ec7e4f0495aba7c69ed --- /dev/null +++ b/workloads/moe/moe_q4_k_m_e64_k8_d2048_ff1024.jsonl @@ -0,0 +1,20 @@ +{"axes": {"n_tokens": 1}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "f2736bb01b0b41ab999c3e7071419f05", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 11}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "e6fea1bf3de246ed8378fa12f3ca2485", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 12}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "290c47812b6848df9491916cf414d339", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 13}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "4563daef7c324efd8d27c1941bee29d6", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 14}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "ad11b2260ec946089ea4e8a7c5de03b5", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 15}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "bb87393fa5194c3aabe343b99830eac8", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 16}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "f31b58d6876f4eebb771a5fca872d2f7", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 17}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "e2c7f10ecb974c40899fe390a5a345db", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 18}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "56c78ab5aab049faa23f52315e31256a", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 19}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "970d06f56b6045019a7cc0ead620b5a2", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 20}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "33b1b87116774a9a9edec21d97afa80f", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 21}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "eab06c5968654e8da479dc57d7e51935", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 22}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "5dc0685b8b0c46ed99873f500c612570", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 23}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "cf4138be18a846288f0a215e2dd3701d", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 24}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "db8668a5086b4499b7ee2d5cd16c88f5", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 25}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "ec22a065cbc44ca9a15563baf32ae59e", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 26}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "0bae4022dad04931ad9b36aff6fd8b4d", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 29}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "e012181a2f2147ffa1045be013fd2410", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 30}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "5af6fbbdfa994d8a81c17b4e0306d167", "tags": {"from": "gen_workload"}} +{"axes": {"n_tokens": 31}, "inputs": {"hidden_states": {"type": "random"}, "router_weight": {"type": "random"}, "gate_proj_q4": {"type": "random"}, "gate_proj_scales": {"type": "random"}, "gate_proj_mins": {"type": "random"}, "up_proj_q4": {"type": "random"}, "up_proj_scales": {"type": "random"}, "up_proj_mins": {"type": "random"}, "down_proj_q4": {"type": "random"}, "down_proj_scales": {"type": "random"}, "down_proj_mins": {"type": "random"}}, "uuid": "e88305e819d04775a2c896c860d78c72", "tags": {"from": "gen_workload"}} diff --git a/workloads/rms_norm/rms_norm_fp32_d2048.jsonl b/workloads/rms_norm/rms_norm_bf16_d2048.jsonl similarity index 100% rename from workloads/rms_norm/rms_norm_fp32_d2048.jsonl rename to workloads/rms_norm/rms_norm_bf16_d2048.jsonl