Generates C/C++ or CUDA code from PyTorch (.pt2) and LiteRT (.tflite) AI models using MATLAB Coder or GPU Coder, including MEX, static/dynamic libraries, executables, and Simulink simulation.
Ships in code-generation. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Generate deployable C/C++ or CUDA code from an AI model using MATLAB Coder or GPU Coder. The workflow follows a common pattern regardless of model framework: load, inspect, write entry-point, generate MEX, verify, then generate production code.
importNetworkFromPyTorch (PyTorch), importNetworkFromTensorFlow (SavedModel), or importNetworkFromKeras (.keras/.h5) which return a dlnetwork. For deployment of an editable dlnetwork with model compression (INT8 quantization via dlquantizer, pruning, projection) or exportNetworkToSimulink workflows — use matlab-deploy-embedded-ai (Pattern 1).| Framework | Model format | Load function | Status |
|---|---|---|---|
| PyTorch | .pt2 | loadPyTorchExportedProgram | Supported (R2026a+) |
| LiteRT / TFLite | .tflite | loadLiteRTModel | Supported (R2026a+) |
For PyTorch-specific details (API routing, entry-point pattern, export workflow,
data layout, common mistakes): see references/pytorch-workflow.md.
For LiteRT-specific details (API routing, entry-point pattern, variable-size inputs,
Simulink integration, conventions): see references/litert-workflow.md.
For converting TensorFlow/Keras/.h5 to .tflite: see
references/tensorflow-to-litert-conversion.md.
The code generation workflow follows the same steps for any framework:
Load the model and check its input/output specifications to determine expected shapes and types.
Create a codegen-compatible entry-point function that:
The model file path must be wrapped with coder.Constant so it's known at
compile time.
Compare MATLAB inference output against the source framework to confirm correct loading. Use the same input data in both environments and compare with tolerance.
Always generate MEX before lib/exe to verify on the host machine:
CPU MEX:
cfg = coder.config("mex");
codegen -config cfg -args {coder.Constant("model_file"), input} entryPoint
CUDA MEX (GPU acceleration):
cfg = coder.gpuConfig("mex");
codegen -config cfg -args {coder.Constant("model_file"), input} entryPoint
For CPU MEX SIMD acceleration (SIMDAcceleration = 'Full' for AVX2 on
Intel/AMD), see the matlab-generate-code skill. For the DNN-
inference-specific MEX AVX2 ceiling, see references/dnn-codegen-options.md.
Compare MEX output against MATLAB reference using matlab.unittest with
tolerance:
refOut = entryPoint("model_file", input);
mexOut = entryPoint_mex("model_file", input);
testCase = matlab.unittest.TestCase.forInteractiveUse;
testCase.verifyThat(mexOut, matlab.unittest.constraints.IsEqualTo(refOut, ...
'Within', matlab.unittest.constraints.AbsoluteTolerance(single(1e-5))));
Once MEX is verified, generate production code:
cfgLib = coder.config("lib");
cfgLib.TargetLang = "C++"; % set to "C++" for C++ output; default is "C"
codegen -config cfgLib -args {coder.Constant("model_file"), input} entryPoint
For DLL: coder.config("dll"). For executable: coder.config("exe").
CUDA variants: Replace coder.config with coder.gpuConfig.
Performance tuning:
matlab-generate-code skill.slbuild
set_param patterns: see the matlab-deploy-embedded-code skill.DLTargetLibrary / DeepLearningConfig to
disable third-party DL libraries, LargeConstantGeneration to serialize
weights to data files): see references/dnn-codegen-options.md.For Simulink integration, use the dedicated PyTorch ExportedProgram block from
dlosslib — set ModelFilePath to the .pt2 file and it auto-detects
input/output shapes. No entry-point function or coder.Constant needed.
Pre/post-processing can be done with Simulink blocks around the dedicated block.
If you need everything in a single block, use a MATLAB Function block with
loadPyTorchExportedProgram + invoke (same pattern as the entry-point, but
the model path is a string literal — no coder.Constant).
Both paths support slbuild code generation (requires fixed-step solver + ERT
or GRT target). See references/simulink-workflow.md for full details.
For embedded deployment, use the same entry-point function with an Embedded Coder
configuration. See the matlab-deploy-embedded-code skill for ERT config,
hardware settings, PIL/SIL verification, and target-specific options.
Ask the user to install the skill if it is not installed
| Function | Purpose | Package | Since |
|---|---|---|---|
coder.Constant | Make argument a compile-time constant | MATLAB Coder | R2011a |
coder.gpuConfig | Create GPU (CUDA) code generation config | GPU Coder | R2017b |
codegen | Generate code | MATLAB Coder | R2011a |
loadPyTorchExportedProgram | Load .pt2 into MATLAB | MATLAB Coder Support Package for PyTorch and LiteRT Models | R2026a |
loadLiteRTModel | Load .tflite into MATLAB | MATLAB Coder Support Package for PyTorch and LiteRT Models | R2026a |
coder.Constant for the model file path argumentimportNetworkFromPyTorch, importNetworkFromTensorFlow, or importNetworkFromKeras in this skill — they return a dlnetwork on a different path. If the user needs a dlnetwork for quantization, projection, pruning, or exportNetworkToSimulink before code generation, route to matlab-deploy-embedded-ai insteadreferences/pytorch-workflow.md — Full PyTorch-specific workflow: API routing,
entry-point pattern, export guidance, common mistakes, and conventions. Consult
for any PyTorch/.pt2 model code generation task. Links to deeper PyTorch
references (API signatures, data layout, numeric verification, supported models).references/export-pytorch-models.md — Exporting an eager-mode PyTorch model to
.pt2 with torch.export (upstream of loading). Consult when the user has a
PyTorch model but no .pt2 file yet, or hits torch.export SerializeError /
kwarg-mismatch errors. Links to pytorch-export-patterns.md (per-source
templates) and pytorch-export-gotchas.md (torch 2.11 serialization fixes).references/simulink-workflow.md — Simulink integration: dedicated PyTorch
ExportedProgram block (Path A) vs MATLAB Function block (Path B), block mask
parameters, code generation config, and key differences from command-line codegen.references/litert-workflow.md — Full LiteRT-specific workflow: API routing
(loadLiteRTModel → inputSpecifications → invoke), entry-point pattern,
variable-size input handling, Simulink integration, and conventions. Consult
for any LiteRT/.tflite model code generation task.references/tensorflow-to-litert-conversion.md — Converting TensorFlow
SavedModel/Keras/.h5 to .tflite via the Python tf.lite.TFLiteConverter API.
Consult when the user has a TensorFlow model but no .tflite file yet.references/litert-numeric-verification.md — Verifying MEX numerics against
MATLAB reference for LiteRT models (tolerance guidance, common mismatches).references/codegen-workflow.md — Shared code generation steps for both
PyTorch and LiteRT: MEX generation, MEX verification, library/executable
targets, coder.Constant usage, and coder.DeepLearningConfig notes.references/dnn-codegen-options.md — DNN-INFERENCE-SPECIFIC codegen
options: DLTargetLibrary / DeepLearningConfig('none') for the plain-C
DL path, LargeConstantGeneration for serializing large DNN weights to
data files, and MEX SIMD ceiling in a DNN-inference context. Read this
when the generic file's knobs need DNN-specific framing (e.g., "the MEX
SIMD cap matters because inference is the target").matlab-generate-code — Generic MATLAB Coder tuning (SIMD instruction sets, OpenMP multi-threading, reduction-loop vectorization). Consult for performance options not specific to DNN inference.matlab-deploy-embedded-ai — dlnetwork-based codegen with model compression (quantization, pruning, projection) and exportNetworkToSimulink workflows (Pattern 1). Use it when the source is an editable dlnetwork in MATLAB rather than a .pt2 / .tflite file.matlab-optimize-gpu-codegen — CUDA-target codegen tuning (coder.gpuConfig, kernel fusion, memory-hierarchy options) when the deployment target is an NVIDIA GPU rather than CPU or embedded hardware.Copyright 2026 The MathWorks, Inc.
manifest.yaml (opens in a new tab)references/codegen-workflow.md (opens in a new tab)references/dnn-codegen-options.md (opens in a new tab)references/export-pytorch-models.md (opens in a new tab)references/litert-numeric-verification.md (opens in a new tab)references/litert-workflow.md (opens in a new tab)references/pytorch-api-reference.md (opens in a new tab)references/pytorch-data-layout.md (opens in a new tab)references/pytorch-export-gotchas.md (opens in a new tab)references/pytorch-export-patterns.md (opens in a new tab)references/pytorch-numeric-verification.md (opens in a new tab)references/pytorch-supported-models.md (opens in a new tab)references/pytorch-workflow.md (opens in a new tab)references/simulink-workflow.md (opens in a new tab)references/tensorflow-to-litert-conversion.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
matlab-coder, gpu-coder, code-generation, model-deployment, simulink
/code-generation:matlab-deploy-ai-modelfrom code-generation
npx claudepluginhub matlab/matlab-agentic-toolkit --plugin code-generation5 skills in this plugin
/matlab-deploy-embedded-codeDeploy MATLAB-generated code to embedded hardware using Embedded Coder. Use when configuring code generation for microcontrollers (STM32, Raspberry Pi, ARM Cortex), setting up PIL/SIL verification, disabling dynamic memory allocation, or configuring hardware-specific code generation settings. Covers ERT-based configurations, processor-in-the-loop testing, memory constraints, and the MEX→SIL→PIL verification progression.
/matlab-generate-codeGenerate, verify, refine, and accelerate C/C++ or CUDA code from MATLAB with MATLAB Coder, Embedded Coder, GPU Coder, or MATLAB Test. Also covers writing codegen-ready MATLAB code: language constraints, coder.* directives, and optimization patterns. Triggers on: codegen, MEX, deploy MATLAB as C/C++, GPU Coder, coder.screener, coder.config, coder.gpuConfig, coder.typeof, coder.runTest, matlabtest.coder.TestCase, SIL, embedded config, no dynamic memory, EnableMexProfiling, coder.timeit, coder.perfCompare, %#codegen, writing codegen-ready MATLAB, code generation readiness, coder.varsize, coder.unroll, coder.noImplicitExpansionInFunction, coder.ceval, coder.inline, coder.extrinsic, coder.const, coder.classSignature, class codegen limitations, temporal types codegen, DMA-off, stack-only, host-target InstructionSetExtensions, SIMDAcceleration, OptimizeReductions, host SIMD tuning, host OpenMP, codegen performance.
/matlab-optimize-gpu-codegenOptimize 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.
/matlab-review-fi-object-codeReviews MATLAB fixed-point (fi) code for performance, code generation efficiency, and correctness. Identifies antipatterns and suggests idiomatic improvements. Use when reviewing fi, fimath, numerictype, or quantizenumeric code.Other plugins' skills for the same job