1use singe_cuda::data_type::DataTypeLike;
2
3use singe_cusparse_sys as sys;
4
5use crate::{
6 context::Context,
7 error::Result,
8 scalar::ScalarMut,
9 try_ffi,
10 types::Operation,
11 utility::to_usize,
12 vector::{DenseVectorDescriptor, SparseVectorDescriptor},
13};
14
15pub fn spvv_buffer_size<Compute: DataTypeLike>(
16 ctx: &Context,
17 operation_x: Operation,
18 x: &SparseVectorDescriptor,
19 y: &DenseVectorDescriptor,
20 result: &mut ScalarMut<'_, Compute>,
21) -> Result<usize> {
22 x.ensure_context(ctx)?;
23 y.ensure_context(ctx)?;
24 ctx.bind()?;
25 if ctx.scalar_pointer_mode()? != result.pointer_mode() {
26 ctx.set_scalar_pointer_mode(result.pointer_mode())?;
27 }
28
29 let mut size = 0;
30 unsafe {
31 try_ffi!(sys::cusparseSpVV_bufferSize(
32 ctx.as_raw(),
33 operation_x.into(),
34 x.as_raw_const(),
35 y.as_raw_const(),
36 result.as_mut_ptr().cast(),
37 Compute::data_type().into(),
38 &raw mut size,
39 ))?;
40 }
41 to_usize(size, "spvv buffer size")
42}