pub struct CudaBackend;Expand description
Re-export CUDA backend (requires cuda feature + NVIDIA CUDA Toolkit).
The CUDA GPU backend. This is a zero-sized marker type.
Trait Implementations§
Source§impl Backend for CudaBackend
impl Backend for CudaBackend
Source§type Device = CudaDevice
type Device = CudaDevice
The device type for this backend.
Source§type Storage = CudaStorage
type Storage = CudaStorage
The storage type for this backend.
Source§fn zeros(
shape: &Shape,
dtype: DType,
device: &CudaDevice,
) -> Result<CudaStorage, Error>
fn zeros( shape: &Shape, dtype: DType, device: &CudaDevice, ) -> Result<CudaStorage, Error>
Allocate storage filled with zeros.
Source§fn ones(
shape: &Shape,
dtype: DType,
device: &CudaDevice,
) -> Result<CudaStorage, Error>
fn ones( shape: &Shape, dtype: DType, device: &CudaDevice, ) -> Result<CudaStorage, Error>
Allocate storage filled with ones.
Source§fn full(
shape: &Shape,
val: f64,
dtype: DType,
device: &CudaDevice,
) -> Result<CudaStorage, Error>
fn full( shape: &Shape, val: f64, dtype: DType, device: &CudaDevice, ) -> Result<CudaStorage, Error>
Allocate storage filled with a constant value.
Source§fn from_f64_slice(
data: &[f64],
dtype: DType,
device: &CudaDevice,
) -> Result<CudaStorage, Error>
fn from_f64_slice( data: &[f64], dtype: DType, device: &CudaDevice, ) -> Result<CudaStorage, Error>
Create storage from a flat f64 slice, converting to the target dtype.
Source§fn rand_uniform(
shape: &Shape,
dtype: DType,
device: &CudaDevice,
) -> Result<CudaStorage, Error>
fn rand_uniform( shape: &Shape, dtype: DType, device: &CudaDevice, ) -> Result<CudaStorage, Error>
Create storage with random uniform values in [0, 1).
Source§fn rand_normal(
shape: &Shape,
dtype: DType,
device: &CudaDevice,
) -> Result<CudaStorage, Error>
fn rand_normal( shape: &Shape, dtype: DType, device: &CudaDevice, ) -> Result<CudaStorage, Error>
Create storage with random normal values (mean=0, std=1).
Source§fn binary_op(
op: BinaryOp,
lhs: &CudaStorage,
lhs_layout: &Layout,
rhs: &CudaStorage,
rhs_layout: &Layout,
) -> Result<CudaStorage, Error>
fn binary_op( op: BinaryOp, lhs: &CudaStorage, lhs_layout: &Layout, rhs: &CudaStorage, rhs_layout: &Layout, ) -> Result<CudaStorage, Error>
Apply a binary op element-wise: result[i] = op(lhs[i], rhs[i]).
The layouts handle broadcasting and non-contiguous access.
Source§fn unary_op(
op: UnaryOp,
input: &CudaStorage,
layout: &Layout,
) -> Result<CudaStorage, Error>
fn unary_op( op: UnaryOp, input: &CudaStorage, layout: &Layout, ) -> Result<CudaStorage, Error>
Apply a unary op element-wise: result[i] = op(input[i]).
Source§fn reduce_op(
op: ReduceOp,
input: &CudaStorage,
layout: &Layout,
dims: &[usize],
_keep_dim: bool,
) -> Result<CudaStorage, Error>
fn reduce_op( op: ReduceOp, input: &CudaStorage, layout: &Layout, dims: &[usize], _keep_dim: bool, ) -> Result<CudaStorage, Error>
Reduce along specific dimensions.
If
dims is empty, reduce over all elements.Source§fn matmul(
lhs: &CudaStorage,
lhs_layout: &Layout,
rhs: &CudaStorage,
rhs_layout: &Layout,
) -> Result<CudaStorage, Error>
fn matmul( lhs: &CudaStorage, lhs_layout: &Layout, rhs: &CudaStorage, rhs_layout: &Layout, ) -> Result<CudaStorage, Error>
General matrix multiply: C = A @ B.
Supports batched matmul for tensors with rank > 2.
Source§fn to_contiguous(
input: &CudaStorage,
layout: &Layout,
) -> Result<CudaStorage, Error>
fn to_contiguous( input: &CudaStorage, layout: &Layout, ) -> Result<CudaStorage, Error>
Make a contiguous copy of the storage following the given layout.
If the layout is already contiguous, this may just clone the storage.
Source§fn to_f64_vec(input: &CudaStorage, layout: &Layout) -> Result<Vec<f64>, Error>
fn to_f64_vec(input: &CudaStorage, layout: &Layout) -> Result<Vec<f64>, Error>
Copy data from this storage to a Vec on the host (for inspection).
Source§fn cmp_op(
op: CmpOp,
lhs: &CudaStorage,
lhs_layout: &Layout,
rhs: &CudaStorage,
rhs_layout: &Layout,
) -> Result<CudaStorage, Error>
fn cmp_op( op: CmpOp, lhs: &CudaStorage, lhs_layout: &Layout, rhs: &CudaStorage, rhs_layout: &Layout, ) -> Result<CudaStorage, Error>
Element-wise comparison, returns a u8 storage (0 or 1).
Source§fn affine(
input: &CudaStorage,
layout: &Layout,
mul: f64,
add: f64,
) -> Result<CudaStorage, Error>
fn affine( input: &CudaStorage, layout: &Layout, mul: f64, add: f64, ) -> Result<CudaStorage, Error>
Affine transform: result = input * mul + add.
Used for normalization and other fused operations.
Source§fn index_select(
input: &CudaStorage,
input_layout: &Layout,
indices: &CudaStorage,
indices_layout: &Layout,
dim: usize,
) -> Result<CudaStorage, Error>
fn index_select( input: &CudaStorage, input_layout: &Layout, indices: &CudaStorage, indices_layout: &Layout, dim: usize, ) -> Result<CudaStorage, Error>
Gather elements along a dimension using index tensor.
Source§fn powf(
input: &CudaStorage,
layout: &Layout,
exponent: f64,
) -> Result<CudaStorage, Error>
fn powf( input: &CudaStorage, layout: &Layout, exponent: f64, ) -> Result<CudaStorage, Error>
Element-wise power: result[i] = input[i] ^ exponent.
Source§fn clamp(
input: &CudaStorage,
layout: &Layout,
min: f64,
max: f64,
) -> Result<CudaStorage, Error>
fn clamp( input: &CudaStorage, layout: &Layout, min: f64, max: f64, ) -> Result<CudaStorage, Error>
Element-wise clamp: result[i] = clamp(input[i], min, max).
Source§fn where_cond(
mask: &CudaStorage,
mask_layout: &Layout,
on_true: &CudaStorage,
on_true_layout: &Layout,
on_false: &CudaStorage,
on_false_layout: &Layout,
) -> Result<CudaStorage, Error>
fn where_cond( mask: &CudaStorage, mask_layout: &Layout, on_true: &CudaStorage, on_true_layout: &Layout, on_false: &CudaStorage, on_false_layout: &Layout, ) -> Result<CudaStorage, Error>
Element-wise conditional: result[i] = if mask[i] != 0 { on_true[i] } else { on_false[i] }.
Source§fn gather(
input: &CudaStorage,
input_layout: &Layout,
index: &CudaStorage,
index_layout: &Layout,
dim: usize,
) -> Result<CudaStorage, Error>
fn gather( input: &CudaStorage, input_layout: &Layout, index: &CudaStorage, index_layout: &Layout, dim: usize, ) -> Result<CudaStorage, Error>
Source§fn cat(
inputs: &[(&CudaStorage, &Layout)],
out_shape: &Shape,
dim: usize,
) -> Result<CudaStorage, Error>
fn cat( inputs: &[(&CudaStorage, &Layout)], out_shape: &Shape, dim: usize, ) -> Result<CudaStorage, Error>
Concatenate multiple storages along
dim into a single contiguous storage.
Each entry is (storage, layout) so non-contiguous inputs are handled correctly.
out_shape is the pre-validated output shape.Source§fn cast(
input: &CudaStorage,
layout: &Layout,
dtype: DType,
device: &CudaDevice,
) -> Result<CudaStorage, Error>
fn cast( input: &CudaStorage, layout: &Layout, dtype: DType, device: &CudaDevice, ) -> Result<CudaStorage, Error>
Cast storage to a different dtype on-device (no host round-trip). Read more
Source§impl Clone for CudaBackend
impl Clone for CudaBackend
Source§fn clone(&self) -> CudaBackend
fn clone(&self) -> CudaBackend
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CudaBackend
impl RefUnwindSafe for CudaBackend
impl Send for CudaBackend
impl Sync for CudaBackend
impl Unpin for CudaBackend
impl UnwindSafe for CudaBackend
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