gpuArray
Copy an array to the GPU device.
📝Syntax
G = gpuArray(A)
📥Input Arguments
Parameter Description
A a real, logical, complex or small-integer numeric array.
📤Output Arguments
Parameter Description
G a gpuArray stored on the device.
📄Description

G = gpuArray(A) copies the array A to the GPU and returns a gpuArray object. Operations on G run on the device; use gather to bring the result back to the host.

The device stores data in single precision: a double input is downcast to single. Real, logical and complex inputs are supported; sparse inputs are not.

The small integer classes int8, uint8, int16 and uint16 are preserved: their values are exact in single precision, arithmetic saturates to the class range and gather returns the original class.

int32 and uint32 are also preserved (stored as raw 32-bit integer bits): round-trip, saturating +, -, .*, ./, .\, unary minus, abs, max/min (element-wise and reductions), sum, prod, mean, cumsum, cumprod, sort, find, integer power (.^ with a non-negative exponent), relational operators and the reshaping/indexing operations are supported. Operations that have no integer meaning (the transcendental elementwise math functions) raise a clear error. The 64-bit integer classes are not supported.

A compatible GPU is required (see canUseGPU).

A device array can also be created directly with zeros(sz, 'gpuArray') / ones(sz, 'gpuArray'), or with the 'like' form zeros(sz, 'like', G) where G is a gpuArray.

💡Examples
A = single(rand(1000));
G = gpuArray(A);
R = gather(G .* G + sqrt(G));
class(G)
🔗See Also
gatherisgpuarraycanUseGPU
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub