Class CudaRandom
- Namespace
- NVMathNet.Rand
- Assembly
- NVMath.Net.dll
GPU random number generator backed by cuRAND. Wraps a cuRAND generator handle and provides methods to fill device buffers with random numbers.
public sealed class CudaRandom : IDisposableInheritance
Implements
Inherited Members
Constructors
CudaRandom(CuRandRngType, ulong, CudaStream?)
Creates a new GPU random number generator.
public CudaRandom(CuRandRngType rngType = CuRandRngType.PseudoDefault, ulong seed = 0, CudaStream? stream = null)Parameters
rngTypeCuRandRngType-
The random number generator algorithm.
seedulong-
Seed value for the generator.
streamCudaStream?-
Optional CUDA stream; a private stream is created if null.
Properties
IsQuasiRandom
true for quasirandom (Sobol) generators.
public bool IsQuasiRandom { get; }Property Value
RngType
The generator algorithm this instance was created with.
public CuRandRngType RngType { get; }Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()FillLogNormal(DeviceBuffer<float>, float, float)
Fills the device buffer with log-normally distributed single-precision floats. Count must be even for cuRAND.
public void FillLogNormal(DeviceBuffer<float> buffer, float mean = 0, float stddev = 1)Parameters
bufferDeviceBuffer<float>meanfloatstddevfloat
FillLogNormal(DeviceBuffer<double>, double, double)
Fills the device buffer with log-normally distributed double-precision floats.
public void FillLogNormal(DeviceBuffer<double> buffer, double mean = 0, double stddev = 1)Parameters
bufferDeviceBuffer<double>meandoublestddevdouble
FillNormal(DeviceBuffer<float>, float, float)
Fills the device buffer with normally distributed single-precision floats. Count must be even for cuRAND.
public void FillNormal(DeviceBuffer<float> buffer, float mean = 0, float stddev = 1)Parameters
bufferDeviceBuffer<float>meanfloatstddevfloat
FillNormal(DeviceBuffer<double>, double, double)
Fills the device buffer with normally distributed double-precision floats. Count must be even for cuRAND.
public void FillNormal(DeviceBuffer<double> buffer, double mean = 0, double stddev = 1)Parameters
bufferDeviceBuffer<double>meandoublestddevdouble
FillNormalAsync(DeviceBuffer<float>, float, float, CancellationToken)
Fills the device buffer with normally distributed values and synchronises.
public Task FillNormalAsync(DeviceBuffer<float> buffer, float mean = 0, float stddev = 1, CancellationToken ct = default)Parameters
bufferDeviceBuffer<float>meanfloatstddevfloatctCancellationToken
Returns
FillNormalAsync(DeviceBuffer<double>, double, double, CancellationToken)
Fills the device buffer with normally distributed values and synchronises.
public Task FillNormalAsync(DeviceBuffer<double> buffer, double mean = 0, double stddev = 1, CancellationToken ct = default)Parameters
bufferDeviceBuffer<double>meandoublestddevdoublectCancellationToken
Returns
FillPoisson(DeviceBuffer<uint>, double)
Fills the buffer with Poisson-distributed integers with the given mean.
public void FillPoisson(DeviceBuffer<uint> buffer, double lambda)Parameters
bufferDeviceBuffer<uint>-
Output buffer.
lambdadouble-
Mean of the distribution; must be positive, finite and at most 400000 (the cuRAND limit).
FillPoissonAsync(DeviceBuffer<uint>, double, CancellationToken)
Fills the buffer with Poisson-distributed integers and synchronises.
public Task FillPoissonAsync(DeviceBuffer<uint> buffer, double lambda, CancellationToken ct = default)Parameters
bufferDeviceBuffer<uint>lambdadoublectCancellationToken
Returns
FillUInt32(DeviceBuffer<uint>)
Fills the buffer with uniformly distributed 32-bit unsigned integers.
public void FillUInt32(DeviceBuffer<uint> buffer)Parameters
bufferDeviceBuffer<uint>
FillUInt32Async(DeviceBuffer<uint>, CancellationToken)
Fills the buffer with 32-bit unsigned integers and synchronises.
public Task FillUInt32Async(DeviceBuffer<uint> buffer, CancellationToken ct = default)Parameters
bufferDeviceBuffer<uint>ctCancellationToken
Returns
FillUInt64(DeviceBuffer<ulong>)
Fills the buffer with 64-bit unsigned integers. Only valid for the 64-bit quasirandom generators (NVMathNet.Interop.CuRandRngType.QuasiSobol64 and NVMathNet.Interop.CuRandRngType.QuasiScrambledSobol64).
public void FillUInt64(DeviceBuffer<ulong> buffer)Parameters
bufferDeviceBuffer<ulong>
FillUInt64Async(DeviceBuffer<ulong>, CancellationToken)
Fills the buffer with 64-bit unsigned integers and synchronises.
public Task FillUInt64Async(DeviceBuffer<ulong> buffer, CancellationToken ct = default)Parameters
bufferDeviceBuffer<ulong>ctCancellationToken
Returns
FillUniform(DeviceBuffer<float>)
Fills the device buffer with uniformly distributed single-precision floats in the range (0, 1].
public void FillUniform(DeviceBuffer<float> buffer)Parameters
bufferDeviceBuffer<float>
FillUniform(DeviceBuffer<double>)
Fills the device buffer with uniformly distributed double-precision floats in the range (0, 1].
public void FillUniform(DeviceBuffer<double> buffer)Parameters
bufferDeviceBuffer<double>
FillUniformAsync(DeviceBuffer<float>, CancellationToken)
Fills the device buffer with uniformly distributed values and synchronises.
public Task FillUniformAsync(DeviceBuffer<float> buffer, CancellationToken ct = default)Parameters
bufferDeviceBuffer<float>ctCancellationToken
Returns
FillUniformAsync(DeviceBuffer<double>, CancellationToken)
Fills the device buffer with uniformly distributed values and synchronises.
public Task FillUniformAsync(DeviceBuffer<double> buffer, CancellationToken ct = default)Parameters
bufferDeviceBuffer<double>ctCancellationToken
Returns
SetOffset(ulong)
Skips ahead in the sequence: the next values generated are those that would follow the
first offset values. Supported by the Philox, XORWOW, MRG32k3a and
Sobol generators; some generators round the offset to a multiple of their block size.
public void SetOffset(ulong offset)Parameters
offsetulong
SetQuasiRandomDimensions(uint)
Sets the number of dimensions of a quasirandom generator (1–20000). Successive values are interleaved across dimensions. Only valid for quasirandom generators.
public void SetQuasiRandomDimensions(uint dimensions)Parameters
dimensionsuint
SetSeed(ulong)
Sets the seed for the pseudorandom generator.
public void SetSeed(ulong seed)Parameters
seedulong