pub struct BatchedSpMV<T: GpuFloat> { /* private fields */ }Expand description
Batched sparse matrix-vector multiplication.
Computes y_i = alpha * A_i * x_i + beta * y_i for a batch of sparse
matrices A_i, dense vectors x_i, and output vectors y_i.
The baseline implementation iterates sequentially on the host. For GPU
execution, use generate_batched_spmv_ptx to create a single fused
kernel that processes all matrices via offset arrays.
Implementations§
Source§impl<T: GpuFloat + Add<Output = T> + Mul<Output = T> + AddAssign> BatchedSpMV<T>
impl<T: GpuFloat + Add<Output = T> + Mul<Output = T> + AddAssign> BatchedSpMV<T>
Sourcepub fn from_device(matrices: &[CsrMatrix<T>]) -> SparseResult<Self>
pub fn from_device(matrices: &[CsrMatrix<T>]) -> SparseResult<Self>
Create a BatchedSpMV by downloading matrix data from device memory.
§Errors
Returns SparseError::InvalidArgument if matrices is empty.
Returns SparseError::Cuda on download failure.
Sourcepub fn from_host(
row_ptrs: Vec<Vec<i32>>,
col_indices: Vec<Vec<i32>>,
values: Vec<Vec<T>>,
rows: Vec<usize>,
cols: Vec<usize>,
) -> SparseResult<Self>
pub fn from_host( row_ptrs: Vec<Vec<i32>>, col_indices: Vec<Vec<i32>>, values: Vec<Vec<T>>, rows: Vec<usize>, cols: Vec<usize>, ) -> SparseResult<Self>
Create a BatchedSpMV from host-side CSR arrays.
§Errors
Returns SparseError::InvalidArgument on dimension mismatch.
Sourcepub fn batch_size(&self) -> usize
pub fn batch_size(&self) -> usize
Returns the number of matrices in the batch.
Sourcepub fn execute(
&self,
xs: &[Vec<T>],
ys: &mut [Vec<T>],
alpha: T,
beta: T,
) -> SparseResult<()>
pub fn execute( &self, xs: &[Vec<T>], ys: &mut [Vec<T>], alpha: T, beta: T, ) -> SparseResult<()>
Execute the batched SpMV on the host (sequential baseline).
For each matrix A_i:
y_i[r] = alpha * sum(A_i[r,c] * x_i[c]) + beta * y_i[r]
§Arguments
xs– Slice of input vectors, one per matrix.ys– Slice of output vectors, one per matrix (modified in place).alpha– Scalar multiplier forA * x.beta– Scalar multiplier for existingy.
§Errors
Returns SparseError::DimensionMismatch if slice lengths do not match
the batch size, or if individual vector dimensions are wrong.