Struct Transfer

Source
pub struct Transfer<'a> { /* private fields */ }
Expand description

Transfer can be used to create a request for data transfer from MCL.

Implementations§

Source§

impl<'a> Transfer<'a>

Source

pub fn arg(self, arg: TaskArg<'a>) -> Self

Adds an argument to be transferred by this request

Returns the Transfer object

§Examples
     let mcl = mcl_rs::MclEnvBuilder::new().initialize();
     mcl.load_prog("my_prog",mcl_rs::PrgType::Src);
     
     let data = vec![0; 4];

     let tr = mcl.transfer(1, 1)
                 .arg(mcl_rs::TaskArg::input_slice(&data));
Source

pub fn dev(self, d_type: DevType) -> Self

Sets the desired device type

§Arguments
  • d_type - The device type to transfer to

Returns the Transfer with the preference set

§Examples
     let mcl = mcl_rs::MclEnvBuilder::new().initialize();
     mcl.load_prog("my_prog",mcl_rs::PrgType::Src);

     let data = vec![0; 4];

     let tr = mcl.transfer(1, 1)
                 .arg(mcl_rs::TaskArg::input_slice(&data))
                 .dev(mcl_rs::DevType::CPU);
Source

pub async fn exec(self)

Submit the transfer request This is an asynchronous operation, meaning that no work is actually performed until the returned future is actually awaited. While awaiting a transfer execution, the user application will not make forward progress until the underylying device has executed the transfer. Upon return from the await call, any data is gauranteed to be written to its approriate buffer.

Transfer execution order can be enforced by sequentially awaiting tasks, or may be executed simultaneously using data structures such as Join_all https://docs.rs/futures/latest/futures/future/fn.join_all.html

§Examples
     let mcl = mcl_rs::MclEnvBuilder::new().initialize();
     mcl.load_prog("my_prog",mcl_rs::PrgType::Src);

     let data = vec![0; 4];

     let t_hdl = mcl.transfer(1, 1)
                 .arg(mcl_rs::TaskArg::input_slice(&data))
                 .dev(mcl_rs::DevType::CPU)
                 .exec();
     futures::executor::block_on(t_hdl);
     let mcl = mcl_rs::MclEnvBuilder::new().num_workers(10).initialize();
     mcl.load_prog("my_path", mcl_rs::PrgType::Src);
     let data = vec![0; 4];
     let pes: [u64; 3] = [1, 1, 1];
     let t1 =mcl.transfer(1, 1)
                 .arg(mcl_rs::TaskArg::input_slice(&data))
                 .dev(mcl_rs::DevType::CPU)
                 .exec(); //this creates a future we need to await
     let t2 = mcl.transfer(1, 1)
                 .arg(mcl_rs::TaskArg::input_slice(&data))
                 .dev(mcl_rs::DevType::CPU)
                 .exec(); //this creates a future we need to await
     let sequential_tasks = async move{
         t1.await; //task will execute before task 2 is even submitted
         t2.await;
     };
     futures::executor::block_on(sequential_tasks);
     
     let t3 = mcl.transfer(1, 1)
                 .arg(mcl_rs::TaskArg::input_slice(&data))
                 .dev(mcl_rs::DevType::CPU)
                 .exec(); //this creates a future we need to await
     let t4 = mcl.transfer(1, 1)
                 .arg(mcl_rs::TaskArg::input_slice(&data))
                 .dev(mcl_rs::DevType::CPU)
                 .exec(); //this creates a future we need to await
     let simultaneous_tasks = futures::future::join_all([t3,t4]);
     futures::executor::block_on(simultaneous_tasks); //both tasks submitted "simultaneously"

Trait Implementations§

Source§

impl Drop for Transfer<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Transfer<'a>

§

impl<'a> RefUnwindSafe for Transfer<'a>

§

impl<'a> !Send for Transfer<'a>

§

impl<'a> !Sync for Transfer<'a>

§

impl<'a> Unpin for Transfer<'a>

§

impl<'a> UnwindSafe for Transfer<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.