Skip to main content

Session

Struct Session 

Source
pub struct Session<'s> { /* private fields */ }
Expand description

Public CubeCL extension session.

Not constructible by users; obtained only from CudaExecSession::with_cubecl. The session borrows the exact tenferro CubeCL client for the request scope and is !Send + !Sync by construction, so the execution authority cannot migrate to another thread.

Implementations§

Source§

impl<'s> Session<'s>

Source

pub fn client(&self) -> &ComputeClient<CubeclCudaRuntime>

Borrow the tenferro CubeCL client.

Source

pub fn tensor_binding<T>( &self, tensor: &TypedTensor<T, impl TensorRank>, op: &'static str, ) -> Result<TensorBinding<CubeclCudaRuntime>>
where T: CubeElement + TensorScalar + Clone,

Build a CubeCL tensor binding for a GPU-backed tensor.

§Errors

Returns crate::Error::RuntimeState when the tensor is not resident on this session’s runtime/device, or crate::Error::Validation when its layout cannot be bound.

Source

pub fn array_arg<T>( &self, tensor: &TypedTensor<T, impl TensorRank>, op: &'static str, ) -> Result<ArrayArg<CubeclCudaRuntime>>
where T: CubeElement + TensorScalar + Clone,

Build a CubeCL array argument for a GPU-backed tensor.

§Errors

Returns crate::Error::RuntimeState when the tensor is not resident on this session’s runtime/device, or crate::Error::Validation when its layout cannot be bound.

Source

pub fn alloc_output<T>(&self, shape: &[usize]) -> Result<TypedTensor<T>>
where T: CubeElement + TensorScalar + Clone + Send + Sync + 'static,

Allocate a dense GPU tensor on the session’s device.

§Errors

Returns crate::Error::Validation when the shape product overflows, or crate::Error::BackendSource when allocation fails.

Source

pub fn alloc_zero_output<T>(&self, shape: &[usize]) -> Result<TypedTensor<T>>
where T: CubeElement + CubePrimitive + TensorScalar + Clone + Send + Sync + 'static,

Allocate a dense GPU tensor zero-filled with the session’s device.

Reuses the backend’s fill-zero structural kernel; it never uploads a host tensor or exposes a device pointer to the caller.

§Errors

Returns crate::Error::Validation when the shape product, output byte length, or launch count overflows, crate::Error::RuntimeState when the output is not resident, or crate::Error::BackendSource when allocation or backend resource inspection fails.

§Examples
use tenferro_gpu::cuda::cubecl::Session;

fn check(session: &Session<'_>) -> tenferro_tensor::Result<()> {
    let _ = session.alloc_zero_output::<f32>(&[4])?;
    Ok(())
}
Source

pub fn scale_tensor_write( &self, output: TensorWrite<'_>, factor: f64, ) -> Result<()>

Scale a mutable CUDA tensor in place by a real factor.

Supports F32, F64, C32, and C64 payloads; the factor is interpreted as a real scalar for complex payloads. This is the op-family scale primitive used for normalization after a vendor transform; it never exposes a device pointer to the caller.

§Errors

Returns crate::Error::RuntimeState when the tensor is not resident on this session’s runtime, a typed layout error for a non-zero-offset discontinuous view, or the typed unsupported-dtype error for other payloads.

Source

pub fn cube_count_1d(&self, len: usize) -> Result<CubeCount>

Return the cube count for a one-dimensional kernel domain of len.

§Errors

Returns crate::Error::Validation carrying ValidationError::InvalidArgument when the one-dimensional launch for len elements would require more than u32::MAX workgroups.

Source

pub fn cube_dim_1d(&self) -> CubeDim

Return the standard one-dimensional CubeCL launch dimension.

Auto Trait Implementations§

§

impl<'s> !RefUnwindSafe for Session<'s>

§

impl<'s> !Send for Session<'s>

§

impl<'s> !Sync for Session<'s>

§

impl<'s> !UnwindSafe for Session<'s>

§

impl<'s> Freeze for Session<'s>

§

impl<'s> Unpin for Session<'s>

§

impl<'s> UnsafeUnpin for Session<'s>

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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

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

§

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

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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.

§

impl<T> IntoComptime for T

§

fn comptime(self) -> Self

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>