Skip to content

session πŸ”—

Interface to the struct vaccel_session C object.

BaseSession πŸ”—

BaseSession(flags: int = 0)

Bases: CType

Wrapper for the struct vaccel_session C object.

Manages the creation and initialization of a C struct vaccel_session and provides access to it through Python properties.

Inherits

CType: Abstract base class for defining C data types.

Parameters:

Name Type Description Default

flags πŸ”—

int

The flags to configure the session creation. Defaults to 0.

0
Source code in vaccel/session.py
def __init__(self, flags: int = 0):
    """Initializes a new `BaseSession` object.

    Args:
        flags: The flags to configure the session creation. Defaults to 0.
    """
    self._flags = flags
    super().__init__()

c_size property πŸ”—

c_size: int

Returns the size of the object in bytes.

flags property πŸ”—

flags: int

The session flags.

Returns:

Type Description
int

The flags set during session creation.

id property πŸ”—

id: int

The session identifier.

Returns:

Type Description
int

The session's unique ID.

remote_id property πŸ”—

remote_id: int

The remote session identifier.

Returns:

Type Description
int

The session's remote ID.

value property πŸ”—

value: CData

Returns the value of the underlying C struct.

Returns:

Type Description
CData

The dereferenced 'struct vaccel_session`

has_resource πŸ”—

has_resource(resource: Resource) -> bool

Check if a resource is registered with the session.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

The resource to check for registration.

required

Returns:

Type Description
bool

True if the resource is registered.

Source code in vaccel/session.py
def has_resource(self, resource: Resource) -> bool:
    """Check if a resource is registered with the session.

    Args:
        resource: The resource to check for registration.

    Returns:
        True if the resource is registered.
    """
    return (
        lib.vaccel_session_has_resource(
            self._c_obj, resource._get_inner_resource()
        )
        != 0
    )

Session πŸ”—

Session(flags: int = 0)

Bases: BaseSession, NoopMixin, GenopMixin, ExecMixin, ImageMixin, BlasMixin, FpgaMixin, MinmaxMixin, TFMixin, TFLiteMixin, TorchMixin

Extended session with operations' functionalities.

Inherits from BaseSession and the operation mixins, adding support for the operation functions.

Inherits

BaseSession: Core session management. NoopMixin: Debug operation. GenopMixin: Generic operation. ExecMixin: Exec operations. ImageMixin: Image-related operations. BlasMixin: BLAS operations. FpgaMixin: FPGA operations. MinmaxMixin: Minmax operations. TensorflowMixin: TensorFlow operations.

Parameters:

Name Type Description Default

flags πŸ”—

int

The flags to configure the session creation. Defaults to 0.

0
Source code in vaccel/session.py
def __init__(self, flags: int = 0):
    """Initializes a new `BaseSession` object.

    Args:
        flags: The flags to configure the session creation. Defaults to 0.
    """
    self._flags = flags
    super().__init__()

c_size property πŸ”—

c_size: int

Returns the size of the object in bytes.

flags property πŸ”—

flags: int

The session flags.

Returns:

Type Description
int

The flags set during session creation.

id property πŸ”—

id: int

The session identifier.

Returns:

Type Description
int

The session's unique ID.

remote_id property πŸ”—

remote_id: int

The remote session identifier.

Returns:

Type Description
int

The session's remote ID.

value property πŸ”—

value: CData

Returns the value of the underlying C struct.

Returns:

Type Description
CData

The dereferenced 'struct vaccel_session`

classify πŸ”—

classify(image: bytes) -> (str, str)

Performs the image classification operation.

Wraps the vaccel_image_classification() C operation.

Parameters:

Name Type Description Default

image πŸ”—

bytes

The image data as a bytes object.

required

Returns:

Type Description
(str, str)

A tuple containing: - The classification tag. - The resulting image filename.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/image.py
def classify(self, image: bytes) -> (str, str):
    """Performs the image classification operation.

    Wraps the `vaccel_image_classification()` C operation.

    Args:
        image: The image data as a `bytes` object.

    Returns:
        A tuple containing:
            - The classification tag.
            - The resulting image filename.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    img = CBytes(image)
    out_text = CBytes(bytearray(self._out_len))
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_classification(
        self._c_ptr,
        img._c_ptr,
        out_text._c_ptr,
        out_imgname._c_ptr,
        len(img),
        len(out_text),
        len(out_imgname),
    )
    if ret:
        raise FFIError(ret, "Image classification failed")

    return out_text.to_str(), out_imgname.to_str()

depth πŸ”—

depth(image: bytes) -> str

Performs the image depth estimation operation.

Wraps the vaccel_image_depth() C operation.

Parameters:

Name Type Description Default

image πŸ”—

bytes

The image data as a bytes object.

required

Returns:

Type Description
str

The resulting image filename.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/image.py
def depth(self, image: bytes) -> str:
    """Performs the image depth estimation operation.

    Wraps the `vaccel_image_depth()` C operation.

    Args:
        image: The image data as a `bytes` object.

    Returns:
        The resulting image filename.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_depth(
        self._c_ptr,
        img._c_ptr,
        out_imgname._c_ptr,
        len(img),
        len(out_imgname),
    )
    if ret:
        raise FFIError(ret, "Image depth estimation failed")

    return out_imgname.to_str()

detect πŸ”—

detect(image: bytes) -> str

Performs the image detection operation.

Wraps the vaccel_image_detection() C operation.

Parameters:

Name Type Description Default

image πŸ”—

bytes

The image data as a bytes object.

required

Returns:

Type Description
str

The resulting image filename.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/image.py
def detect(self, image: bytes) -> str:
    """Performs the image detection operation.

    Wraps the `vaccel_image_detection()` C operation.

    Args:
        image: The image data as a `bytes` object.

    Returns:
        The resulting image filename.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_detection(
        self._c_ptr,
        img._c_ptr,
        out_imgname._c_ptr,
        len(img),
        len(out_imgname),
    )
    if ret:
        raise FFIError(ret, "Image detection failed")

    return out_imgname.to_str()

exec πŸ”—

Performs the Exec operation.

Wraps the vaccel_exec() C operation.

Parameters:

Name Type Description Default

library πŸ”—

str | Path

The path to the shared object containing the function that will be called.

required

symbol πŸ”—

str

The name of the function contained in the above shared object.

required

arg_read πŸ”—

list[Any]

The input arguments that will be passed to the called function.

required

arg_write πŸ”—

list[Any]

The output arguments that will be passed to the called function.

required

Returns:

Type Description
list[Any]

The resulting outputs.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/exec.py
def exec(
    self,
    library: str | Path,
    symbol: str,
    arg_read: list[Any],
    arg_write: list[Any],
) -> list[Any]:
    """Performs the Exec operation.

    Wraps the `vaccel_exec()` C operation.

    Args:
        library: The path to the shared object containing the function that
            will be called.
        symbol: The name of the function contained in the above shared
            object.
        arg_read: The input arguments that will be passed to the
            called function.
        arg_write: The output arguments that will be passed to the
            called function.

    Returns:
        The resulting outputs.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    c_arg_read = CList([Arg(arg) for arg in arg_read])
    c_arg_write = CList([Arg(arg) for arg in arg_write])

    ret = lib.vaccel_exec(
        self._c_ptr,
        str(library).encode(),
        symbol.encode(),
        c_arg_read._c_ptr,
        len(c_arg_read),
        c_arg_write._c_ptr,
        len(c_arg_write),
    )
    if ret != 0:
        raise FFIError(ret, "Exec operation failed")

    return [c_arg_write[i].buf for i in range(len(c_arg_write))]

exec_with_resource πŸ”—

exec_with_resource(
    resource: Resource, symbol: str, arg_read: list[Any], arg_write: list[Any]
) -> list[Any]

Performs the Exec with resource operation.

Wraps the vaccel_exec_with_resource() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

The resource of the shared object containing the function that will be called.

required

symbol πŸ”—

str

The name of the function contained in the above shared object.

required

arg_read πŸ”—

list[Any]

The input arguments that will be passed to the called function.

required

arg_write πŸ”—

list[Any]

The output arguments that will be passed to the called function.

required

Returns:

Type Description
list[Any]

The resulting outputs.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/exec.py
def exec_with_resource(
    self,
    resource: Resource,
    symbol: str,
    arg_read: list[Any],
    arg_write: list[Any],
) -> list[Any]:
    """Performs the Exec with resource operation.

    Wraps the `vaccel_exec_with_resource()` C operation.

    Args:
        resource: The resource of the shared object containing the function
            that will be called.
        symbol: The name of the function contained in the above shared
            object.
        arg_read: The input arguments that will be passed to the
            called function.
        arg_write: The output arguments that will be passed to the
            called function.

    Returns:
        The resulting outputs.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    c_arg_read = CList([Arg(arg) for arg in arg_read])
    c_arg_write = CList([Arg(arg) for arg in arg_write])

    ret = lib.vaccel_exec_with_resource(
        self._c_ptr,
        resource._c_ptr,
        symbol.encode(),
        c_arg_read._c_ptr,
        len(c_arg_read),
        c_arg_write._c_ptr,
        len(c_arg_write),
    )
    if ret != 0:
        raise FFIError(ret, "Exec with resource operation failed")

    return [c_arg_write[i].buf for i in range(len(c_arg_write))]

fpga_arraycopy πŸ”—

fpga_arraycopy(a: list[int]) -> list[int]

Performs the matrix copying operation.

Wraps the vaccel_fpga_arraycopy() C operation.

Parameters:

Name Type Description Default

a πŸ”—

list[int]

The matrix A to be copied.

required

Returns:

Type Description
list[int]

A copy of the matrix A.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/fpga.py
def fpga_arraycopy(self, a: list[int]) -> list[int]:
    """Performs the matrix copying operation.

    Wraps the `vaccel_fpga_arraycopy()` C operation.

    Args:
        a: The matrix A to be copied.

    Returns:
        A copy of the matrix A.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    c_a = CList(a)
    c_out_a = CList([0] * len(a))

    ret = lib.vaccel_fpga_arraycopy(
        self._c_ptr, c_a._c_ptr, c_out_a._c_ptr, len(c_a)
    )
    if ret != 0:
        raise FFIError(ret, "FPGA array copy failed")

    return [int(item) for item in c_out_a.value]

fpga_mmult πŸ”—

fpga_mmult(a: list[float], b: list[float]) -> list[float]

Performs the matrix multiplication operation.

Wraps the vaccel_fpga_mmult() C operation.

Parameters:

Name Type Description Default

a πŸ”—

list[float]

A matrix A.

required

b πŸ”—

list[float]

A matrix B.

required

Returns:

Type Description
list[float]

The multiplication result of matrices A and B.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/fpga.py
def fpga_mmult(self, a: list[float], b: list[float]) -> list[float]:
    """Performs the matrix multiplication operation.

    Wraps the `vaccel_fpga_mmult()` C operation.

    Args:
        a: A matrix A.
        b: A matrix B.

    Returns:
        The multiplication result of matrices A and B.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    c_a = CList(a)
    c_b = CList(b)
    c_c = CList([float(0)] * len(a))

    ret = lib.vaccel_fpga_mmult(
        self._c_ptr, c_a._c_ptr, c_b._c_ptr, c_c._c_ptr, len(c_a)
    )
    if ret != 0:
        raise FFIError(ret, "FPGA matrix multiplication failed")

    return [float(item) for item in c_c.value]

fpga_parallel πŸ”—

fpga_parallel(a: list[float], b: list[float]) -> (list[float], list[float])

Performs the parallel matrix addition and multiplication operation.

Wraps the vaccel_fpga_parallel() C operation.

Parameters:

Name Type Description Default

a πŸ”—

list[float]

A matrix A.

required

b πŸ”—

list[float]

A matrix B.

required

Returns:

Type Description
(list[float], list[float])

A tuple containing: - The result of the addition of matrices A and B. - The result of the multiplication of matrices A and B.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/fpga.py
def fpga_parallel(
    self, a: list[float], b: list[float]
) -> (list[float], list[float]):
    """Performs the parallel matrix addition and multiplication operation.

    Wraps the `vaccel_fpga_parallel()` C operation.

    Args:
        a: A matrix A.
        b: A matrix B.

    Returns:
        A tuple containing:
            - The result of the addition of matrices A and B.
            - The result of the multiplication of matrices A and B.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    c_a = CList(a)
    c_b = CList(b)
    c_add_output = CList([float(0)] * len(a))
    c_mult_output = CList([float(0)] * len(a))

    ret = lib.vaccel_fpga_parallel(
        self._c_ptr,
        c_a._c_ptr,
        c_b._c_ptr,
        c_add_output._c_ptr,
        c_mult_output._c_ptr,
        len(c_a),
    )
    if ret != 0:
        raise FFIError(
            ret, "FPGA parallel matrix addition and multiplication failed"
        )

    return (
        [float(item) for item in c_add_output.value],
        [float(item) for item in c_mult_output.value],
    )

fpga_vadd πŸ”—

fpga_vadd(a: list[float], b: list[float]) -> list[float]

Performs the matrix addition operation.

Wraps the vaccel_fpga_vadd() C operation.

Parameters:

Name Type Description Default

a πŸ”—

list[float]

A matrix A.

required

b πŸ”—

list[float]

A matrix B.

required

Returns:

Type Description
list[float]

The addition result of matrices A and B.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/fpga.py
def fpga_vadd(self, a: list[float], b: list[float]) -> list[float]:
    """Performs the matrix addition operation.

    Wraps the `vaccel_fpga_vadd()` C operation.

    Args:
        a: A matrix A.
        b: A matrix B.

    Returns:
        The addition result of matrices A and B.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    c_a = CList(a)
    c_b = CList(b)
    c_c = CList([float(0)] * len(a))

    ret = lib.vaccel_fpga_vadd(
        self._c_ptr, c_a._c_ptr, c_b._c_ptr, c_c._c_ptr, len(c_a), len(c_b)
    )
    if ret != 0:
        raise FFIError(ret, "FPGA vector addition failed")

    return [float(item) for item in c_c.value]

genop πŸ”—

genop(arg_read: list[Arg], arg_write: list[Arg]) -> None

Performs the Generic operation.

Wraps the vaccel_genop() C operation.

Parameters:

Name Type Description Default

arg_read πŸ”—

list[Arg]

The input arguments of the operation.

required

arg_write πŸ”—

list[Arg]

The output arguments of the operation. Modified in place.

required

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/genop.py
def genop(self, arg_read: list[Arg], arg_write: list[Arg]) -> None:
    """Performs the Generic operation.

    Wraps the `vaccel_genop()` C operation.

    Args:
        arg_read: The input arguments of the operation.
        arg_write: The output arguments of the operation. Modified in place.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    c_args_read = CList(arg_read)
    c_args_write = CList(arg_write)

    ret = lib.vaccel_genop(
        self._c_ptr,
        c_args_read._c_ptr,
        len(c_args_read),
        c_args_write._c_ptr,
        len(c_args_write),
    )
    if ret:
        raise FFIError(ret, "Generic operation failed")

has_resource πŸ”—

has_resource(resource: Resource) -> bool

Check if a resource is registered with the session.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

The resource to check for registration.

required

Returns:

Type Description
bool

True if the resource is registered.

Source code in vaccel/session.py
def has_resource(self, resource: Resource) -> bool:
    """Check if a resource is registered with the session.

    Args:
        resource: The resource to check for registration.

    Returns:
        True if the resource is registered.
    """
    return (
        lib.vaccel_session_has_resource(
            self._c_obj, resource._get_inner_resource()
        )
        != 0
    )

minmax πŸ”—

Performs the minmax operation.

Wraps the vaccel_minmax() C operation.

Parameters:

Name Type Description Default

indata πŸ”—

bytes

The input data as a bytes object.

required

ndata πŸ”—

int

The number of data to be read provided data object.

required

low_threshold πŸ”—

int

The threshold for the min value.

required

high_threshold πŸ”—

int

The threshold for the max value.

required

Returns:

Type Description
(bytes, float, float)

A tuple containing: - The resulting output data. - The detected min value of the data. - The detected max value of the data.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/minmax.py
def minmax(
    self, indata: bytes, ndata: int, low_threshold: int, high_threshold: int
) -> (bytes, float, float):
    """Performs the minmax operation.

    Wraps the `vaccel_minmax()` C operation.

    Args:
        indata: The input data as a `bytes` object.
        ndata: The number of data to be read provided data object.
        low_threshold: The threshold for the min value.
        high_threshold: The threshold for the max value.

    Returns:
        A tuple containing:
            - The resulting output data.
            - The detected min value of the data.
            - The detected max value of the data.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    c_indata = CBytes(indata)
    c_outdata = CBytes(bytearray(ndata * ffi.sizeof("double")))
    c_min = CFloat(float(0), "double")
    c_max = CFloat(float(0), "double")

    ret = lib.vaccel_minmax(
        self._c_ptr,
        c_indata._as_c_array("double"),
        ndata,
        low_threshold,
        high_threshold,
        c_outdata._as_c_array("double"),
        c_min._c_ptr,
        c_max._c_ptr,
    )
    if ret != 0:
        raise FFIError(ret, "Minmax operation failed")

    return (c_outdata.value, c_min.value, c_max.value)

noop πŸ”—

noop() -> None

Performs the NoOp operation.

Wraps the vaccel_noop() C operation.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/noop.py
def noop(self) -> None:
    """Performs the NoOp operation.

    Wraps the `vaccel_noop()` C operation.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    ret = lib.vaccel_noop(self._c_ptr)
    if ret != 0:
        raise FFIError(ret, "NoOp operation failed")

pose πŸ”—

pose(image: bytes) -> str

Performs the image pose estimation operation.

Wraps the vaccel_image_pose() C operation.

Parameters:

Name Type Description Default

image πŸ”—

bytes

The image data as a bytes object.

required

Returns:

Type Description
str

The resulting image filename.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/image.py
def pose(self, image: bytes) -> str:
    """Performs the image pose estimation operation.

    Wraps the `vaccel_image_pose()` C operation.

    Args:
        image: The image data as a `bytes` object.

    Returns:
        The resulting image filename.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_pose(
        self._c_ptr,
        img._c_ptr,
        out_imgname._c_ptr,
        len(img),
        len(out_imgname),
    )
    if ret:
        raise FFIError(ret, "Image pose estimation failed")

    return out_imgname.to_str()

segment πŸ”—

segment(image: bytes) -> str

Performs the image segmentation operations.

Wraps the vaccel_image_segmentation() C operation.

Parameters:

Name Type Description Default

image πŸ”—

bytes

The image data as a bytes object.

required

Returns:

Type Description
str

The resulting image filename.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/image.py
def segment(self, image: bytes) -> str:
    """Performs the image segmentation operations.

    Wraps the `vaccel_image_segmentation()` C operation.

    Args:
        image: The image data as a `bytes` object.

    Returns:
        The resulting image filename.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_segmentation(
        self._c_ptr,
        img._c_ptr,
        out_imgname._c_ptr,
        len(img),
        len(out_imgname),
    )
    if ret:
        raise FFIError(ret, "Image segmentation failed")

    return out_imgname.to_str()

sgemm πŸ”—

sgemm(
    m: int,
    n: int,
    k: int,
    alpha: float,
    a: list[float],
    lda: int,
    b: list[float],
    ldb: int,
    beta: float,
    ldc: int,
) -> list[float]

Performs the SGEMM operation.

Wraps the vaccel_sgemm() C operation.

Parameters:

Name Type Description Default

m πŸ”—

int

The number of rows in matrix A and matrix C.

required

n πŸ”—

int

The number of columns in matrix B and matrix C.

required

k πŸ”—

int

The number of columns in matrix A and rows in matrix B.

required

alpha πŸ”—

float

Scalar multiplier for the matrix product A * B.

required

a πŸ”—

list[float]

The matrix A in row-major order with shape (m, k).

required

lda πŸ”—

int

The leading dimension of matrix A (usually m).

required

b πŸ”—

list[float]

The matrix B in row-major order with shape (k, n).

required

ldb πŸ”—

int

The leading dimension of matrix B (usually k).

required

beta πŸ”—

float

Scalar multiplier for matrix C.

required

ldc πŸ”—

int

The leading dimension of matrix C (usually m).

required

Returns:

Type Description
list[float]

The resulting matrix C in row-major order with shape (m, n).

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/blas.py
def sgemm(
    self,
    m: int,
    n: int,
    k: int,
    alpha: float,
    a: list[float],
    lda: int,
    b: list[float],
    ldb: int,
    beta: float,
    ldc: int,
) -> list[float]:
    """Performs the SGEMM operation.

    Wraps the `vaccel_sgemm()` C operation.

    Args:
        m: The number of rows in matrix A and matrix C.
        n: The number of columns in matrix B and matrix C.
        k: The number of columns in matrix A and rows in matrix B.
        alpha: Scalar multiplier for the matrix product A * B.
        a: The matrix A in row-major order with shape (m, k).
        lda: The leading dimension of matrix A (usually m).
        b: The matrix B in row-major order with shape (k, n).
        ldb: The leading dimension of matrix B (usually k).
        beta: Scalar multiplier for matrix C.
        ldc: The leading dimension of matrix C (usually m).

    Returns:
        The resulting matrix C in row-major order with shape (m, n).

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    c_a = CList(a)
    c_b = CList(b)
    c_c = CList([float(0)] * m * n)

    ret = lib.vaccel_sgemm(
        self._c_ptr,
        m,
        n,
        k,
        alpha,
        c_a._c_ptr,
        lda,
        c_b._c_ptr,
        ldb,
        beta,
        c_c._c_ptr,
        ldc,
    )
    if ret != 0:
        raise FFIError(ret, "SGEMM failed")

    return c_c.value

tf_model_delete πŸ”—

tf_model_delete(resource: Resource) -> Status

Performs the Tensorflow model deletion operation.

Wraps the vaccel_tf_session_delete() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

A resource with the model to unload.

required

Returns:

Type Description
Status

The status of the operation execution.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/tf.py
def tf_model_delete(self, resource: Resource) -> Status:
    """Performs the Tensorflow model deletion operation.

    Wraps the `vaccel_tf_session_delete()` C operation.

    Args:
        resource: A resource with the model to unload.

    Returns:
        The status of the operation execution.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    status = Status()
    ret = lib.vaccel_tf_session_delete(
        self._c_ptr, resource._c_ptr, status._c_ptr
    )
    if ret != 0:
        raise FFIError(ret, "Tensorflow model delete failed")
    return status

tf_model_load πŸ”—

tf_model_load(resource: Resource) -> Status

Performs the Tensorflow model loading operation.

Wraps the vaccel_tf_session_load() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

A resource with the model to load.

required

Returns:

Type Description
Status

The status of the operation execution.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/tf.py
def tf_model_load(self, resource: Resource) -> Status:
    """Performs the Tensorflow model loading operation.

    Wraps the `vaccel_tf_session_load()` C operation.

    Args:
        resource: A resource with the model to load.

    Returns:
        The status of the operation execution.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    status = Status()
    ret = lib.vaccel_tf_session_load(
        self._c_ptr, resource._c_ptr, status._c_ptr
    )
    if ret != 0:
        raise FFIError(ret, "Tensorflow model loading failed")
    return status

tf_model_run πŸ”—

Performs the Tensorflow model run operation.

Wraps the vaccel_tf_session_run() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

A resource with the model to run.

required

in_nodes πŸ”—

list[Node]

The input nodes for the inference.

required

in_tensors πŸ”—

list[Tensor]

The input tensors for the inference.

required

out_nodes πŸ”—

list[Node]

The output nodes for the inference.

required

run_options πŸ”—

Buffer | None

The inference options.

None

Returns:

Type Description
(list[Tensor], Status)

A tuple containing: - The output tensors - The status of the operation execution.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/tf.py
def tf_model_run(
    self,
    resource: Resource,
    in_nodes: list[Node],
    in_tensors: list[Tensor],
    out_nodes: list[Node],
    run_options: Buffer | None = None,
) -> (list[Tensor], Status):
    """Performs the Tensorflow model run operation.

    Wraps the `vaccel_tf_session_run()` C operation.

    Args:
        resource: A resource with the model to run.
        in_nodes: The input nodes for the inference.
        in_tensors: The input tensors for the inference.
        out_nodes: The output nodes for the inference.
        run_options: The inference options.

    Returns:
        A tuple containing:
            - The output tensors
            - The status of the operation execution.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    run_options_ptr = (
        ffi.NULL if run_options is None else run_options._c_ptr
    )
    c_in_nodes = CList(in_nodes)
    c_in_tensors = CList.from_ptrs(in_tensors)
    c_out_nodes = CList(out_nodes)
    c_out_tensors = CList.from_ptrs([Tensor.empty()] * len(c_out_nodes))
    status = Status()

    ret = lib.vaccel_tf_session_run(
        self._c_ptr,
        resource._c_ptr,
        run_options_ptr,
        c_in_nodes._c_ptr,
        c_in_tensors._c_ptr,
        len(c_in_nodes),
        c_out_nodes._c_ptr,
        c_out_tensors._c_ptr,
        len(c_out_nodes),
        status._c_ptr,
    )
    if ret != 0:
        raise FFIError(ret, "Tensorflow model run failed")

    out_tensors = [Tensor.from_c_obj(t) for t in c_out_tensors.value]
    return (out_tensors, status)

tflite_model_delete πŸ”—

tflite_model_delete(resource: Resource) -> None

Performs the Tensorflow Lite model deletion operation.

Wraps the vaccel_tflite_session_delete() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

A resource with the model to unload.

required

Returns:

Type Description
None

The status of the operation execution.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/tflite.py
def tflite_model_delete(self, resource: Resource) -> None:
    """Performs the Tensorflow Lite model deletion operation.

    Wraps the `vaccel_tflite_session_delete()` C operation.

    Args:
        resource: A resource with the model to unload.

    Returns:
        The status of the operation execution.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    ret = lib.vaccel_tflite_session_delete(self._c_ptr, resource._c_ptr)
    if ret != 0:
        raise FFIError(ret, "Tensorflow Lite model delete failed")

tflite_model_load πŸ”—

tflite_model_load(resource: Resource) -> None

Performs the Tensorflow Lite model loading operation.

Wraps the vaccel_tflite_session_load() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

A resource with the model to load.

required

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/tflite.py
def tflite_model_load(self, resource: Resource) -> None:
    """Performs the Tensorflow Lite model loading operation.

    Wraps the `vaccel_tflite_session_load()` C operation.

    Args:
        resource: A resource with the model to load.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    ret = lib.vaccel_tflite_session_load(self._c_ptr, resource._c_ptr)
    if ret != 0:
        raise FFIError(ret, "Tensorflow Lite model loading failed")

tflite_model_run πŸ”—

tflite_model_run(
    resource: Resource, in_tensors: list[Tensor], nr_out_tensors: int = 1
) -> (list[Tensor], int)

Performs the Tensorflow Lite model run operation.

Wraps the vaccel_tflite_session_run() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

A resource with the model to run.

required

in_tensors πŸ”—

list[Tensor]

The input tensors for the inference.

required

nr_out_tensors πŸ”—

int

The number of output tensors. Defaults to 1.

1

Returns:

Type Description
(list[Tensor], int)

A tuple containing: - The output tensors - The status of the operation execution.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/tflite.py
def tflite_model_run(
    self,
    resource: Resource,
    in_tensors: list[Tensor],
    nr_out_tensors: int = 1,
) -> (list[Tensor], int):
    """Performs the Tensorflow Lite model run operation.

    Wraps the `vaccel_tflite_session_run()` C operation.

    Args:
        resource: A resource with the model to run.
        in_tensors: The input tensors for the inference.
        nr_out_tensors: The number of output tensors. Defaults to 1.

    Returns:
        A tuple containing:
            - The output tensors
            - The status of the operation execution.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    c_in_tensors = CList.from_ptrs(in_tensors)
    c_out_tensors = CList.from_ptrs([Tensor.empty()] * nr_out_tensors)
    status = CInt(0, "uint8_t")

    ret = lib.vaccel_tflite_session_run(
        self._c_ptr,
        resource._c_ptr,
        c_in_tensors._c_ptr,
        len(c_in_tensors),
        c_out_tensors._c_ptr,
        len(c_out_tensors),
        status._c_ptr,
    )
    if ret != 0:
        raise FFIError(ret, "Tensorflow Lite model run failed")

    out_tensors = [Tensor.from_c_obj(t) for t in c_out_tensors.value]
    return (out_tensors, status.value)

torch_jitload_forward πŸ”—

torch_jitload_forward(
    resource: Resource,
    in_tensors: list[Tensor],
    nr_out_tensors: int = 1,
    run_options: Buffer | None = None,
) -> list[Tensor]

Performs the Torch jitload forward operation.

Wraps the vaccel_torch_jitload_forward() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

A resource with the model to run.

required

in_tensors πŸ”—

list[Tensor]

The input tensors for the inference.

required

nr_out_tensors πŸ”—

int

The number of output tensors. Defaults to 1.

1

run_options πŸ”—

Buffer | None

The inference options.

None

Returns:

Type Description
list[Tensor]

The output tensors

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/torch.py
def torch_jitload_forward(
    self,
    resource: Resource,
    in_tensors: list[Tensor],
    nr_out_tensors: int = 1,
    run_options: Buffer | None = None,
) -> list[Tensor]:
    """Performs the Torch jitload forward operation.

    Wraps the `vaccel_torch_jitload_forward()` C operation.

    Args:
        resource: A resource with the model to run.
        in_tensors: The input tensors for the inference.
        nr_out_tensors: The number of output tensors. Defaults to 1.
        run_options: The inference options.

    Returns:
        The output tensors

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    run_options_ptr = (
        ffi.NULL if run_options is None else run_options._c_ptr
    )
    c_in_tensors = CList.from_ptrs(in_tensors)
    c_out_tensors = CList.from_ptrs([Tensor.empty()] * nr_out_tensors)

    ret = lib.vaccel_torch_jitload_forward(
        self._c_ptr,
        resource._c_ptr,
        run_options_ptr,
        c_in_tensors._c_ptr,
        len(c_in_tensors),
        c_out_tensors._c_ptr,
        len(c_out_tensors),
    )
    if ret != 0:
        raise FFIError(ret, "Torch jitload forward operation failed")

    return [Tensor.from_c_obj(t) for t in c_out_tensors.value]