pub struct TensorRef {
pub ptr: DevicePtr,
pub shape: Vec<usize>,
}Expand description
A reference to a device-side tensor: raw device pointer + concrete shape.
shape is always fully concrete (no None dims).
Fields§
§ptr: DevicePtrThe device pointer to this tensor’s data.
shape: Vec<usize>This tensor’s concrete shape.
Implementations§
Source§impl TensorRef
impl TensorRef
Sourcepub fn new(ptr: DevicePtr, shape: Vec<usize>) -> Self
pub fn new(ptr: DevicePtr, shape: Vec<usize>) -> Self
Wraps an existing device pointer and shape as a TensorRef.
Sourcepub fn n_elements(&self) -> usize
pub fn n_elements(&self) -> usize
Total number of elements (product of shape).
Sourcepub fn from_host_f32(data: &[f32], shape: Vec<usize>) -> Result<Self>
pub fn from_host_f32(data: &[f32], shape: Vec<usize>) -> Result<Self>
Allocate a device buffer, copy data to it, and return a TensorRef.
data.len() must equal shape.iter().product().
The caller owns the allocation; call TensorRef::free when done.
Sourcepub fn to_host_f32(&self) -> Result<Vec<f32>>
pub fn to_host_f32(&self) -> Result<Vec<f32>>
Copy the device buffer contents to a host Vec<f32>.
Sourcepub fn free(self) -> Result<()>
pub fn free(self) -> Result<()>
Free the underlying device buffer.
Only call this on TensorRefs that own their allocation (created via
TensorRef::from_host_f32 or TensorRef::new with a freshly
allocated pointer). Do not call this on refs borrowed from an
ActivationCache — the cache frees them on drop.