RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • mex
    • mexcuda
    • mexext

mexcuda — Build a native CUDA MEX module with the configured nvcc toolchain.

mexcuda(source, options...) delegates to the shared MEX builder in CUDA mode. It requires at least one .cu translation unit and returns no value. CUDA compilation is currently supported only on native Linux and Windows targets with a compatible nvcc toolchain.

Syntax

mexcuda(arguments)

Inputs

arguments
Type
Any
Required
Variadic
Default
—
Description
Native CUDA source files and MEX options as scalar text; RunMat also converts scalar numeric and logical arguments to text.
NameTypeRequiredDefaultDescription
argumentsAnyVariadic—Native CUDA source files and MEX options as scalar text; RunMat also converts scalar numeric and logical arguments to text.

Errors

RunMat:MEX:UnsupportedTarget
When
The current target cannot load native MEX modules.
Message
MEX modules are unavailable on this target.
RunMat:MEX:InvalidBuildArguments
When
The MEX command receives no source file or an invalid build option.
Message
mex: invalid build arguments.
RunMat:MEX:BuildFailed
When
The selected compiler cannot produce the requested MEX module.
Message
mex: C MEX compilation failed.
RunMat:MEX:TooManyOutputs
When
The caller requests more results than the MEX build or target query returns.
Message
Too many MEX output arguments.
IdentifierWhenMessage
RunMat:MEX:UnsupportedTargetThe current target cannot load native MEX modules.MEX modules are unavailable on this target.
RunMat:MEX:InvalidBuildArgumentsThe MEX command receives no source file or an invalid build option.mex: invalid build arguments.
RunMat:MEX:BuildFailedThe selected compiler cannot produce the requested MEX module.mex: C MEX compilation failed.
RunMat:MEX:TooManyOutputsThe caller requests more results than the MEX build or target query returns.Too many MEX output arguments.

CUDA build contract

A .cu source is required even when C or C++ sources accompany it. Source paths, output naming, include/library flags, compiler assignments, verbosity, and the -R2017b/-R2018a API pins use the same parser as mex. Mixed Fortran/CUDA gateway sources are rejected by the adapter. The build records a target- and ABI-bound manifest for the resulting module.

Scalar numbers and logical arguments are currently converted to text by RunMat's call boundary, like mex; this coercion is not MATLAB API parity. Unsupported targets are reported as UnsupportedTarget, invalid invocation options as InvalidBuildArguments, and compiler/SDK/output failures as BuildFailed with their build cause.

Execution limits

CUDA compilation uses native process, filesystem, environment, and console effects. It is not itself a provider-resident array computation: the CUDA gateway's runtime behavior and ownership are validated separately when loaded. Building is unsupported in browser/Worker sessions and on native targets lacking the supported CUDA toolchain contract.

The current compiler call blocks the caller. It cannot interrupt an in-flight compiler on invocation cancellation and does not enforce a complete-call host-memory budget.

Examples

Build a CUDA gateway with the R2018a API

mexcuda('-R2018a', '-output', 'cuda_gateway', 'cuda_gateway.cu');
module = strcat('cuda_gateway.', mexext());
assert(isfile(module));

Require a source argument

mexcuda();

Using mexcuda with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how mexcuda changes the result.

Run a small mexcuda example, explain the result, then change one input and compare the output.

FAQ

Is a CUDA-capable GPU needed just to build?⌄

The build requires a supported native CUDA compiler/toolchain; executing the compiled gateway has separate accelerator and loader requirements.

Can I mix a Fortran gateway with CUDA?⌄

No. The shared MEX builder rejects mixed Fortran and CUDA gateway sources.

Related Interop functions

Mex

mex · mexext

Native

calllib · clibgen.buildInterface · libfunctions · libisloaded · libpointer · libstruct · loadlibrary · setdatatype · unloadlibrary

Java

isjava · javaaddpath · javaArray · javaclasspath · javaMethod · javaMethodEDT · javaObject · javaObjectEDT · javarmpath · jenv · usejava

Python

pyargs · pyenv · pyrun · pyrunfile · terminate

Related guides

  • MEX execution and build compatibility
  • Native extension development

Source you can read

Every RunMat function's source is public. Read exactly how mexcuda is executed, line by line, in Rust.

  • View the source for mexcuda in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Errors
  • CUDA build contract
  • Execution limits
  • Examples
  • Build a CUDA gateway with the R2018a API
  • Require a source argument
  • Using mexcuda with coding agents
  • FAQ
  • Related Interop functions
  • Mex
  • Native
  • Java
  • Python
  • Related guides
  • Source you can read
  • About RunMat