Random Number Generation

Classes for random number generation. augpy’s speciality is that all dtypes are supported for all distributions. For example, it is possible to fill an integer tensor with approximately Gaussian distributed numbers.

using augpy::rng_t = curandStateXORWOW_t
class augpy::RandomNumberGenerator

A convenient wrapper for cuRAND methods that fill tensors with pseudo-random numbers.

Public Functions

RandomNumberGenerator(py::object *device_id, py::object *seed)

Create a new RNG instance. device_id and seed may both be Python None. The behavior is identical to RandomNumberGenerator(int*, unsigned long long*) with NULL pointers.

RandomNumberGenerator(int *device_id, unsigned long long *seed)

Create a new RNG instance.

Parameters

void uniform(CudaTensor *target, double vmin, double vmax, unsigned int blocks_per_sm = BLOCKS_PER_SM, unsigned int num_threads = 0)

Fill target tensor with uniformly distributed numbers in \( [v_{min}, v_{max}) \).

Note

This is supported for integer tensors. Values are cast from float or double down to the integer type. The mean of the values is approximately \( \frac{v_{max} + v_{min}}{2} \).

Warning

Saturation is not used. \( v_{min} \) and \( v_{max} \) must be representable in the target tensor data type.

Parameters
  • target: tensor to fill

  • vmin: minimum value; can occur

  • vmax: maximum value; does not occur

  • blocks_per_sm: number of blocks per SM

  • num_threads: number of threads per block

    See Blocks and threads

void gaussian(CudaTensor *target, double mean, double std, unsigned int blocks_per_sm = BLOCKS_PER_SM, unsigned int num_threads = 0)

Fill target tensor with Gaussian distributed numbers with specified mean and standard deviation std.

Note

This is supported for integer tensors. Values are drawn from the given distribution, then rounded and cast to the data type of the tensor with saturation. The values in an integer tensor are thus only approximately Gaussian distributed.

Parameters
  • target: tensor to fill

  • mean: Gaussian mean

  • std: Gaussian standard deviation

  • blocks_per_sm: number of blocks per SM

  • num_threads: number of threads per block

    See Blocks and threads