Skip to main content

UnifiedTensor

Struct UnifiedTensor 

Source
pub struct UnifiedTensor {
    pub shape: Vec<usize>,
    pub dtype: DType,
    /* private fields */
}
Expand description

A dense, row-major tensor stored in a GPU buffer.

Cloning is cheap: clones and reshaped views share the buffer.

Fields§

§shape: Vec<usize>

Dimensions, outermost first.

§dtype: DType

Element type of the buffer.

Implementations§

Source§

impl UnifiedTensor

Source

pub fn buffer(&self) -> &Buffer

The underlying GPU buffer.

Source

pub fn size_in_bytes(&self) -> u64

Size of the tensor’s data in bytes.

Source

pub fn write_data(&self, context: &WgpuContext, data: &[u8])

Uploads data to the start of the buffer.

Source§

impl UnifiedTensor

Source

pub fn new(context: &WgpuContext, data: &[f32], shape: &[usize]) -> Self

Uploads data as an f32 tensor of the given shape.

Source

pub fn empty(context: &WgpuContext, shape: &[usize]) -> Self

An uninitialised f32 tensor drawn from the context’s buffer pool.

Source

pub fn empty_with_dtype( context: &WgpuContext, shape: &[usize], dtype: DType, ) -> Self

An uninitialised tensor of dtype drawn from the buffer pool.

Source

pub fn zeros(context: &WgpuContext, shape: &[usize]) -> Self

A zero-filled f32 tensor.

Source

pub fn from_bytes(context: &WgpuContext, data: &[u8], shape: &[usize]) -> Self

Uploads raw bytes as an f32-typed tensor (e.g. packed quantised data).

Source

pub fn from_bytes_with_dtype( context: &WgpuContext, data: &[u8], shape: &[usize], dtype: DType, ) -> Self

Uploads raw bytes as a tensor of dtype.

Source

pub fn empty_fp16(context: &WgpuContext, shape: &[usize]) -> Self

Create an FP16 tensor (half precision for memory savings)

Source

pub fn reshaped(&self, new_shape: &[usize]) -> Self

Create a new tensor view with different shape but sharing the same underlying data

Source

pub async fn to_vec(&self, context: &WgpuContext) -> Vec<f32>

Copies the tensor back to the CPU, waiting for queued GPU work.

Trait Implementations§

Source§

impl Clone for UnifiedTensor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnifiedTensor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,