stencil-convolution
Expert skill for optimized stencil and convolution pattern implementations on GPU. Design tiled stencil algorithms with halos, implement 2D/3D convolution kernels, optimize boundary condition handling, apply temporal blocking techniques, generate separable filter implementations, and profile stencil memory bandwidth.
What this skill does
# stencil-convolution
You are **stencil-convolution** - a specialized skill for optimized stencil and convolution pattern implementations on GPU. This skill provides expert capabilities for scientific computing, image processing, and numerical simulations requiring neighborhood computations.
## Overview
This skill enables AI-powered stencil and convolution operations including:
- Designing tiled stencil algorithms with halos
- Implementing 2D/3D convolution kernels
- Optimizing boundary condition handling
- Applying temporal blocking techniques
- Generating separable filter implementations
- Configuring shared memory tiling strategies
- Profiling stencil memory bandwidth
- Supporting multi-resolution stencils
## Prerequisites
- NVIDIA CUDA Toolkit 11.0+
- GPU with compute capability 3.5+
- Understanding of memory coalescing patterns
- Nsight Compute for memory analysis
- Optional: cuDNN for optimized convolutions
## Capabilities
### 1. Basic 2D Stencil (5-Point Laplacian)
```cuda
// Naive 5-point stencil (for comparison)
__global__ void laplacian2D_naive(
float* out, const float* in,
int width, int height
) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
if (x >= 1 && x < width - 1 && y >= 1 && y < height - 1) {
int idx = y * width + x;
out[idx] = -4.0f * in[idx]
+ in[idx - 1] // left
+ in[idx + 1] // right
+ in[idx - width] // up
+ in[idx + width]; // down
}
}
```
### 2. Tiled Stencil with Shared Memory and Halo
```cuda
#define TILE_X 32
#define TILE_Y 32
#define HALO 1
__global__ void laplacian2D_tiled(
float* out, const float* in,
int width, int height
) {
// Shared memory with halo
__shared__ float tile[TILE_Y + 2 * HALO][TILE_X + 2 * HALO];
// Global coordinates
int gx = blockIdx.x * TILE_X + threadIdx.x;
int gy = blockIdx.y * TILE_Y + threadIdx.y;
// Local coordinates in shared memory (offset by halo)
int lx = threadIdx.x + HALO;
int ly = threadIdx.y + HALO;
// Load center tile
if (gx < width && gy < height) {
tile[ly][lx] = in[gy * width + gx];
}
// Load halo regions
// Left halo
if (threadIdx.x < HALO && gx >= HALO) {
tile[ly][lx - HALO] = in[gy * width + (gx - HALO)];
}
// Right halo
if (threadIdx.x >= TILE_X - HALO && gx + HALO < width) {
tile[ly][lx + HALO] = in[gy * width + (gx + HALO)];
}
// Top halo
if (threadIdx.y < HALO && gy >= HALO) {
tile[ly - HALO][lx] = in[(gy - HALO) * width + gx];
}
// Bottom halo
if (threadIdx.y >= TILE_Y - HALO && gy + HALO < height) {
tile[ly + HALO][lx] = in[(gy + HALO) * width + gx];
}
// Corner halos (if needed for larger stencils)
// ...
__syncthreads();
// Compute stencil using shared memory
if (gx >= 1 && gx < width - 1 && gy >= 1 && gy < height - 1) {
out[gy * width + gx] = -4.0f * tile[ly][lx]
+ tile[ly][lx - 1]
+ tile[ly][lx + 1]
+ tile[ly - 1][lx]
+ tile[ly + 1][lx];
}
}
```
### 3. Generic N-Point Stencil with Configurable Radius
```cuda
template <int RADIUS>
__global__ void stencil2D_generic(
float* out, const float* in,
const float* weights, // Stencil weights
int width, int height
) {
extern __shared__ float tile[];
const int TILE_X = blockDim.x;
const int TILE_Y = blockDim.y;
const int TILE_PITCH = TILE_X + 2 * RADIUS;
int gx = blockIdx.x * TILE_X + threadIdx.x;
int gy = blockIdx.y * TILE_Y + threadIdx.y;
int lx = threadIdx.x + RADIUS;
int ly = threadIdx.y + RADIUS;
// Load tile with halos
// ... (similar to above but generic)
__syncthreads();
if (gx >= RADIUS && gx < width - RADIUS &&
gy >= RADIUS && gy < height - RADIUS) {
float result = 0.0f;
int wIdx = 0;
// Apply stencil weights
for (int dy = -RADIUS; dy <= RADIUS; dy++) {
for (int dx = -RADIUS; dx <= RADIUS; dx++) {
result += weights[wIdx++] * tile[(ly + dy) * TILE_PITCH + (lx + dx)];
}
}
out[gy * width + gx] = result;
}
}
```
### 4. 2D Convolution with Arbitrary Kernel
```cuda
#define CONV_TILE_X 32
#define CONV_TILE_Y 32
#define MAX_KERNEL_RADIUS 8
// Kernel weights in constant memory for fast access
__constant__ float c_kernel[(2 * MAX_KERNEL_RADIUS + 1) * (2 * MAX_KERNEL_RADIUS + 1)];
__global__ void convolution2D(
float* out, const float* in,
int width, int height,
int kernelRadius
) {
extern __shared__ float tile[];
int TILE_PITCH = CONV_TILE_X + 2 * kernelRadius;
int gx = blockIdx.x * CONV_TILE_X + threadIdx.x;
int gy = blockIdx.y * CONV_TILE_Y + threadIdx.y;
int lx = threadIdx.x + kernelRadius;
int ly = threadIdx.y + kernelRadius;
// Load center
if (gx < width && gy < height) {
tile[ly * TILE_PITCH + lx] = in[gy * width + gx];
} else {
tile[ly * TILE_PITCH + lx] = 0.0f; // Zero padding
}
// Load halos with boundary handling
// Left
if (threadIdx.x < kernelRadius) {
int srcX = gx - kernelRadius;
tile[ly * TILE_PITCH + (lx - kernelRadius)] =
(srcX >= 0 && gy < height) ? in[gy * width + srcX] : 0.0f;
}
// Right
if (threadIdx.x >= CONV_TILE_X - kernelRadius) {
int srcX = gx + kernelRadius;
tile[ly * TILE_PITCH + (lx + kernelRadius)] =
(srcX < width && gy < height) ? in[gy * width + srcX] : 0.0f;
}
// Top and bottom (similar pattern)
// ...
__syncthreads();
if (gx < width && gy < height) {
float sum = 0.0f;
int kernelSize = 2 * kernelRadius + 1;
for (int ky = -kernelRadius; ky <= kernelRadius; ky++) {
for (int kx = -kernelRadius; kx <= kernelRadius; kx++) {
int kidx = (ky + kernelRadius) * kernelSize + (kx + kernelRadius);
sum += c_kernel[kidx] * tile[(ly + ky) * TILE_PITCH + (lx + kx)];
}
}
out[gy * width + gx] = sum;
}
}
```
### 5. Separable Convolution (2-Pass for Performance)
```cuda
// Separable convolution is faster: O(2*r) vs O(r^2)
// First pass: horizontal convolution
__global__ void convolutionRow(
float* out, const float* in,
int width, int height, int radius
) {
extern __shared__ float tile[];
int gx = blockIdx.x * blockDim.x + threadIdx.x;
int gy = blockIdx.y;
int TILE_WIDTH = blockDim.x + 2 * radius;
int lx = threadIdx.x + radius;
// Load with halos
if (gx < width) {
tile[lx] = in[gy * width + gx];
}
if (threadIdx.x < radius) {
tile[threadIdx.x] = (gx >= radius) ? in[gy * width + gx - radius] : 0.0f;
tile[lx + blockDim.x] = (gx + blockDim.x < width) ?
in[gy * width + gx + blockDim.x] : 0.0f;
}
__syncthreads();
if (gx < width) {
float sum = 0.0f;
for (int k = -radius; k <= radius; k++) {
sum += c_kernelRow[k + radius] * tile[lx + k];
}
out[gy * width + gx] = sum;
}
}
// Second pass: vertical convolution
__global__ void convolutionColumn(
float* out, const float* in,
int width, int height, int radius
) {
extern __shared__ float tile[];
int gx = blockIdx.x;
int gy = blockIdx.y * blockDim.y + threadIdx.y;
int TILE_HEIGHT = blockDim.y + 2 * radius;
int ly = threadIdx.y + radius;
// Load with halos
if (gy < height) {
tile[ly] = in[gy * width + gx];
}
if (threadIdx.y < radius) {
tile[threadIdx.y] = (gy >= radius) ? in[(gy - radius) * width + gx] : 0.0f;
tile[ly + blockDim.y] = (gy + blockDim.y < height) ?
in[(gy + blockDim.y) * width + gx] : 0.0f;
}
__syncthreads();
if (gRelated in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.