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: DTypeElement type of the buffer.
Implementations§
Source§impl UnifiedTensor
impl UnifiedTensor
Sourcepub fn size_in_bytes(&self) -> u64
pub fn size_in_bytes(&self) -> u64
Size of the tensor’s data in bytes.
Sourcepub fn write_data(&self, context: &WgpuContext, data: &[u8])
pub fn write_data(&self, context: &WgpuContext, data: &[u8])
Uploads data to the start of the buffer.
Source§impl UnifiedTensor
impl UnifiedTensor
Sourcepub fn new(context: &WgpuContext, data: &[f32], shape: &[usize]) -> Self
pub fn new(context: &WgpuContext, data: &[f32], shape: &[usize]) -> Self
Uploads data as an f32 tensor of the given shape.
Sourcepub fn empty(context: &WgpuContext, shape: &[usize]) -> Self
pub fn empty(context: &WgpuContext, shape: &[usize]) -> Self
An uninitialised f32 tensor drawn from the context’s buffer pool.
Sourcepub fn empty_with_dtype(
context: &WgpuContext,
shape: &[usize],
dtype: DType,
) -> Self
pub fn empty_with_dtype( context: &WgpuContext, shape: &[usize], dtype: DType, ) -> Self
An uninitialised tensor of dtype drawn from the buffer pool.
Sourcepub fn zeros(context: &WgpuContext, shape: &[usize]) -> Self
pub fn zeros(context: &WgpuContext, shape: &[usize]) -> Self
A zero-filled f32 tensor.
Sourcepub fn from_bytes(context: &WgpuContext, data: &[u8], shape: &[usize]) -> Self
pub fn from_bytes(context: &WgpuContext, data: &[u8], shape: &[usize]) -> Self
Uploads raw bytes as an f32-typed tensor (e.g. packed quantised data).
Sourcepub fn from_bytes_with_dtype(
context: &WgpuContext,
data: &[u8],
shape: &[usize],
dtype: DType,
) -> Self
pub fn from_bytes_with_dtype( context: &WgpuContext, data: &[u8], shape: &[usize], dtype: DType, ) -> Self
Uploads raw bytes as a tensor of dtype.
Sourcepub fn empty_fp16(context: &WgpuContext, shape: &[usize]) -> Self
pub fn empty_fp16(context: &WgpuContext, shape: &[usize]) -> Self
Create an FP16 tensor (half precision for memory savings)
Sourcepub fn reshaped(&self, new_shape: &[usize]) -> Self
pub fn reshaped(&self, new_shape: &[usize]) -> Self
Create a new tensor view with different shape but sharing the same underlying data
Sourcepub async fn to_vec(&self, context: &WgpuContext) -> Vec<f32>
pub async fn to_vec(&self, context: &WgpuContext) -> Vec<f32>
Copies the tensor back to the CPU, waiting for queued GPU work.