Skip to main content

Context

Struct Context 

Source
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

Source

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.

Source

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.

Source

pub fn cuda_context(&self) -> &Arc<CudaContext>

Returns the underlying CUDA context used by this cuSPARSE handle.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub unsafe fn set_logger_callback( callback: cusparseLoggerCallback_t, ) -> Result<()>

Experimental: sets the logging callback function.

The callback must use the cuSPARSE logger callback ABI.

§Safety

callback, if present, must remain valid for use by cuSPARSE and must follow the callback ABI expected by the library.

§Errors

Returns an error if cuSPARSE rejects the callback.

Source

pub fn set_logger_level(level: i32) -> Result<()>

Experimental: sets the logging level.

§Errors

Returns an error if cuSPARSE rejects the logging level.

Source

pub fn set_logger_mask(mask: i32) -> Result<()>

Experimental: sets the logging mask.

§Errors

Returns an error if cuSPARSE rejects the logging mask.

Source

pub unsafe fn set_logger_file(file: *mut FILE) -> Result<()>

Experimental: sets the logging output file. Once registered, the provided file handle must remain open until another file handle is registered.

§Safety

file must be a valid FILE handle for as long as cuSPARSE may write to it.

§Errors

Returns an error if cuSPARSE rejects the file handle.

Source

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.

Source

pub fn disable_logger() -> Result<()>

Disables cuSPARSE logging.

§Errors

Returns an error if cuSPARSE cannot disable logging.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.