pub struct GpuNdarray<T: GpuScalar> { /* private fields */ }Expand description
A GPU-backed n-dimensional array backed by a real wgpu Buffer.
Created via GpuNdarray::from_ndarray_data or GpuNdarray::from_data.
Converted back with GpuNdarray::to_ndarray.
Implementations§
Source§impl<T: GpuScalar> GpuNdarray<T>
impl<T: GpuScalar> GpuNdarray<T>
Sourcepub fn buffer_arc(&self) -> &Arc<Buffer> ⓘ
pub fn buffer_arc(&self) -> &Arc<Buffer> ⓘ
Expose the underlying Arc<wgpu::Buffer> for zero-copy checks in tests.
Source§impl GpuNdarray<f32>
impl GpuNdarray<f32>
Sourcepub fn from_ndarray_data(
data: &[f32],
shape: Vec<usize>,
context: Arc<WebGPUContext>,
) -> Result<Self, GpuError>
pub fn from_ndarray_data( data: &[f32], shape: Vec<usize>, context: Arc<WebGPUContext>, ) -> Result<Self, GpuError>
Upload a CPU NdarrayWrapper<f32, _> to the GPU.
Returns Err(GpuError) if no adapter is available or upload fails.
Sourcepub fn from_data(data: &[f32], shape: Vec<usize>) -> Result<Self, GpuError>
pub fn from_data(data: &[f32], shape: Vec<usize>) -> Result<Self, GpuError>
Construct from a WebGPUContext, uploading data.
Uses the process-wide singleton WebGPUContext so that all arrays
created via this function share the same wgpu::Device and can be
combined freely in kernel dispatches.
Sourcepub fn add(&self, other: &GpuNdarray<f32>) -> Result<GpuNdarray<f32>, GpuError>
pub fn add(&self, other: &GpuNdarray<f32>) -> Result<GpuNdarray<f32>, GpuError>
Elementwise add: self + other. Both must have the same shape.
Sourcepub fn subtract(
&self,
other: &GpuNdarray<f32>,
) -> Result<GpuNdarray<f32>, GpuError>
pub fn subtract( &self, other: &GpuNdarray<f32>, ) -> Result<GpuNdarray<f32>, GpuError>
Elementwise subtract: self - other. Both must have the same shape.
Sourcepub fn multiply(
&self,
other: &GpuNdarray<f32>,
) -> Result<GpuNdarray<f32>, GpuError>
pub fn multiply( &self, other: &GpuNdarray<f32>, ) -> Result<GpuNdarray<f32>, GpuError>
Elementwise multiply: self * other. Both must have the same shape.
Sourcepub fn multiply_by_scalar_f32(
&self,
scalar: f32,
) -> Result<GpuNdarray<f32>, GpuError>
pub fn multiply_by_scalar_f32( &self, scalar: f32, ) -> Result<GpuNdarray<f32>, GpuError>
Multiply every element by a scalar: self * scalar.
Sourcepub fn sum_all(&self) -> Result<f32, GpuError>
pub fn sum_all(&self) -> Result<f32, GpuError>
Compute the sum of all elements (dot product via a.multiply(b)?.sum_all()).
Sourcepub fn dot_gpu(&self, other: &GpuNdarray<f32>) -> Result<f32, GpuError>
pub fn dot_gpu(&self, other: &GpuNdarray<f32>) -> Result<f32, GpuError>
Compute the dot product self · other = sum(self * other).
Sourcepub fn matmul(
&self,
other: &GpuNdarray<f32>,
) -> Result<GpuNdarray<f32>, GpuError>
pub fn matmul( &self, other: &GpuNdarray<f32>, ) -> Result<GpuNdarray<f32>, GpuError>
Tiled 16x16 matrix multiplication: self x other.
Both arrays must be 2-D. For a matrix-vector product, upload the vector as a [n, 1] column; the result will have shape [m, 1].
Trait Implementations§
Source§impl ArrayProtocol for GpuNdarray<f32>
impl ArrayProtocol for GpuNdarray<f32>
Source§fn array_function(
&self,
func: &ArrayFunction,
_types: &[TypeId],
args: &[Box<dyn Any>],
kwargs: &HashMap<String, Box<dyn Any>>,
) -> Result<Box<dyn Any>, NotImplemented>
fn array_function( &self, func: &ArrayFunction, _types: &[TypeId], args: &[Box<dyn Any>], kwargs: &HashMap<String, Box<dyn Any>>, ) -> Result<Box<dyn Any>, NotImplemented>
Source§fn shape(&self) -> &[usize]
fn shape(&self) -> &[usize]
Source§fn box_clone(&self) -> Box<dyn ArrayProtocol>
fn box_clone(&self) -> Box<dyn ArrayProtocol>
Source§impl<T: GpuScalar> Clone for GpuNdarray<T>
impl<T: GpuScalar> Clone for GpuNdarray<T>
Source§impl<T: GpuScalar> Debug for GpuNdarray<T>
impl<T: GpuScalar> Debug for GpuNdarray<T>
Source§impl GPUArray for GpuNdarray<f32>
impl GPUArray for GpuNdarray<f32>
Source§fn to_cpu(&self) -> CoreResult<Box<dyn ArrayProtocol>>
fn to_cpu(&self) -> CoreResult<Box<dyn ArrayProtocol>>
Auto Trait Implementations§
impl<T> Freeze for GpuNdarray<T>
impl<T> !RefUnwindSafe for GpuNdarray<T>
impl<T> Send for GpuNdarray<T>
impl<T> Sync for GpuNdarray<T>
impl<T> Unpin for GpuNdarray<T>where
T: Unpin,
impl<T> UnsafeUnpin for GpuNdarray<T>
impl<T> !UnwindSafe for GpuNdarray<T>
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.