pub struct Context { /* private fields */ }Expand description
A stateful cuSPARSE handle.
Use one context per host thread or concurrent task. The handle is movable
between threads, but it is intentionally not Clone or Sync.
Implementations§
Source§impl Context
impl Context
Sourcepub fn create(cuda_ctx: &Arc<CudaContext>) -> Result<Self>
pub fn create(cuda_ctx: &Arc<CudaContext>) -> Result<Self>
Initializes the cuSPARSE library and creates a cuSPARSE handle. The handle must be created before using other cuSPARSE operations through this wrapper. It allocates hardware resources needed to access the GPU.
§Errors
Returns an error if the CUDA context cannot be bound, if cuSPARSE cannot create a handle, or if cuSPARSE returns a null handle.
Sourcepub unsafe fn from_raw(
handle: cusparseHandle_t,
cuda_ctx: Arc<CudaContext>,
) -> Result<Self>
pub unsafe fn from_raw( handle: cusparseHandle_t, cuda_ctx: Arc<CudaContext>, ) -> Result<Self>
Wraps an existing cuSPARSE handle and takes ownership of it.
§Safety
handle must be a valid cuSPARSE handle associated with cuda_ctx.
Ownership of handle is transferred to the returned context, and the
handle must not be destroyed elsewhere after calling this function.
Sourcepub fn cuda_context(&self) -> &Arc<CudaContext>
pub fn cuda_context(&self) -> &Arc<CudaContext>
Returns the underlying CUDA context used by this cuSPARSE handle.
Sourcepub fn bind(&self) -> Result<()>
pub fn bind(&self) -> Result<()>
Binds the underlying CUDA context associated with this handle.
§Errors
Returns an error if the CUDA context cannot be bound.
Sourcepub fn ensure_stream(&self, stream: &Stream) -> Result<()>
pub fn ensure_stream(&self, stream: &Stream) -> Result<()>
Ensures stream belongs to the same CUDA context as this handle.
Returns an error if the stream belongs to a different context.
Sourcepub fn version(&self) -> Result<i32>
pub fn version(&self) -> Result<i32>
Returns the version number of the cuSPARSE library.
§Errors
Returns an error if the CUDA context cannot be bound or if cuSPARSE cannot report the version for this handle.
Sourcepub fn stream(&self) -> Result<StreamBinding>
pub fn stream(&self) -> Result<StreamBinding>
Returns the stream used for cuSPARSE operations on this handle. If no explicit stream has been set, cuSPARSE uses the CUDA default stream.
§Errors
Returns an error if the CUDA context cannot be bound or if cuSPARSE cannot report the current stream.
Sourcepub fn set_stream(&self, stream: Option<&Stream>) -> Result<()>
pub fn set_stream(&self, stream: Option<&Stream>) -> Result<()>
Sets the stream used by cuSPARSE operations on this handle.
§Errors
Returns an error if stream belongs to another CUDA context, if the CUDA
context cannot be bound, or if cuSPARSE rejects the stream.
Sourcepub fn scalar_pointer_mode(&self) -> Result<PointerMode>
pub fn scalar_pointer_mode(&self) -> Result<PointerMode>
Returns the context-global scalar pointer mode used by cuSPARSE operations on this handle.
See PointerMode for scalar pointer semantics.
§Errors
Returns an error if the CUDA context cannot be bound or if cuSPARSE cannot report the pointer mode.
Sourcepub fn set_scalar_pointer_mode(&self, mode: PointerMode) -> Result<()>
pub fn set_scalar_pointer_mode(&self, mode: PointerMode) -> Result<()>
Sets the context-global scalar pointer mode used by cuSPARSE operations on this handle.
The default mode reads scalar values from host memory.
See PointerMode for scalar pointer semantics.
§Errors
Returns an error if the CUDA context cannot be bound or if cuSPARSE rejects the pointer mode.
Sourcepub unsafe fn set_logger_callback(
callback: cusparseLoggerCallback_t,
) -> Result<()>
pub unsafe fn set_logger_callback( callback: cusparseLoggerCallback_t, ) -> Result<()>
Sourcepub fn set_logger_level(level: i32) -> Result<()>
pub fn set_logger_level(level: i32) -> Result<()>
Experimental: sets the logging level.
§Errors
Returns an error if cuSPARSE rejects the logging level.
Sourcepub fn set_logger_mask(mask: i32) -> Result<()>
pub fn set_logger_mask(mask: i32) -> Result<()>
Sourcepub fn set_logger_path(path: impl AsRef<Path>) -> Result<()>
pub fn set_logger_path(path: impl AsRef<Path>) -> Result<()>
Experimental: sets the logging output file by path.
§Errors
Returns an error if path cannot be converted to a C string or if
cuSPARSE cannot open the log file.
Sourcepub fn disable_logger() -> Result<()>
pub fn disable_logger() -> Result<()>
Sourcepub fn as_raw(&self) -> cusparseHandle_t
pub fn as_raw(&self) -> cusparseHandle_t
Returns the raw cuSPARSE handle.
The returned handle is borrowed and remains valid only while this context and its underlying CUDA context are alive.
Sourcepub fn into_raw(self) -> cusparseHandle_t
pub fn into_raw(self) -> cusparseHandle_t
Consumes the context and returns the raw cuSPARSE handle without destroying it.
The caller becomes responsible for eventually destroying the returned handle with cuSPARSE.