write-cuda-layernorm-kernel

write-cuda-layernorm-kernel is a skill for Claude Code, Codex from tensormux/kernel-skills. It costs 0 tokens per session (3,507 once invoked), scanned A, original, MIT.

A guide to writing custom NVIDIA GPU code for LayerNorm and RMSNorm, operations that normalize values in machine-learning models. It covers forward and backward calculations, numerical accuracy, and unusual data sizes.

In plain words
What is it for?
Designing, implementing, or tuning custom CUDA normalization kernels, including fused operations, gradient calculations, and non-power-of-two hidden dimensions.
Why use it?
It helps when standard library implementations do not fit a model's shape or when several operations need to be combined to reduce memory transfers.

Skill for Claude CodeCodex

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/tensormux/kernel-skills/write-cuda-layernorm-kernel
Any agent
npx skills add tensormux/kernel-skills --skill write-cuda-layernorm-kernel
Clone the repo
git clone --depth 1 https://github.com/tensormux/kernel-skills

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 write-cuda-layernorm-kernel

README.md
[![agentmods](https://agentmods.dev/badge/skills/tensormux/kernel-skills/write-cuda-layernorm-kernel.svg)](https://agentmods.dev/skills/tensormux/kernel-skills/write-cuda-layernorm-kernel)
Your own site
<a href="https://agentmods.dev/skills/tensormux/kernel-skills/write-cuda-layernorm-kernel"><img src="https://agentmods.dev/badge/skills/tensormux/kernel-skills/write-cuda-layernorm-kernel.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,507 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 $0.00000 $0.03507
Opus 5 $0.00000 $0.01754
Sonnet 5 $0.00000 $0.00701
Haiku 4.5 $0.00000 $0.00351

Measured 5d ago against content hash 4a5b3c51e9ad, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

write-cuda-layernorm-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 5d 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.

skills/cuda/write-cuda-layernorm-kernel/SKILL.md · 127 lines

How it starts

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

Skill: Write CUDA LayerNorm Kernel

Purpose

Guide the agent through designing and implementing a correct, efficient CUDA LayerNorm (and RMSNorm) kernel, covering mean/variance computation strategies, Welford online accumulation, epsilon placement, affine transform application, backward pass structure, and decomposition for non-power-of-two hidden dimensions.

Use this when

  • You need a custom LayerNorm kernel with a non-standard normalization axis, fused activation, or non-standard epilogue
  • You are implementing RMSNorm (no mean subtraction, only variance normalization) and need a custom kernel
  • You need the backward pass and require explicit control over the gradient computation for numerical accuracy or fusion
  • The hidden dimension size does not match the assumptions of library implementations, or you need custom handling of non-power-of-two sizes
  • You are fusing LayerNorm with a preceding or following operation and need to avoid extra memory round-trips

Do not use this when

  • Standard forward-only LayerNorm with affine parameters on common hidden dimensions: use torch.nn.LayerNorm (which calls into cuDNN or a well-tuned CUDA kernel) or APEX's FusedLayerNorm
  • You are using PyTorch with autograd: the built-in LayerNorm already has a correct, optimized backward pass
  • The normalization is applied over batch dimensions (BatchNorm): this skill covers LayerNorm (normalization over the last D dimensions within a single sample)

Inputs the agent should gather first

  • Input shape: [batch, seq, hidden] or [N, D] where D is the normalization dimension. What is the hidden dimension size? Is it always the same or variable at runtime?
  • Normalization axis: which dimension(s) are normalized? LayerNorm normalizes over the last D dimensions; confirm this assumption.
  • Dtype: fp32, fp16, or bf16 for input/output. What dtype are the gamma/beta parameters? (Usually fp32 even when input is fp16.)
  • Affine parameters: are gamma (scale) and beta (shift) parameters present (LayerNorm) or absent (plain normalization)?
  • Epsilon: what value? Typically 1e-5 for LayerNorm, 1e-6 for RMSNorm. Is it applied inside or outside the sqrt?
  • Forward only vs forward + backward: does the kernel need to support gradient computation? If yes, what tensors need to be saved from the forward pass?
  • RMSNorm variant: should mean subtraction be skipped (RMSNorm only divides by the root mean square, not the standard deviation)?
  • Hardware target: SM architecture.

Read the full file on GitHub · 127 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 5d ago First seen · 127 lines · 0 tokens per session scan A 4a5b3c51e9ad

Subscribe to this mod's changes

write-cuda-layernorm-kernel is a skill published in the GitHub repository tensormux/kernel-skills (73 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 3,507 tokens. 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.

Related

Other skills, from other repositories