gpuDevice — Query metadata about the active GPU provider and return it as a MATLAB struct.
info = gpuDevice() queries the active accelerator provider and returns a MATLAB struct that describes the GPU (or GPU-like backend) that RunMat is currently using. The struct mirrors MathWorks MATLAB's gpuDevice metadata, exposing identifiers, vendor information, memory hints, and precision support so you can adapt algorithms at runtime.
The returned struct contains a subset of these fields (providers may omit ones they cannot populate):
device_id— zero-based identifier reported by the provider.index— MATLAB-style one-based index derived fromdevice_id.name— human-readable adapter name.vendor— provider-reported vendor or implementation name.backend— backend identifier such asinprocessorVulkan(optional).memory_bytes— total device memory in bytes when known (optional).precision— string describing the scalar precision used for kernels ("double"or"single").supports_double— logical flag that istruewhen double precision kernels are available.
The builtin raises gpuDevice: no acceleration provider registered when no provider is active.
How gpuDevice works in RunMat
- Requires an acceleration provider that implements RunMat Accelerate's
AccelProvidertrait. - Returns a struct so you can access fields with dot notation:
gpuDevice().name. - Does not mutate GPU state or enqueue kernels—it is safe to call frequently.
- Accepts a scalar device index;
gpuDevice(1)returns the active provider, while any other index raises the MATLAB-style errorgpuDevice: GPU device with index N not available. - Requests to reset the provider using
gpuDevice('reset')orgpuDevice([])currently raisegpuDevice: reset is not supported by the active provider. - Hooks into
gpuInfoso the string-form summary stays in sync with the struct fields.
GPU memory and residency
gpuDevice purely reports metadata and does not change residency. Arrays remain on the GPU or CPU exactly as they were prior to the call. Use gpuArray, gather, and the planner-controlled automatic residency features to move data as needed.
Examples
Inspecting the active GPU provider
info = gpuDevice();
disp(info.name)Expected output:
InProcessDisplaying vendor and backend metadata
info = gpuDevice();
fprintf("Vendor: %s (backend: %s)\n", info.vendor, info.backend)Expected output:
Vendor: RunMat (backend: inprocess)Checking whether double precision is supported
info = gpuDevice();
if info.supports_double
disp("Double precision kernels are available.");
else
disp("Provider only exposes single precision.");
endFormatting a user-facing status message
summary = gpuInfo();
disp("Active GPU summary:");
disp(summary)Expected output:
Active GPU summary:
GPU[device_id=0, index=1, name='InProcess', vendor='RunMat', backend='inprocess', precision='double', supports_double=true]Handling missing providers gracefully
try
info = gpuDevice();
catch ex
warning("GPU unavailable: %s", ex.message);
endFAQ
Do I need to call gpuDevice before using other GPU builtins?
No. RunMat initialises the active provider during startup. gpuDevice is purely informational and can be called at any time to inspect the current provider.
Why are some fields missing from the struct?
Providers only fill metadata they can reliably supply. For example, the in-process test provider does not report memory_bytes. Real GPU backends typically populate additional fields.
What happens if there is no GPU provider?
RunMat raises gpuDevice: no acceleration provider registered. You can catch this error and fall back to CPU code, as shown in the examples above.
Does gpuDevice support selecting or resetting devices?
RunMat currently exposes a single provider. gpuDevice(1) returns that provider, matching MATLAB's first-device semantics, while any other index raises gpuDevice: GPU device with index N not available. Reset requests (gpuDevice('reset') or gpuDevice([])) are not implemented yet and return gpuDevice: reset is not supported by the active provider.
How can I get a quick string summary instead of a struct?
Use gpuInfo(). It internally calls gpuDevice and formats the struct fields into a concise status string that is convenient for logging or display.
Related functions to explore
These functions work well alongside gpuDevice. Each page has runnable examples you can try in the browser.
gpuArray, gather, gpuInfo, arrayfun, pagefun
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how gpuDevice works, line by line, in Rust.
- View gpuDevice.rs on GitHub
- Learn how the runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.