Skip to content

fpga πŸ”—

FPGA operations.

FpgaMixin πŸ”—

Mixin providing the FPGA operations for a Session.

This mixin is intended to be used in combination with BaseSession and should not be instantiated on its own.

Intended usage

class Session(BaseSession, FPGAMixin): ...

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]