add-cuda-kernel

add-cuda-kernel is a skill for Claude Code, Codex from flashinfer-ai/flashinfer. It costs 18 tokens per session (7,616 once invoked), scanned A, original, Apache-2.0.

A step-by-step guide for adding CUDA kernels to FlashInfer. CUDA kernels are small GPU programs that perform specific computations.

In plain words
What is it for?
Use it as a template when implementing and integrating a new FlashInfer GPU operation.
Why use it?
It explains the full process of adding an element-by-element scaling operation and supporting common data types.

Skill for Claude CodeCodex

About the project

FlashInfer is a library and kernel generator that supplies GPU operations used to run large language model inference, including attention, matrix multiplication, and mixture-of-experts computations. It helps engineers build and optimize LLM serving systems across supported GPU hardware and backend implementations. Its catalogue add-ons provide skills and instructions for working with FlashInfer.

flashinfer-ai/flashinfer · 6,337 stars · on GitHub · flashinfer.ai

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

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/flashinfer-ai/flashinfer/add-cuda-kernel.svg)](https://agentmods.dev/skills/flashinfer-ai/flashinfer/add-cuda-kernel)
Your own site
<a href="https://agentmods.dev/skills/flashinfer-ai/flashinfer/add-cuda-kernel"><img src="https://agentmods.dev/badge/skills/flashinfer-ai/flashinfer/add-cuda-kernel.svg" alt="Measured on agentmods" height="20"></a>
Per session 18 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 7,616 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.00018 $0.07616
Opus 5 $0.00009 $0.03808
Sonnet 5 $0.00004 $0.01523
Haiku 4.5 $0.00002 $0.00762

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

Security

Grade A, and why

add-cuda-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-cuda-kernel/SKILL.md · 957 lines

How it starts

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

Tutorial: Adding a New Kernel to FlashInfer

This tutorial walks through adding a simple element-wise scale operation to FlashInfer. 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 and scalar factor
  • Output: x * factor (element-wise)
  • Support multiple dtypes (FP16, BF16, FP32)

Step 1: Define CUDA Kernel in include/

Create include/flashinfer/scale.cuh:

#pragma once
#include <cuda_runtime.h>
#include <cuda_fp16.h>
#include <cuda_bf16.h>

namespace flashinfer {

/*!
 * \brief Element-wise scale kernel
 * \tparam T Data type (half, __nv_bfloat16, float)
 * \param input Input tensor
 * \param output Output tensor
 * \param factor Scale factor
 * \param n Number of elements
 */
template <typename T>
__global__ void ScaleKernel(const T* input, T* output, T factor, int n) {
  int idx = blockIdx.x * blockDim.x + threadIdx.x;
  if (idx < n) {
    output[idx] = input[idx] * factor;
  }
}

/*!
 * \brief Launch scale kernel
 * \tparam T Data type
 * \param input Input pointer
 * \param output Output pointer
 * \param factor Scale factor
 * \param n Number of elements
 * \param stream CUDA stream
 */
template <typename T>
cudaError_t ScaleLauncher(const T* input, T* output, T factor, int n,
                          cudaStream_t stream = nullptr) {
  const int threads = 256;
  const int blocks = (n + threads - 1) / threads;

  ScaleKernel<T><<<blocks, threads, 0, stream>>>(input, output, factor, n);

  return cudaGetLastError();
}

}  // namespace flashinfer

Key points:

  • Framework-agnostic (no Torch headers)
  • Uses raw pointers
  • Template-based for dtype flexibility
  • Only includes what's needed (cuda_runtime, cuda_fp16, cuda_bf16)

Step 2: Create Launcher in csrc/

Create csrc/scale.cu:

#include "flashinfer/scale.cuh"

using namespace flashinfer;

void scale_launcher(TensorView input, TensorView output,
                    float factor) {
  CHECK_INPUT(input);
  CHECK_INPUT(output);
  TVM_FFI_ICHECK_EQ(input.dtype(), output.dtype());
  int n = input.numel();
  auto stream = get_stream(input.device());

  DISPATCH_DLPACK_DTYPE_TO_CTYPE_FP32_FP16(input.dtype(), DType, [&] {
    cudaError_t status = ScaleLauncher<DType>(
      input.data_ptr<DType>(),
      output.data_ptr<DType>(),
      static_cast<DType>(factor),
      n,
      stream
    );
    TVM_FFI_ICHECK(status == cudaSuccess)
        << "Failed to run ScaleLauncher: " << cudaGetErrorString(status);
    return true;
  });
}

Read the full file on GitHub · 957 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 · 957 lines · 18 tokens per session scan A b8381f9f36a6

Subscribe to this mod's changes

add-cuda-kernel is a skill published in the GitHub repository flashinfer-ai/flashinfer (6,337 stars, last pushed today), licensed Apache-2.0. It adds 18 tokens to every session and 7,616 once invoked, about $0.0001 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.

Related

Other skills, from other repositories

megakernel-optimization

Use when optimizing or generating a CUDA megakernel for a HuggingFace Llama-family model with AutoMegaKernel (AMK), drives the correctness-gated propose -> eval -> keep/revert loop (or hands off to the unattended autoresearch driver).

RightNow-AI/AutoMegaKernel · 57 tokens

cuopt-developer

Modify, build, test, debug, and contribute to NVIDIA cuOpt (C++/CUDA, Python, server, CI). Use for solver internals, PRs, DCO, and code conventions.

NVIDIA/cuopt · 47 tokens

add-sgl-kernel

Step-by-step tutorial for adding a heavyweight AOT CUDA/C++ kernel to sgl-kernel (including tests & benchmarks).

sgl-project/sglang · 31 tokens

add-uint-support

Add unsigned integer (uint) type support to PyTorch operators by updating ATDISPATCH macros. Use when adding support for uint16, uint32, uint64 types to operators, kernels, or when user mentions enabling unsigned types, barebones unsigned types, or uint support.

pytorch/pytorch · 60 tokens

at-dispatch-v2

Convert PyTorch ATDISPATCH macros to ATDISPATCHV2 format in ATen C++ code. Use when porting ATDISPATCHALLTYPESAND, ATDISPATCHFLOATINGTYPES, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.

pytorch/pytorch · 70 tokens

cuda-index-width

Choose 32-bit vs 64-bit index math in PyTorch CUDA kernels. Use when fixing large-tensor indexing overflows, deciding whether to use int64t, canUse32BitIndexMath, CUDAKERNELLOOPTYPE, or ATDISPATCHINDEXTYPES, and when considering binary-size or performance impact of index-type templating.

pytorch/pytorch · 71 tokens