Struct cudarc::curand::safe::CudaRng

source ·
pub struct CudaRng { /* private fields */ }
Expand description

Host side RNG that can fill CudaSlice with random values.

  1. Create:
let device = CudaDevice::new(0).unwrap();
let rng = CudaRng::new(0, device).unwrap();
  1. Fill device memory:
let mut a_dev = device.alloc_zeros::<f32>(10).unwrap();
rng.fill_with_uniform(&mut a_dev).unwrap();

The three distributions are:

  1. Uniform - CudaRng::fill_with_uniform()
  2. Normal - CudaRng::fill_with_normal()
  3. LogNormal - CudaRng::fill_with_log_normal()

Implementations§

source§

impl CudaRng

source

pub fn new(seed: u64, device: Arc<CudaDevice>) -> Result<Self, CurandError>

Constructs the RNG with the given seed. Requires the stream from CudaDevice to submit kernels.

source

pub fn set_seed(&mut self, seed: u64) -> Result<(), CurandError>

Re-seed the RNG.

source

pub fn fill_with_uniform<T>( &self, t: &mut CudaSlice<T> ) -> Result<(), CurandError>where curandGenerator_t: UniformFill<T>,

Fill the CudaSlice with data from a Uniform distribution

source

pub fn fill_with_normal<T>( &self, t: &mut CudaSlice<T>, mean: T, std: T ) -> Result<(), CurandError>where curandGenerator_t: NormalFill<T>,

Fill the CudaSlice with data from a Normal(mean, std) distribution.

source

pub fn fill_with_log_normal<T>( &self, t: &mut CudaSlice<T>, mean: T, std: T ) -> Result<(), CurandError>where curandGenerator_t: LogNormalFill<T>,

Fill the CudaRc with data from a LogNormal(mean, std) distribution.

Trait Implementations§

source§

impl Drop for CudaRng

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.