pub struct CudaTensor { /* private fields */ }Expand description
Tensor stored on CUDA device
Implementations§
Source§impl CudaTensor
impl CudaTensor
Sourcepub fn new(shape: &[usize], dtype: DType, device_id: i32) -> CudaResult<Self>
pub fn new(shape: &[usize], dtype: DType, device_id: i32) -> CudaResult<Self>
Create new CUDA tensor with given shape (uninitialized)
Sourcepub fn from_tensor(tensor: &Tensor, device_id: i32) -> CudaResult<Self>
pub fn from_tensor(tensor: &Tensor, device_id: i32) -> CudaResult<Self>
Create CUDA tensor from CPU tensor (copies data to GPU)
Sourcepub fn from_tensor_async(
tensor: &Tensor,
device_id: i32,
stream: &CudaStream,
) -> CudaResult<Self>
pub fn from_tensor_async( tensor: &Tensor, device_id: i32, stream: &CudaStream, ) -> CudaResult<Self>
Create CUDA tensor from CPU tensor (async copy)
Sourcepub fn to_tensor(&self) -> CudaResult<Tensor>
pub fn to_tensor(&self) -> CudaResult<Tensor>
Copy back to CPU tensor
Sourcepub fn to_tensor_async(&self, stream: &CudaStream) -> CudaResult<Vec<f32>>
pub fn to_tensor_async(&self, stream: &CudaStream) -> CudaResult<Vec<f32>>
Copy back to CPU tensor (async)
Sourcepub fn as_mut_ptr(&mut self) -> *mut f32
pub fn as_mut_ptr(&mut self) -> *mut f32
Get mutable raw buffer pointer
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Get buffer size in bytes
Sourcepub fn zeros(shape: &[usize], device_id: i32) -> CudaResult<Self>
pub fn zeros(shape: &[usize], device_id: i32) -> CudaResult<Self>
Create zeros tensor
Sourcepub fn ones(shape: &[usize], device_id: i32) -> CudaResult<Self>
pub fn ones(shape: &[usize], device_id: i32) -> CudaResult<Self>
Create ones tensor
Sourcepub fn full(shape: &[usize], value: f32, device_id: i32) -> CudaResult<Self>
pub fn full(shape: &[usize], value: f32, device_id: i32) -> CudaResult<Self>
Create tensor filled with value
Sourcepub fn reshape(&self, new_shape: &[usize]) -> CudaResult<Self>
pub fn reshape(&self, new_shape: &[usize]) -> CudaResult<Self>
Reshape tensor
Sourcepub fn transpose(&self, dim0: usize, dim1: usize) -> CudaResult<Self>
pub fn transpose(&self, dim0: usize, dim1: usize) -> CudaResult<Self>
Transpose dimensions
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Check if tensor is contiguous
Sourcepub fn clone_tensor(&self) -> CudaResult<Self>
pub fn clone_tensor(&self) -> CudaResult<Self>
Deep clone
Sourcepub fn add(&self, other: &CudaTensor) -> CudaResult<CudaTensor>
pub fn add(&self, other: &CudaTensor) -> CudaResult<CudaTensor>
Element-wise addition
Sourcepub fn sub(&self, other: &CudaTensor) -> CudaResult<CudaTensor>
pub fn sub(&self, other: &CudaTensor) -> CudaResult<CudaTensor>
Element-wise subtraction
Sourcepub fn mul_scalar(&self, scalar: f32) -> CudaResult<CudaTensor>
pub fn mul_scalar(&self, scalar: f32) -> CudaResult<CudaTensor>
Scalar multiplication
Sourcepub fn matmul(&self, other: &CudaTensor) -> CudaResult<CudaTensor>
pub fn matmul(&self, other: &CudaTensor) -> CudaResult<CudaTensor>
Matrix multiplication
Sourcepub fn dot(&self, other: &CudaTensor) -> CudaResult<f32>
pub fn dot(&self, other: &CudaTensor) -> CudaResult<f32>
Dot product
Sourcepub fn norm(&self) -> CudaResult<f32>
pub fn norm(&self) -> CudaResult<f32>
L2 norm
Sourcepub fn sum(&self) -> CudaResult<f32>
pub fn sum(&self) -> CudaResult<f32>
Sum all elements
Sourcepub fn mean(&self) -> CudaResult<f32>
pub fn mean(&self) -> CudaResult<f32>
Mean of all elements
Sourcepub fn max(&self) -> CudaResult<f32>
pub fn max(&self) -> CudaResult<f32>
Max element
Sourcepub fn min(&self) -> CudaResult<f32>
pub fn min(&self) -> CudaResult<f32>
Min element
Sourcepub fn relu(&self) -> CudaResult<CudaTensor>
pub fn relu(&self) -> CudaResult<CudaTensor>
ReLU activation (in-place capable)
Sourcepub fn sigmoid(&self) -> CudaResult<CudaTensor>
pub fn sigmoid(&self) -> CudaResult<CudaTensor>
Sigmoid activation
Sourcepub fn gelu(&self) -> CudaResult<CudaTensor>
pub fn gelu(&self) -> CudaResult<CudaTensor>
GELU activation
Sourcepub fn softmax(&self, dim: i32) -> CudaResult<CudaTensor>
pub fn softmax(&self, dim: i32) -> CudaResult<CudaTensor>
Softmax
Sourcepub fn exp(&self) -> CudaResult<CudaTensor>
pub fn exp(&self) -> CudaResult<CudaTensor>
Exponential
Sourcepub fn log(&self) -> CudaResult<CudaTensor>
pub fn log(&self) -> CudaResult<CudaTensor>
Natural logarithm
Sourcepub fn sqrt(&self) -> CudaResult<CudaTensor>
pub fn sqrt(&self) -> CudaResult<CudaTensor>
Square root
Sourcepub fn pow(&self, exp: f32) -> CudaResult<CudaTensor>
pub fn pow(&self, exp: f32) -> CudaResult<CudaTensor>
Power
Trait Implementations§
Source§impl Clone for CudaTensor
impl Clone for CudaTensor
Auto Trait Implementations§
impl Freeze for CudaTensor
impl RefUnwindSafe for CudaTensor
impl !Send for CudaTensor
impl !Sync for CudaTensor
impl Unpin for CudaTensor
impl UnwindSafe for CudaTensor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more