GPUArray

GPUArray[array]

yields an array stored in memory accessible for GPU-accelerated computation.

Details

  • GPUArray provides an efficient representation for storing and manipulating data accessible from a graphics processor unit (GPU).
  • GPUArray is typically used to enhance speed of execution of functions by running computations on the GPU.
  • GPUArray[array] creates an array in GPU memory or unified memory.
  • The array can have the following forms:
  • {e1,},{{e1,},},full array of numeric elements
    NumericArray[]numeric array of a specified type
  • Normal[GPUArray[array]] converts the GPUArray object to an ordinary list of values.
  • Additional conversions include:
  • SparseArray[GPUArray[]]sparse array with few nonzero elements
    NumericArray[GPUArray[],type]numeric array of a specified type
  • Information for a GPUArray includes the following properties:
  • "ElementType"element native type
    "Dimensions"list of the dimensions
  • Functions such as LinearSolve, Plus and Part work on GPUArray by running the computation on the GPU.
  • GPUArray is treated as a raw object by functions like AtomQ and for purposes of pattern matching.

Examples

open allclose all

Basic Examples  (1)

Create a GPUArray object from a vector:

Compute the cosine:

Converts to an ordinary list of values:

Scope  (27)

Basic Uses  (4)

Create a GPUArray object from a vector:

From a matrix:

Use NumericArray to create a GPUArray object of a specified type:

64-bit integers:

Convert a GPUArray object to an ordinary list of values:

Convert to a NumericArray object:

Convert to a SparseArray:

Get information of a GPUArray object:

Dimensions:

Type of elements:

Arrays Operations  (3)

Test whether a GPUArray object is a vector:

A matrix:

Extract parts of a GPUArray object:

Get properties of a GPUArray object:

Dimensions:

Depth:

Byte count:

Mathematical Operations  (6)

Apply arithmetic operations on GPUArray objects:

Addition:

Multiplication:

Power:

Evaluate numerically trigonometric functions:

Sine:

Cosine:

Arc cosine:

Compute transcendental functions:

Exp:

Log:

Power:

Evaluate efficiently hyperbolic functions:

Sinh:

Cosh:

Inverse cosine:

Evaluate numerically integer functions:

Ceiling:

Floor:

Round:

Compute absolute values and signs functions:

Abs:

Sign:

Absolute value of the real:

Fourier Analysis  (2)

Find a discrete Fourier transform:

Inverse Fourier transform of a complex list:

Statistics  (3)

Evaluate statistics functions on a GPUArray object:

Mean:

Geometric mean:

Variance:

Standard deviation:

Skewness:

Minimum of a GPUArray object:

Maximum:

Minimum and maximum:

Sort a GPUArray object:

Linear Algebra  (4)

Apply matrix operations on GPUArray objects:

Dot product:

Transpose:

Trace:

Solve a matrix-vector equation:

A matrix equation:

Solve a matrix-vector least-squares problem:

Solve a matrix-matrix least-squares problem:

Compute the singular value decomposition of a complex-valued matrix:

Up to expected precision loss, m=u.sigma.TemplateBox[{v}, ConjugateTranspose]:

Random Number Generation  (2)

Switch to the GPU random number generator:

Random numbers are now generated using it:

Random integers:

Random complexes:

A specific seed will affect the current GPU random number generator:

Visualization  (3)

Plot a list of values from a continuous probability distribution:

Plot an array of numbers:

Plot a matrix as an array of colors:

Properties & Relations  (4)

Use GPUArrayQ to test whether an object is a valid GPUArray object:

Find the number of bytes used to store a GPUArray object:

Use Normal to retrieve data from GPU:

GPUArray preserves representation types of elements in NumericArray objects:

Element type:

Possible Issues  (2)

GPUArray autoevaluates if no supported GPUs were detected:

Operations without GPU-accelerated support fall back to CPU implementations:

Wolfram Research (2025), GPUArray, Wolfram Language function, https://reference.wolfram.com/language/ref/GPUArray.html.

Text

Wolfram Research (2025), GPUArray, Wolfram Language function, https://reference.wolfram.com/language/ref/GPUArray.html.

CMS

Wolfram Language. 2025. "GPUArray." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/GPUArray.html.

APA

Wolfram Language. (2025). GPUArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GPUArray.html

BibTeX

@misc{reference.wolfram_2024_gpuarray, author="Wolfram Research", title="{GPUArray}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/GPUArray.html}", note=[Accessed: 15-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_gpuarray, organization={Wolfram Research}, title={GPUArray}, year={2025}, url={https://reference.wolfram.com/language/ref/GPUArray.html}, note=[Accessed: 15-January-2025 ]}