Table of Contents

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 : IDisposable

Inheritance

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

rngType CuRandRngType

The random number generator algorithm.

seed ulong

Seed value for the generator.

stream CudaStream?

Optional CUDA stream; a private stream is created if null.

Properties

IsQuasiRandom

true for quasirandom (Sobol) generators.

public bool IsQuasiRandom { get; }

Property Value

bool

RngType

The generator algorithm this instance was created with.

public CuRandRngType RngType { get; }

Property Value

CuRandRngType

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

buffer DeviceBuffer<float>
mean float
stddev float

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

buffer DeviceBuffer<double>
mean double
stddev double

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

buffer DeviceBuffer<float>
mean float
stddev float

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

buffer DeviceBuffer<double>
mean double
stddev double

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

buffer DeviceBuffer<float>
mean float
stddev float
ct CancellationToken

Returns

Task

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

buffer DeviceBuffer<double>
mean double
stddev double
ct CancellationToken

Returns

Task

FillPoisson(DeviceBuffer<uint>, double)

Fills the buffer with Poisson-distributed integers with the given mean.

public void FillPoisson(DeviceBuffer<uint> buffer, double lambda)

Parameters

buffer DeviceBuffer<uint>

Output buffer.

lambda double

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

buffer DeviceBuffer<uint>
lambda double
ct CancellationToken

Returns

Task

FillUInt32(DeviceBuffer<uint>)

Fills the buffer with uniformly distributed 32-bit unsigned integers.

public void FillUInt32(DeviceBuffer<uint> buffer)

Parameters

buffer DeviceBuffer<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

buffer DeviceBuffer<uint>
ct CancellationToken

Returns

Task

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

buffer DeviceBuffer<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

buffer DeviceBuffer<ulong>
ct CancellationToken

Returns

Task

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

buffer DeviceBuffer<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

buffer DeviceBuffer<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

buffer DeviceBuffer<float>
ct CancellationToken

Returns

Task

FillUniformAsync(DeviceBuffer<double>, CancellationToken)

Fills the device buffer with uniformly distributed values and synchronises.

public Task FillUniformAsync(DeviceBuffer<double> buffer, CancellationToken ct = default)

Parameters

buffer DeviceBuffer<double>
ct CancellationToken

Returns

Task

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

offset ulong

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

dimensions uint

SetSeed(ulong)

Sets the seed for the pseudorandom generator.

public void SetSeed(ulong seed)

Parameters

seed ulong