Struct coaster::tensor::SharedTensor
source · pub struct SharedTensor<T> { /* private fields */ }
Expand description
Container that handles synchronization of [Memory][1] of type T
.
[1]: ../memory/index.html
Implementations§
sourcepub fn new<D: IntoTensorDesc>(desc: &D) -> SharedTensor<T>
pub fn new<D: IntoTensorDesc>(desc: &D) -> SharedTensor<T>
Create new Tensor by allocating [Memory][1] on a Device. [1]: ../memory/index.html
sourcepub fn reshape<D: IntoTensorDesc>(&mut self, desc: &D) -> Result<(), Error>
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
.
sourcepub fn resize<D: IntoTensorDesc>(&mut self, desc: &D) -> Result<(), Error>
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.
sourcepub fn read<'a, D: IDevice>(&'a self, device: &D) -> Result<&'a D::M, Error>
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.
sourcepub fn read_write<'a, D: IDevice>(
&'a mut self,
device: &D
) -> Result<&'a mut D::M, Error>
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.
sourcepub fn write_only<'a, D: IDevice>(
&'a mut self,
device: &D
) -> Result<&'a mut D::M, Error>
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.
sourcepub fn drop<D: IDevice>(&mut self, device: &D) -> Result<(), Error>
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.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements for which the Tensor has been allocated.
sourcepub fn desc(&self) -> &TensorDesc
pub fn desc(&self) -> &TensorDesc
Returns the descriptor of the Tensor.