User`s guide
Run Element-wise MATLAB Code on GPU
9-17
for gpuArray” on page 9-5. For more information about generating random numbers
on a GPU, and a comparison between GPU and CPU generation, see “Control Random
Number Streams” on page 6-37. For an example that shows performance comparisons for
different random generators, see Generating Random Numbers on a GPU.
Tips and Restrictions
The following limitations apply to the code within the function that arrayfun or bsxfun
is evaluating on a GPU.
• Like arrayfun in MATLAB, matrix exponential power, multiplication, and division
(^, *, /, \) perform element-wise calculations only.
• Operations that change the size or shape of the input or output arrays (cat, reshape,
etc.), are not supported.
• When generating random matrices with rand, randi, or randn, you do not need to
specify the matrix size, and each element of the matrix has its own random stream.
See “Generate Random Numbers on a GPU” on page 9-16.
• arrayfun and bsxfun support read-only indexing (subsref) and access to variables
of the parent (outer) function workspace from within nested functions, i.e., those
variables that exist in the function before the arrayfun/bsxfun evaluation on
the GPU. Assignment or subsasgn indexing of these variables from within the
nested function is not supported. For an example of the supported usage see Stencil
Operations on a GPU
• Anonymous functions do not have access to their parent function workspace.
• Overloading the supported functions is not allowed.
• The code cannot call scripts.
• There is no ans variable to hold unassigned computation results. Make sure to
explicitly assign to variables the results of all calculations that you need to access.
• The following language features are not supported: persistent or global variables,
parfor, spmd, switch, and try/catch.
• P-code files cannot contain a call to arrayfun or bsxfun with gpuArray data.