parallel.gpu.RandStream
Random number stream on a GPU
Description
Use parallel.gpu.RandStream to control the global GPU random
number stream and create multiple independent streams on the GPU. When you generate random
numbers on a GPU, the numbers are drawn from the GPU random number stream. This stream is
different from the random stream of the client MATLAB® session on the CPU.
To create random numbers on the GPU, use the random number generator functions rand, randi, and randn. If you use a GPU random number stream, then the results are returned as a
gpuArray. By default, these functions draw numbers from the global GPU
random number stream. To use a different stream, follow the syntaxes described in Object Functions.
Creation
Use the following syntaxes to create a single parallel.gpu.RandStream
object. If you want to create multiple independent streams simultaneously, use the parallel.gpu.RandStream.create function.
Description
s = parallel.gpu.RandStream( creates
a random number stream that uses the uniform pseudorandom number generator algorithm
specified by gentype)gentype.
s = parallel.gpu.RandStream(
specifies options using one or more name-value arguments in addition to the generator
algorithm argument. For example, to seed the random number generator based on the current
time, set gentype,Name=Value)Seed to "shuffle".
Input Arguments
Name-Value Arguments
Properties
Object Functions
parallel.gpu.RandStream.create | Create independent random number streams on a GPU |
parallel.gpu.RandStream.list | List random number generator algorithms on the GPU |
parallel.gpu.RandStream.getGlobalStream | Get current global GPU random number stream |
parallel.gpu.RandStream.setGlobalStream | Set GPU global random number stream |
reset (RandStream) | Reset random number stream |
By default, when you create random numbers on the GPU using random number generation
functions, such as rand, the random numbers are drawn from the
global random number stream on the GPU. To specify a different stream, create a
parallel.gpu.RandStream object and pass it as the first input argument. For
instance, create a 4-by-1 vector of random numbers using the Philox 4x32 generator
algorithm.
s = parallel.gpu.RandStream("Philox");
r = rand(s,4,1);These functions accept a parallel.gpu.RandStream object and generate
random numbers on the GPU:
rand | Uniformly distributed random numbers | Supported syntaxes, where X = rand(s) X = rand(s,n) X = rand(s,sz1,...,szN) X = rand(s,sz) X = rand(s,typename) rand, randi, and randn. |
randi | Uniformly distributed pseudorandom integers | |
randn | Normally distributed random numbers | |
randperm | Random permutation of integers | Supported syntaxes, where p = randperm(s,n) p = randperm(s,n,k) randperm. |
Examples
Extended Capabilities
Version History
Introduced in R2011b