# Fused MoE router (`mega_gate`) | ServingStudio Kernel Library

One kernel that computes router logits, scores and biases them, picks the top-k experts and maps them to physical expert slots.

DeepGEMM's mega gate multiplies the bf16 hidden states by the bf16 router weight with fp32 accumulation, applies the scoring function and the score-correction bias, selects the top-k experts per token, scales their weights by the routed scaling factor and maps each choice to one of the expert's physical slots. It writes int32 slot indices and fp32 weights.

Category: MoE; group: Routing and combine. Interactive page: https://servingstudio.cs.washington.edu/kernels.html?kind=mega_gate. All kernel kinds: https://servingstudio.cs.washington.edu/kernels.md.

## Formula

- `FLOPs = 2 · num_tokens · num_experts · hidden_size`
- `bytes = 2 · num_tokens · hidden_size + 2 · num_experts · hidden_size + 8 · num_tokens · top_k`

## How it is measured

GPU kernel time from CUPTI activity records, averaged over repeated launches in one capture. The L2 cache is flushed before each launch, so the numbers are cold-cache times.

## Caveats

- Every redundant slot of an expert is equally likely; the slot map is DeepInfer's initial EPLB layout.

## Arguments

| Argument | Type | Unit | Meaning |
| --- | --- | --- | --- |
| `num_tokens` | number | tokens | Tokens routed on this GPU. |
| `hidden_size` | number | elements | Width of each token's hidden state. |
| `num_experts` | number | experts | Logical routed experts the router scores. |
| `num_physical_experts` | number | experts | Physical expert slots, redundant (EPLB) slots included, that choices map to. |
| `top_k` | number | experts | Experts selected per token. |
| `scoring_func` | label |  | Router scoring function, e.g. sqrtsoftplus or sigmoid. |
| `dtype` | dtype |  | Element type of the hidden states and gate weight (bf16). |

## Metrics

- Time (`time_ms`, ms)
- Throughput (`tflops`, TFLOPS)
- Memory bandwidth (`memory_bandwidth_gbps`, GB/s)
- Energy (`energy_j`, J)

## Backends

- `deepgemm_sm100`: DeepGEMM bf16_mega_gate as DeepInfer calls it: score-correction bias, routed scaling, logical-to-physical slot map, no shared-as-routed. dtypes `bf16`, SM targets `sm_100f`, GPUs B200-SXM-180GB, B300-SXM-288GB, GB200-Superchip. Source: https://github.com/deepseek-ai/DeepGEMM

## Measured rows

274 rows in all.

| GPU | Backend | Precision | Rows |
| --- | --- | --- | --- |
| NVIDIA B200 | `deepgemm_sm100` | `bf16` | 274 |

## Used by these deployments

- [DeepSeek V4.1 Flash 1017: vLLM or DeepInfer, DP attention, EP MoE](https://servingstudio.cs.washington.edu/models/DeepSeek-V4.1-Flash-1017/deepseek_v41_vllm_dp_attn_ep_moe.md) (`DeepSeek-V4.1-Flash-1017/deepseek_v41_vllm_dp_attn_ep_moe`)
- [DeepSeek V4.1 Flash 1017: vLLM, DP attention, EP MoE, DSpark speculative decoding](https://servingstudio.cs.washington.edu/models/DeepSeek-V4.1-Flash-1017/deepseek_v41_vllm_dp_attn_ep_moe_dspark.md) (`DeepSeek-V4.1-Flash-1017/deepseek_v41_vllm_dp_attn_ep_moe_dspark`)

## API

- This kind: https://servingstudio.cs.washington.edu/api/public/v1/kernels/mega_gate
- Measured rows: https://servingstudio.cs.washington.edu/api/public/v1/kernels/mega_gate/rows (filter by any column, such as `?gpu=NVIDIA%20H200`; `format=csv` for CSV)
- Configs the public deployments ask of it: https://servingstudio.cs.washington.edu/api/public/v1/kernels/mega_gate/configs

---

This page as Markdown: https://servingstudio.cs.washington.edu/kernels/mega_gate.md. A guide to the whole site for AI agents: [llms.txt](https://servingstudio.cs.washington.edu/llms.txt).
