Skip to content

vaccel 🔗

Python API for vAccel.

Arg 🔗

Arg(data: Any)

Bases: CType

Wrapper for the vaccel_arg C struct.

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

Inherits

CType: Abstract base class for defining C data types.

Parameters:

Name Type Description Default

data 🔗

Any

The input data to be passed to the C struct.

required
Source code in vaccel/arg.py
def __init__(self, data: Any):
    """Initializes a new `Arg` object.

    Args:
        data: The input data to be passed to the C struct.
    """
    self._c_data = CAny(data)
    super().__init__()

buf property 🔗

buf: Any

Returns the buffer value from the underlying C struct.

Retrieves the buffer (buf) stored in the struct vaccel_arg C object. If the original data type is a Python built-in type, the buffer is converted back to that type.

Returns:

Type Description
Any

The buffer value from the C struct vaccel_arg.

c_size property 🔗

c_size: int

Returns the size of the object in bytes.

value property 🔗

value: CData

Returns the value of the underlying C struct.

Returns:

Type Description
CData

The dereferenced 'struct vaccel_arg`

Config 🔗

Config(
    plugins: str = "libvaccel-noop.so",
    log_level: int = 1,
    log_file: str | None = None,
    *,
    profiling_enabled: bool = False,
    version_ignore: bool = False,
)

Bases: CType

Wrapper for the struct vaccel_config C object.

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

Inherits

CType: Abstract base class for defining C data types.

Parameters:

Name Type Description Default

plugins 🔗

str

Colon-separated list of plugin names to load.

'libvaccel-noop.so'

log_level 🔗

int

Logging level (1=ERROR, 4=DEBUG).

1

log_file 🔗

str | None

Path to log file or None to disable logging to file.

None

profiling_enabled 🔗

bool

Enable or disable profiling.

False

version_ignore 🔗

bool

Ignore version mismatches if True.

False
Source code in vaccel/config.py
def __init__(
    self,
    plugins: str = "libvaccel-noop.so",
    log_level: int = 1,
    log_file: str | None = None,
    *,
    profiling_enabled: bool = False,
    version_ignore: bool = False,
):
    """Initializes a new `Config` object.

    Args:
        plugins (str): Colon-separated list of plugin names to load.
        log_level (int): Logging level (1=ERROR, 4=DEBUG).
        log_file (str | None): Path to log file or None to disable logging
            to file.
        profiling_enabled (bool): Enable or disable profiling.
        version_ignore (bool): Ignore version mismatches if True.
    """
    self._plugins = str(plugins)
    self._log_level = log_level
    self._log_file = log_file
    self._profiling_enabled = profiling_enabled
    self._version_ignore = version_ignore
    self._c_obj_ptr = ffi.NULL
    super().__init__()

c_size property 🔗

c_size: int

Returns the size of the object in bytes.

log_file property 🔗

log_file: str | None

The configured log file.

Returns:

Type Description
str | None

The config's log file.

log_level property 🔗

log_level: int

The configured log level.

Returns:

Type Description
int

The config's log level.

plugins property 🔗

plugins: str

The configured plugins.

Returns:

Type Description
str

The config's plugins.

profiling_enabled property 🔗

profiling_enabled: bool

If profiling is enabled or disabled.

Returns:

Type Description
bool

True if profiling is enabled.

value property 🔗

value: CData

Returns the value of the underlying C struct.

Returns:

Type Description
CData

The dereferenced 'struct vaccel_config`

version_ignore property 🔗

version_ignore: bool

Whether a plugin/vAccel version mismatch is ignored.

Returns:

Type Description
bool

True if version mismatch is ignored.

Resource 🔗

Resource(paths: list[Path] | list[str] | Path | str, type_: ResourceType)

Bases: CType

Wrapper for the struct vaccel_resource C object.

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

Inherits

CType: Abstract base class for defining C data types.

Parameters:

Name Type Description Default

paths 🔗

list[Path] | list[str] | Path | str

The path(s) to the file(s) that will be represented by the resource.

required

type_ 🔗

ResourceType

The type of the resource.

required
Source code in vaccel/resource.py
def __init__(
    self, paths: list[Path] | list[str] | Path | str, type_: ResourceType
):
    """Initializes a new `Resource` object.

    Args:
        paths: The path(s) to the file(s) that will be represented by the
            resource.
        type_: The type of the resource.
    """
    if isinstance(paths, list):
        self._paths = [str(path) for path in paths]
    else:
        self._paths = [str(paths)]
    self._c_paths = CList(self._paths)
    self._type = type_
    self.__sessions = []
    super().__init__()

c_size property 🔗

c_size: int

Returns the size of the object in bytes.

id property 🔗

id: int

The resource identifier.

Returns:

Type Description
int

The resource's unique ID.

remote_id property 🔗

remote_id: int

The remote resource identifier.

Returns:

Type Description
int

The resource's remote ID.

value property 🔗

value: CData

Returns the value of the underlying C struct.

Returns:

Type Description
CData

The dereferenced 'struct vaccel_resource`

is_registered 🔗

is_registered(session: BaseSession) -> bool

Checks if the resource is registered with the session.

Parameters:

Name Type Description Default

session 🔗

BaseSession

The session to check for registration.

required

Returns:

Type Description
bool

True if the resource is registered with the session.

Source code in vaccel/resource.py
def is_registered(self, session: "Session") -> bool:
    """Checks if the resource is registered with the session.

    Args:
        session: The session to check for registration.

    Returns:
        True if the resource is registered with the session.
    """
    return session in self.__sessions

register 🔗

register(session: BaseSession) -> None

Register the resource with a session.

Parameters:

Name Type Description Default

session 🔗

BaseSession

The session to register the resource with.

required

Raises:

Type Description
FFIError

If resource registration fails.

Source code in vaccel/resource.py
def register(self, session: "Session") -> None:
    """Register the resource with a session.

    Args:
        session: The session to register the resource with.

    Raises:
        FFIError: If resource registration fails.
    """
    ret = lib.vaccel_resource_register(
        self._c_ptr_or_raise,
        session._c_ptr_or_raise,
    )
    if ret != 0:
        raise FFIError(
            ret,
            f"Could not register resource {self.id} "
            f"with session {session.id}",
        )
    self.__sessions.append(session)

unregister 🔗

unregister(session: BaseSession) -> None

Unregister the resource from a session.

Parameters:

Name Type Description Default

session 🔗

BaseSession

The session to unregister the resource from.

required

Raises:

Type Description
FFIError

If resource unregistration fails.

Source code in vaccel/resource.py
def unregister(self, session: "Session") -> None:
    """Unregister the resource from a session.

    Args:
        session: The session to unregister the resource from.

    Raises:
        FFIError: If resource unregistration fails.
    """
    ret = lib.vaccel_resource_unregister(
        self._c_ptr_or_raise,
        session._c_ptr_or_raise,
    )
    if ret != 0:
        raise FFIError(
            ret,
            f"Could not unregister resource {self.id} "
            f"from session {session.id}",
        )
    self.__sessions.remove(session)

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
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:
        FFIError: If the C operation fails.
    """
    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_or_raise,
        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
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:
        FFIError: If the C operation fails.
    """
    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_depth(
        self._c_ptr_or_raise,
        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
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:
        FFIError: If the C operation fails.
    """
    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_detection(
        self._c_ptr_or_raise,
        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 🔗

exec(
    library: str | Path,
    symbol: str,
    arg_read: list[Any] | None = None,
    arg_write: list[Any] | None = None,
) -> list[Any] | None

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] | None

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

None

arg_write 🔗

list[Any] | None

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

None

Returns:

Type Description
list[Any] | None

The resulting outputs.

Raises:

Type Description
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] | None = None,
    arg_write: list[Any] | None = None,
) -> list[Any] | None:
    """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:
        FFIError: If the C operation fails.
    """
    if arg_read is not None:
        c_arg_read = CList([Arg(arg) for arg in arg_read])
        c_arg_read_ptr = c_arg_read._c_ptr
        c_arg_read_len = len(c_arg_read)
    else:
        c_arg_read = None
        c_arg_read_ptr = ffi.NULL
        c_arg_read_len = 0

    if arg_write is not None:
        c_arg_write = CList([Arg(arg) for arg in arg_write])
        c_arg_write_ptr = c_arg_write._c_ptr
        c_arg_write_len = len(c_arg_write)
    else:
        c_arg_write = None
        c_arg_write_ptr = ffi.NULL
        c_arg_write_len = 0

    ret = lib.vaccel_exec(
        self._c_ptr_or_raise,
        str(library).encode(),
        symbol.encode(),
        c_arg_read_ptr,
        c_arg_read_len,
        c_arg_write_ptr,
        c_arg_write_len,
    )
    if ret != 0:
        raise FFIError(ret, "Exec operation failed")

    if c_arg_write is not None:
        return [c_arg_write[i].buf for i in range(len(c_arg_write))]
    return None

exec_with_resource 🔗

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

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] | None

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

None

arg_write 🔗

list[Any] | None

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

None

Returns:

Type Description
list[Any] | None

The resulting outputs.

Raises:

Type Description
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] | None = None,
    arg_write: list[Any] | None = None,
) -> list[Any] | None:
    """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:
        FFIError: If the C operation fails.
    """
    if arg_read is not None:
        c_arg_read = CList([Arg(arg) for arg in arg_read])
        c_arg_read_ptr = c_arg_read._c_ptr
        c_arg_read_len = len(c_arg_read)
    else:
        c_arg_read = None
        c_arg_read_ptr = ffi.NULL
        c_arg_read_len = 0

    if arg_write is not None:
        c_arg_write = CList([Arg(arg) for arg in arg_write])
        c_arg_write_ptr = c_arg_write._c_ptr
        c_arg_write_len = len(c_arg_write)
    else:
        c_arg_write = None
        c_arg_write_ptr = ffi.NULL
        c_arg_write_len = 0

    ret = lib.vaccel_exec_with_resource(
        self._c_ptr_or_raise,
        resource._c_ptr,
        symbol.encode(),
        c_arg_read_ptr,
        c_arg_read_len,
        c_arg_write_ptr,
        c_arg_write_len,
    )
    if ret != 0:
        raise FFIError(ret, "Exec with resource operation failed")

    if c_arg_write is not None:
        return [c_arg_write[i].buf for i in range(len(c_arg_write))]
    return None

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
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:
        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_or_raise, 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
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:
        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_or_raise, 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
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:
        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_or_raise,
        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
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:
        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_or_raise,
        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
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:
        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_or_raise,
        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_ptr_or_raise, resource._c_ptr
        )
        != 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
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:
        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_or_raise,
        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
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:
        FFIError: If the C operation fails.
    """
    ret = lib.vaccel_noop(self._c_ptr_or_raise)
    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
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:
        FFIError: If the C operation fails.
    """
    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_pose(
        self._c_ptr_or_raise,
        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
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:
        FFIError: If the C operation fails.
    """
    img = CBytes(image)
    out_imgname = CBytes(bytearray(self._out_len))

    ret = lib.vaccel_image_segmentation(
        self._c_ptr_or_raise,
        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
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:
        FFIError: If the C operation fails.
    """
    c_a = CList(a)
    c_b = CList(b)
    c_c = CList([float(0)] * m * n)

    ret = lib.vaccel_sgemm(
        self._c_ptr_or_raise,
        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
FFIError

If the C operation fails.

Source code in vaccel/ops/tf/mixin.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:
        FFIError: If the C operation fails.
    """
    status = Status()
    ret = lib.vaccel_tf_session_delete(
        self._c_ptr_or_raise, 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
FFIError

If the C operation fails.

Source code in vaccel/ops/tf/mixin.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:
        FFIError: If the C operation fails.
    """
    status = Status()
    ret = lib.vaccel_tf_session_load(
        self._c_ptr_or_raise, 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
FFIError

If the C operation fails.

Source code in vaccel/ops/tf/mixin.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:
        FFIError: If the C operation fails.
    """
    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_or_raise,
        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
FFIError

If the C operation fails.

Source code in vaccel/ops/tf/lite/mixin.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:
        FFIError: If the C operation fails.
    """
    ret = lib.vaccel_tflite_session_delete(
        self._c_ptr_or_raise, 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
FFIError

If the C operation fails.

Source code in vaccel/ops/tf/lite/mixin.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:
        FFIError: If the C operation fails.
    """
    ret = lib.vaccel_tflite_session_load(
        self._c_ptr_or_raise, 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
FFIError

If the C operation fails.

Source code in vaccel/ops/tf/lite/mixin.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:
        FFIError: If the C operation fails.
    """
    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_or_raise,
        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
FFIError

If the C operation fails.

Source code in vaccel/ops/torch/mixin.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:
        FFIError: If the C operation fails.
    """
    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_or_raise,
        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]

bootstrap 🔗

bootstrap(config: Config | None = None) -> None

Initializes the vAccel library.

Parameters:

Name Type Description Default

config 🔗

Config | None

A configuration object for the library. If None, defaults are used.

None

Raises:

Type Description
FFIError

If the C operation fails.

Source code in vaccel/vaccel.py
def bootstrap(config: Config | None = None) -> None:
    """Initializes the vAccel library.

    Args:
        config (Config | None): A configuration object for the library. If None,
            defaults are used.

    Raises:
        FFIError: If the C operation fails.
    """
    if config is None:
        ret = lib.vaccel_bootstrap()
    else:
        ret = lib.vaccel_bootstrap_with_config(config._c_ptr)
    if ret != 0:
        raise FFIError(ret, "Could not bootstrap vAccel library")

cleanup 🔗

cleanup() -> None

Cleans up the vAccel library resources.

This function is called automatically at program exit, but can also be invoked explicitly if needed.

Raises:

Type Description
FFIError

If the C operation fails.

Source code in vaccel/vaccel.py
@atexit.register
def cleanup() -> None:
    """Cleans up the vAccel library resources.

    This function is called automatically at program exit, but can also be
    invoked explicitly if needed.

    Raises:
        FFIError: If the C operation fails.
    """
    ret = lib.vaccel_cleanup()
    if ret != 0:
        raise FFIError(ret, "Could not cleanup vAccel library objects")