Skip to main content

GgmlContext

Struct GgmlContext 

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

A safe wrapper around ggml_context.

Implementations§

Source§

impl GgmlContext

Source

pub fn new(mem_size: usize, no_alloc: bool) -> Self

Create a new ggml context.

§Parameters
  • mem_size: Memory pool size in bytes for tensor metadata.
  • no_alloc: If true, tensor data is not allocated (use with backend allocation).
§Panics

Panics if ggml returns a null pointer.

Source

pub fn as_ptr(&self) -> *mut ggml_context

Get the raw context pointer.

Source

pub fn new_tensor_1d(&self, typ: ggml_type, ne0: i64) -> GgmlTensor

Create a 1D tensor.

Source

pub fn new_tensor_2d(&self, typ: ggml_type, ne0: i64, ne1: i64) -> GgmlTensor

Create a 2D tensor.

Source

pub fn new_tensor_3d( &self, typ: ggml_type, ne0: i64, ne1: i64, ne2: i64, ) -> GgmlTensor

Create a 3D tensor.

Source

pub fn new_tensor_4d( &self, typ: ggml_type, ne0: i64, ne1: i64, ne2: i64, ne3: i64, ) -> GgmlTensor

Create a 4D tensor.

Source

pub fn dup_tensor(&self, src: &GgmlTensor) -> GgmlTensor

Create a tensor with the same shape and type as another.

Source

pub fn new_tensor(&self, typ: ggml_type, ne: &[i64]) -> GgmlTensor

Create a new tensor with arbitrary dimensions.

Source

pub fn add(&self, a: &GgmlTensor, b: &GgmlTensor) -> GgmlTensor

Element-wise addition: a + b

Source

pub fn mul_mat(&self, a: &GgmlTensor, b: &GgmlTensor) -> GgmlTensor

Matrix multiplication: a @ b

Source

pub fn scale(&self, a: &GgmlTensor, s: f32) -> GgmlTensor

Scale tensor: a * s

Source

pub fn cast(&self, a: &GgmlTensor, typ: ggml_type) -> GgmlTensor

Cast tensor to a different type.

Source

pub fn cont(&self, a: &GgmlTensor) -> GgmlTensor

Make tensor contiguous in memory.

Source

pub fn transpose(&self, a: &GgmlTensor) -> GgmlTensor

Transpose a tensor.

Source

pub fn reshape_1d(&self, a: &GgmlTensor, ne0: i64) -> GgmlTensor

Reshape to 1D.

Source

pub fn reshape_2d(&self, a: &GgmlTensor, ne0: i64, ne1: i64) -> GgmlTensor

Reshape to 2D.

Source

pub fn view_1d(&self, a: &GgmlTensor, ne0: i64, offset: usize) -> GgmlTensor

Create a 1D view of a tensor.

Source

pub fn new_graph(&self) -> GgmlGraph

Create a new computation graph.

Source

pub fn first_tensor(&self) -> Option<GgmlTensor>

Get the first tensor in this context.

Source

pub fn next_tensor(&self, tensor: &GgmlTensor) -> Option<GgmlTensor>

Get the next tensor after tensor in this context.

Trait Implementations§

Source§

impl Debug for GgmlContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for GgmlContext

Source§

fn drop(&mut self)

Executes the destructor for this type. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more