pub struct SharedTensor<T> { /* private fields */ }
Expand description

Container that handles synchronization of [Memory][1] of type T. [1]: ../memory/index.html

Implementations§

source§

impl<T> SharedTensor<T>

source

pub fn new<D: IntoTensorDesc>(desc: &D) -> SharedTensor<T>

Create new Tensor by allocating [Memory][1] on a Device. [1]: ../memory/index.html

source

pub fn reshape<D: IntoTensorDesc>(&mut self, desc: &D) -> Result<(), Error>

Change the shape of the Tensor.

Will return an Error if size of new shape is not equal to the old shape. If you want to change the shape to one of a different size, use resize.

source

pub fn resize<D: IntoTensorDesc>(&mut self, desc: &D) -> Result<(), Error>

Change the size and shape of the Tensor.

Caution: Drops all copies which are not on the current device.

‘reshape’ is preffered over this method if the size of the old and new shape are identical because it will not reallocate memory.

source

pub fn read<'a, D: IDevice>(&'a self, device: &D) -> Result<&'a D::M, Error>

Get memory for reading on the specified device. Can fail if memory allocation fails, or if tensor wasn’t initialized yet.

source

pub fn read_write<'a, D: IDevice>( &'a mut self, device: &D ) -> Result<&'a mut D::M, Error>

Get memory for reading and writing on the specified device. Can fail if memory allocation fails, or if tensor wasn’t initialized yet.

source

pub fn write_only<'a, D: IDevice>( &'a mut self, device: &D ) -> Result<&'a mut D::M, Error>

Get memory for writing only. This function skips synchronization and initialization checks, since contents will be overwritten anyway. By convention caller must fully initialize returned memory. Failure to do so may result in use of uninitialized data later. If caller has failed to overwrite memory, for some reason, it must call invalidate() to return vector to uninitialized state.

source

pub fn drop<D: IDevice>(&mut self, device: &D) -> Result<(), Error>

Drops memory allocation on the specified device. Returns error if no memory has been allocated on this device.

source

pub fn capacity(&self) -> usize

Returns the number of elements for which the Tensor has been allocated.

source

pub fn desc(&self) -> &TensorDesc

Returns the descriptor of the Tensor.

source

pub fn mem_size(capacity: usize) -> usize

Returns the allocated Memory size in bytes.

Trait Implementations§

source§

impl<T> Debug for SharedTensor<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SharedTensor<T>

§

impl<T> !Send for SharedTensor<T>

§

impl<T> !Sync for SharedTensor<T>

§

impl<T> Unpin for SharedTensor<T>
where T: Unpin,

§

impl<T> !UnwindSafe for SharedTensor<T>

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>,

§

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>,

§

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.