Random Number Generation

MatX provides the capability to generate random numbers using the cuRAND library on tensor view objects using the APIs below.

template<typename T>
class matx::randomGenerator_t

Generates random numbers

Generate random numbers based on a size and seed. Uses the Philox 4x32 generator with 10 rounds.

tparam Type

of random number

Public Functions

inline randomGenerator_t(index_t total_threads, uint64_t seed)

Constructs a random number generator

This call will allocate memory sufficiently large enough to store state of the RNG

Parameters
  • total_threads – Number of random values to generate

  • seed – Seed for the RNG

template<int RANK>
inline auto GetTensorView(const tensorShape_t<RANK> shape, Distribution_t dist, T alpha = 1, T beta = 0)

Get a tensor view of the random numbers

Parameters
  • shape – Dimensions of the view in the form of an tensorShape_t

  • dist – Distribution to use

  • alpha – Alpha value

  • beta – Beta value

Returns

A randomTensorView_t with given parameters

template<int RANK>
inline auto GetTensorView(const index_t (&sizes)[RANK], Distribution_t dist, T alpha = 1, T beta = 0)

Get a tensor view of the random numbers

Parameters
  • sizes – Dimensions of the view in the form of an initializer list

  • dist – Distribution to use

  • alpha – Alpha value

  • beta – Beta value

Returns

A randomTensorView_t with given parameters

inline ~randomGenerator_t()

Destroy the RNG and free all memory

template<typename T, int RANK>
class matx::randomTensorView_t

Random number generator view

Provides a view into a previously-allocated randomGenerator_t

tparam Type

of random number

tparam Rank

of view

Public Functions

__MATX_DEVICE__ inline T operator()() const

Retrieve a value from a rank-0 random view

__MATX_DEVICE__ inline T operator()(index_t i) const

Retrieve a value from a rank-1 random view

Parameters

i – First index

__MATX_DEVICE__ inline T operator()(index_t i, index_t j) const

Retrieve a value from a rank-2 random view

Parameters
  • i – First index

  • j – Second index

__MATX_DEVICE__ inline T operator()(index_t i, index_t j, index_t k) const

Retrieve a value from a rank-3 random view

Parameters
  • i – First index

  • j – Second index

  • k – Third index

__MATX_DEVICE__ inline T operator()(index_t i, index_t j, index_t k, index_t l) const

Retrieve a value from a rank-4 random view

Parameters
  • i – First index

  • j – Second index

  • k – Third index

  • l – Fourth index