{"record":{"id":"3944a04f0b16c984","repo":"sgl-project/sglang","slug":"fused-ipm-kernel-needs-used-1024-1f-kib-of-shar","errorCode":null,"errorMessage":"fused IPM kernel needs {used/1024:.1f} KiB of shared memory for NC={nc}, NV={nv}, but {gpu} allows {cap/1024:.1f} KiB/block. Either reduce problem size or switch to a tiled design.","messagePattern":"fused IPM kernel needs (.+?) KiB of shared memory for NC=(.+?), NV=(.+?), but (.+?) allows (.+?) KiB/block\\. Either reduce problem size or switch to a tiled design\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/lplb/shmem_budget.py","lineNumber":113,"sourceCode":"def gpu_budget_bytes(gpu: str) -> int:\n    key = gpu.lower()\n    if key not in GPU_BUDGETS_BYTES:\n        raise ValueError(\n            f\"unknown gpu '{gpu}', expected one of {sorted(GPU_BUDGETS_BYTES)}\"\n        )\n    return GPU_BUDGETS_BYTES[key]\n\n\ndef fits(nc: int, nv: int, gpu: str = \"h100\") -> bool:\n    return shmem_bytes(nc, nv) <= gpu_budget_bytes(gpu)\n\n\ndef assert_fits(nc: int, nv: int, gpu: str = \"h100\") -> None:\n    \"\"\"Raise if the fused kernel will not fit on the target GPU.\"\"\"\n    used = shmem_bytes(nc, nv)\n    cap = gpu_budget_bytes(gpu)\n    if used > cap:\n        raise ValueError(\n            f\"fused IPM kernel needs {used/1024:.1f} KiB of shared memory for \"\n            f\"NC={nc}, NV={nv}, but {gpu} allows {cap/1024:.1f} KiB/block. \"\n            f\"Either reduce problem size or switch to a tiled design.\"\n        )\n\n\ndef max_nc_for_nv(nv: int, gpu: str = \"h100\") -> int:\n    \"\"\"Largest NC that fits for a given NV. Solves\n        4 * (NC^2 + (NV+1)*NC + 3*NV) + pad <= cap\n    via the quadratic formula (monotone in NC). Returns 0 if even NC=1 overflows.\n    \"\"\"\n    cap = gpu_budget_bytes(gpu)\n    b = _BYTES_PER_ELEM\n    # cap - pad >= b * (NC^2 + (NV+1)*NC + 3*NV)\n    rhs = (cap - _RUNTIME_PAD_BYTES) / b - 3 * nv\n    if rhs <= 0:\n        return 0\n    # NC^2 + (NV+1)*NC - rhs <= 0","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/lplb/shmem_budget.py#L95-L131","documentation":"assert_fits computes the shared memory required by the fused interior-point-method kernel for the given NC/NV (constraint/variable counts) and compares it against the per-block shmem cap of the target GPU. Exceeding the cap means the kernel cannot launch. The error is a capacity-planning guard, not a runtime CUDA failure.","triggerScenarios":"Calling assert_fits(nc, nv, gpu) or LPLB warmup/solve with problem sizes whose shmem_bytes(nc, nv) exceeds gpu_budget_bytes(gpu); larger NC*NV combos on smaller-shmem GPUs (e.g. A100's 164 KiB vs H100's 228 KiB).","commonSituations":"Scaling up the LPLB problem (more constraints/vars) until it exceeds ~227 KiB on H100; targeting a consumer GPU with 99/100 KiB caps; forgetting that shmem scales with both nc and nv.","solutions":["Reduce nc or nv below the budget (the message states exact required vs allowed KiB)","Switch to the tiled / torch reference path (solve_ipm_torch_reference) which does not use one-block shared memory","Target a GPU with a larger per-block shmem budget (e.g. h100) if available"],"exampleFix":"// before\nwarmup(nc=8192, nv=8192)  # exceeds H100 227 KiB/block\n\n// after\nfrom sglang.kernels.ops.lplb.torch_solver import solve_ipm_torch_reference\nx, y, s = solve_ipm_torch_reference(A, b, c)","handlingStrategy":"validation","validationCode":"from sglang.kernels.ops.lplb.shmem_budget import fits\nif not fits(nc, nv, gpu='h100'):\n    use_fused = False  # route to reference solver","typeGuard":null,"tryCatchPattern":"try:\n    assert_fits(nc, nv, gpu)\nexcept ValueError as e:\n    logger.warning('%s; falling back to torch reference', e)\n    result = solve_ipm_torch_reference(A, b, c)","preventionTips":["Gate problem size with fits(nc, nv, gpu) at config time, before warmup","Budget against the weakest GPU in your fleet, not the strongest"],"tags":["shared-memory","capacity","lplb","cuda-kernel"],"backgroundTag":"shared-memory-budget-exceeded","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}