User`s guide
9 GPU Computing
9-4
Transfer Array of a Specified Precision
Create a matrix of double-precision random values in MATLAB, and then transfer the
matrix as single-precision from MATLAB to the GPU:
X = rand(1000);
G = gpuArray(single(X));
Construct an Array for Storing on the GPU
Construct a 100-by-100 matrix of uint32 ones and transfer it to the GPU. You can
accomplish this with a single line of code:
G = gpuArray(ones(100,'uint32'));
Create GPU Arrays Directly
A number of methods on the gpuArray class allow you to directly construct arrays
on the GPU without having to transfer arrays from the MATLAB workspace. These
constructors require only array size and data class information, so they can construct
an array without any elements from the workspace. Use any of the following to directly
create an array on the GPU:
eye(___,'gpuArray') rand(___,'gpuArray')
false(___,'gpuArray') randi(___,'gpuArray')
Inf(___,'gpuArray') randn(___,'gpuArray')
NaN(___,'gpuArray') gpuArray.freqspace
ones(___,'gpuArray') gpuArray.linspace
true(___,'gpuArray') gpuArray.logspace
zeros(___,'gpuArray') gpuArray.colon
For a complete list of available static methods in any release, type
methods('gpuArray')
The constructors appear at the bottom of the output from this command.
For help on any one of the constructors, type
help gpuArray/functionname