add-sgl-kernel

add-sgl-kernel is a skill for Claude Code, Codex from sgl-project/sglang. It costs 31 tokens per session (3,388 once invoked), scanned A, original, Apache-2.0.

A step-by-step guide for adding a heavyweight ahead-of-time compiled CUDA/C++ operation to SGLang's kernel package. Ahead-of-time compilation builds the kernel before use, and CUDA runs the operation on NVIDIA graphics processors.

In plain words
What is it for?
Use it to add an element-by-element tensor scaling kernel supporting FP16, BF16, and FP32 data. It is intended for operations that depend on large C++ projects such as CUTLASS or must be included in the prebuilt package and PyTorch operation registration flow.
Why use it?
It shows the required implementation, test, and benchmark workflow for kernels that belong in the prebuilt system. It also helps distinguish these kernels from lighter operations that should use SGLang's JIT path.

Skill for Claude CodeCodex

About the project

SGLang is a framework for running inference for large language models and multimodal models, meaning it processes inputs to produce model outputs such as text or other media. It is used to serve and accelerate open AI models and related workloads.

sgl-project/sglang · 35,483 stars · on GitHub · sglang.io

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/sgl-project/sglang/add-sgl-kernel
Any agent
npx skills add sgl-project/sglang --skill add-sgl-kernel
Clone the repo
git clone --depth 1 https://github.com/sgl-project/sglang

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for add-sgl-kernel

README.md
[![agentmods](https://agentmods.dev/badge/skills/sgl-project/sglang/add-sgl-kernel.svg)](https://agentmods.dev/skills/sgl-project/sglang/add-sgl-kernel)
Your own site
<a href="https://agentmods.dev/skills/sgl-project/sglang/add-sgl-kernel"><img src="https://agentmods.dev/badge/skills/sgl-project/sglang/add-sgl-kernel.svg" alt="Measured on agentmods" height="20"></a>
Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,388 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00031 $0.03388
Opus 5 $0.00015 $0.01694
Sonnet 5 $0.00006 $0.00678
Haiku 4.5 $0.00003 $0.00339

Measured 6d ago against content hash 1560d3d9f4c9, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

add-sgl-kernel scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/add-sgl-kernel/SKILL.md · 368 lines

How it starts

The opening of the file, as written. The whole thing — 368 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Tutorial: Adding a New Kernel to sgl-kernel (AOT / Heavyweight)

This tutorial walks through adding a simple element-wise scale operation as an AOT kernel. We'll implement scale(x, factor) = x * factor to demonstrate the complete workflow.

Goal

Add a new operation that scales each element of a tensor by a scalar factor:

  • Input: tensor x (CUDA) and scalar factor (float)
  • Output: x * factor (element-wise, in-place or into pre-allocated out)
  • Supported dtypes: FP16 (torch.float16), BF16 (torch.bfloat16), FP32 (torch.float32)
    • Dispatched via DISPATCH_PYTORCH_DTYPE_TO_CTYPE_FLOAT_FP16 macro (defined in python/sglang/kernels/aot/include/utils.h)

Two rules of thumb (must follow)

  1. Prefer python/sglang/kernels/jit first when the kernel does not depend on CUTLASS or another large C++ project. This is the default path for lightweight kernels that benefit from rapid iteration.
  2. Prefer sgl-kernel when the kernel does depend on CUTLASS or another large C++ project, or when it should be part of the AOT wheel / torch op registration flow.
  3. Exception: if the dependency is flashinfer, or CUTLASS that is already provided through flashinfer, the kernel can still be implemented as jit_kernel.

In addition, every new kernel must ship with:

  • Tests (pytest)
  • A benchmark script (triton.testing)

Repository integration map

You will typically touch these files/areas:

  • Implementation: python/sglang/kernels/aot/csrc/elementwise/scale.cu (pick the right subdirectory)
  • Public declarations: python/sglang/kernels/aot/include/sgl_kernel_ops.h
  • Torch extension registration: python/sglang/kernels/aot/csrc/common_extension.cc
  • Build: python/sglang/kernels/aot/CMakeLists.txt (set(SOURCES ...))
  • Python API: python/sglang/kernels/aot/python/sgl_kernel/ and python/sglang/kernels/aot/python/sgl_kernel/__init__.py
  • Tests: python/sglang/kernels/aot/tests/test_scale.py
  • Benchmarks: python/sglang/kernels/aot/benchmark/bench_scale.py

Read the full file on GitHub · 368 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 368 lines · 31 tokens per session scan A 1560d3d9f4c9

Subscribe to this mod's changes

add-sgl-kernel is a skill published in the GitHub repository sgl-project/sglang (35,483 stars, last pushed today), licensed Apache-2.0. It adds 31 tokens to every session and 3,388 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.