Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

A stateful cuTENSOR 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 cuTENSOR library and allocates the memory for the library context.

The device associated with a particular cuTENSOR handle is assumed to remain unchanged after the Context::create call. To use a different device, make that device current through the CUDA wrapper crate and create a new cuTENSOR handle with Context::create.

Each handle has a plan cache that stores least-recently-used cuTENSOR plans. Its default capacity is 64, but it can be changed with Context::resize_plan_cache. See the Plan Cache Guide for more information.

The returned Context frees the cuTENSOR handle when dropped.

This blocking call is thread-safe but not reentrant.

§Errors

Returns an error if the CUDA context cannot be bound, if cuTENSOR cannot create a handle, or if cuTENSOR returns a null handle.

Source

pub unsafe fn from_raw( handle: cutensorHandle_t, cuda_ctx: Arc<CudaContext>, ) -> Result<Self>

Wraps an existing cuTENSOR handle and takes ownership of it.

§Safety

handle must be a valid cuTENSOR 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>

Source

pub fn bind(&self) -> Result<()>

Source

pub fn resize_plan_cache(&self, entry_count: usize) -> Result<()>

Resizes the plan cache.

Changes the number of plans that can be stored in the plan cache of the handle.

Resizing invalidates the cache.

The call is not thread-safe, but the resulting cache can be shared across threads safely.

This non-blocking call is neither reentrant nor thread-safe.

§Errors

Returns an error if the context cannot be bound, entry_count cannot be represented for cuTENSOR, or cuTENSOR rejects the new cache size.

Source

pub fn write_plan_cache_to_file(&self, path: impl AsRef<Path>) -> Result<()>

Writes the plan cache that belongs to this handle to file.

This non-blocking call is thread-safe but not reentrant.

§Errors

Returns an error if the context cannot be bound, path cannot be converted to a C string, no plan cache is attached, or cuTENSOR cannot write the file.

Source

pub fn read_plan_cache_from_file(&self, path: impl AsRef<Path>) -> Result<u32>

Reads a plan cache from file and overwrites this handle’s cache lines.

A cache is only valid for the same cuTENSOR version, CUDA version, and GPU architecture, including multiprocessor count.

This non-blocking call is thread-safe but not reentrant.

§Errors

Returns an error if the context cannot be bound, path cannot be converted to a C string, the file cannot be read, the stored cache is incompatible with this cuTENSOR/CUDA/device configuration, the current cache is too small for the stored data, or cuTENSOR rejects the cache.

Source

pub fn write_kernel_cache_to_file(&self, path: impl AsRef<Path>) -> Result<()>

Writes the per-library kernel cache to file.

Writes the just-in-time compiled kernels to the provided file. These kernels belong to the library, not to the handle.

This non-blocking call is thread-safe but not reentrant.

§Errors

Returns an error if the context cannot be bound, path cannot be converted to a C string, JIT kernel caching is unsupported for this operating system, CUDA Toolkit, or device, or cuTENSOR cannot write the file.

Source

pub fn read_kernel_cache_from_file(&self, path: impl AsRef<Path>) -> Result<()>

Reads a kernel cache from file and adds all non-existing JIT compiled kernels to the kernel cache.

A cache is only valid for the same cuTENSOR version, CUDA version, and GPU architecture, including multiprocessor count.

This non-blocking call is thread-safe but not reentrant.

§Errors

Returns an error if the context cannot be bound, path cannot be converted to a C string, the file cannot be read, the stored cache is incompatible with this cuTENSOR/CUDA/device configuration, JIT kernel caching is unsupported for this operating system, CUDA Toolkit, or device, or cuTENSOR rejects the cache.

Source

pub fn ensure_stream(&self, stream: &Stream) -> Result<()>

Source

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

Sets the logging callback.

§Safety

callback must remain valid for every later cuTENSOR log event that may call it and must follow cuTENSOR’s callback requirements.

§Errors

Returns an error if cuTENSOR rejects the callback.

Source

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

Sets the logging level.

§Errors

Returns an error if cuTENSOR rejects the logging level.

Source

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

Sets the log mask.

§Errors

Returns an error if cuTENSOR rejects the logging mask.

Source

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

Sets the logging output file.

§Safety

file must be a valid C FILE pointer for every later cuTENSOR log write that may use it, or a null pointer if cuTENSOR accepts that for the active logger configuration.

§Errors

Returns an error if cuTENSOR rejects the file pointer.

Source

pub fn set_logger_path(path: impl AsRef<Path>) -> Result<()>

Sets the logging output file by path.

§Errors

Returns an error if path cannot be converted to a C string or if cuTENSOR cannot open the log file.

Source

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

Disables logging for the entire run.

§Errors

Returns an error if cuTENSOR cannot disable logging.

Source

pub fn as_raw(&self) -> cutensorHandle_t

Returns the raw cuTENSOR 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) -> cutensorHandle_t

Consumes the context and returns the raw cuTENSOR handle without destroying it.

The caller becomes responsible for eventually destroying the returned handle with cuTENSOR.

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.