# Matlab Optimize Gpu Codegen

Optimize MATLAB design files for GPU Coder to generate faster CUDA code.

- Repository: https://github.com/matlab/matlab-agentic-toolkit (1237 stars)
- Category: Design
- License: see repository
- Last updated: 2026-10-27
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-gpu-codegen -g -a claude-code -y`
Codex: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-gpu-codegen -g -a codex -y`
Cursor: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-gpu-codegen -g -a cursor -y`
Gemini CLI: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-gpu-codegen -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add matlab/matlab-agentic-toolkit`

## Description

Optimize MATLAB design files for GPU Coder to generate faster CUDA code. Iteratively profiles, rewrites, and benchmarks until performance targets are met or diagnostics are resolved. Use when asked to: optimize for GPU Coder, improve GPU codegen performance, profile generated GPU/CUDA code, profile GPU MEX, fix gpuPerformanceAnalyzer diagnostics, speed up GPU MEX, reduce GPU memory transfers, improve kernel parallelism, rewrite MATLAB for CUDA, or run gpuPerformanceAnalyzer.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Optimize MATLAB for GPU Code Generation

Iteratively optimize a MATLAB design file for GPU Coder: compile, benchmark,
apply structural optimizations, profile with gpuPerformanceAnalyzer, fix
diagnostics, and verify numerical equivalence at every step.

## When to Use

- User has a MATLAB function and wants faster GPU MEX or CUDA code
- User mentions GPU Coder, codegen, CUDA, gpuPerformanceAnalyzer
- User asks to profile generated GPU/CUDA code or GPU MEX (profiling generated
  GPU code is the entry point to this skill's diagnostic-fix workflow)
- User wants to reduce GPU memory, improve kernel parallelism, or fix Performance Analyzer diagnostics
- User has a `.m` design file and representative inputs

## When NOT to Use

- Workflows with no codegen
- `coder.gpuConfig("exe")`, standalone executables cannot be benchmarked or
  equivalence-checked from MATLAB. Suggest the user switch to `mex` or `lib`/`dll` and regenerate `exe` from the final optimized source.
- Simulink GPU code generation
- Writing new MATLAB functions from scratch (this skill optimizes existing code)
- Optimizing helper functions called by the design file, this skill optimizes the main design file only
- Hardware setup or CUDA toolkit installation
- General MATLAB performance tuning without GPU involvement
- The user's prompt does not mention GPU, codegen, CUDA, MEX, or profiling.
  Activation must be driven by the user's prompt alone, do not infer GPU
  intent from filenames or function contents. If unsure, ask before activating.

## Workflow

### Setup, Create Session Directory

All codegen artifacts, profiling outputs, and optimized versions go in a
single temp directory for the entire session. `pwd` must be `sessionDir` for
every codegen/benchmark/PA call, otherwise compiled MEX and SIL binaries
land in the user's working directory.

The rest: https://github.com/matlab/matlab-agentic-toolkit/blob/HEAD/skills-catalog/code-generation/matlab-optimize-gpu-codegen/SKILL.md
