alkaid.trace package

Subpackages

Submodules

alkaid.trace.affine_interval module

class alkaid.trace.affine_interval.AffineInterval(coeffs: dict[AtomicInterval, float], bias: float)

Bases: object

classmethod new(qint: QInterval) AffineInterval
property qint: QInterval
class alkaid.trace.affine_interval.AtomicInterval(qint: QInterval, uuid=None)

Bases: object

alkaid.trace.fixed_variable module

class alkaid.trace.fixed_variable.BitsView(var: FVariable)

Bases: object

class alkaid.trace.fixed_variable.FVariable(low: float | None = None, high: float | None = None, step: float | None = None, *, latency: float | None = None, hwconf: HWConfig | tuple[int, int, int] = (-1, 1, -1), opr: str = 'new', _from: tuple[FVariable, ...] = (), _factor: float = 1.0, _data: int | None = None, _id: UUID | None = None, _affine: AffineInterval | None = None, _table: LookupTable | None = None)

Bases: object

binary_bit_op(other: FVariable, _type: str)
property bits
classmethod from_const(const: float, hwconf: HWConfig)
classmethod from_kif(k: int | bool, i: int, f: int, **kwargs)
get_latency() float
property high: float
is_negative() FVariable
is_positive() FVariable
property kif: tuple[bool, int, int]
lookup(table: LookupTable | ndarray, original_qint: tuple[float, float, float] | None = None) FVariable

Use a lookup table to map the variable.

Parameters:
  • table (LookupTable | np.ndarray) – Lookup table to use

  • original_qint (tuple[float, float, float] | None) – The original quantization interval of the variable where the original table is applied to.

Return type:

FVariable

property low: float
max_of(other)

Get the maximum of this variable and another variable or constant.

min_of(other)

Get the minimum of this variable and another variable or constant.

msb() FVariable
msb_mux(a: FVariable | float, b: FVariable | float, qint: tuple[float, float, float] | None = None) FVariable

If the MSB of this variable is 1, return a, else return b. When the variable is signed, the MSB is determined by the sign bit (1 for <0, 0 for >=0)

property qint: QInterval
quantize(k: int | bool, i: int, f: int, overflow_mode: str = 'WRAP', round_mode: str = 'TRN') FVariable

Quantize the variable to the specified fixed-point format.

Parameters:
  • k (int | bool) – Sign bit (True for signed, False for unsigned)

  • i (int) – Integer bits, excluding sign bit

  • f (int) – Fraction bits

  • overflow_mode (str, optional) – Overflow mode, one of ‘WRAP’, ‘SAT’, ‘SAT_SYM’, by default ‘WRAP’

  • round_mode (str, optional) – Rounding mode, one of ‘TRN’ (truncate), ‘RND’ (round to nearest, half up), by default ‘TRN’

relu(i: int | None = None, f: int | None = None, round_mode: str = 'TRN')
property step: float
unary_bit_op(_type: str)
property unscaled
class alkaid.trace.fixed_variable.FVariableInput(latency: float | None = None, hwconf: HWConfig | tuple[int, int, int] = (-1, 1, -1), opr: str = 'new')

Bases: FVariable

property high: float
property low: float
max_of(other)

Get the maximum of this variable and another variable or constant.

min_of(other)

Get the minimum of this variable and another variable or constant.

quantize(k: int | bool, i: int, f: int, overflow_mode: str = 'WRAP', round_mode: str = 'TRN')

Quantize the variable to the specified fixed-point format.

Parameters:
  • k (int | bool) – Sign bit (True for signed, False for unsigned)

  • i (int) – Integer bits, excluding sign bit

  • f (int) – Fraction bits

  • overflow_mode (str, optional) – Overflow mode, one of ‘WRAP’, ‘SAT’, ‘SAT_SYM’, by default ‘WRAP’

  • round_mode (str, optional) – Rounding mode, one of ‘TRN’ (truncate), ‘RND’ (round to nearest, half up), by default ‘TRN’

relu(*args, **kwargs)
property step: float
class alkaid.trace.fixed_variable.HWConfig(adder_size, carry_size, latency_cutoff)

Bases: NamedTuple

adder_size: int

Alias for field number 0

carry_size: int

Alias for field number 1

latency_cutoff: float

Alias for field number 2

class alkaid.trace.fixed_variable.LookupTable(values: ndarray[tuple[Any, ...], dtype[_ScalarT]], spec: TableSpec | None = None, mask: ndarray[tuple[Any, ...], dtype[bool]] | None = None)

Bases: object

property float_table: ndarray[tuple[Any, ...], dtype[floating]]
classmethod from_dict(data: dict) LookupTable
lookup(var: FVariable, qint_in: QInterval) FVariable
lookup(var: floating | float, qint_in: QInterval | tuple[float, float, float]) float
padded_table(key_qint: QInterval) ndarray[tuple[Any, ...], dtype[float64]]
to_dict() dict
class alkaid.trace.fixed_variable.TableSpec(hash: str, out_qint: alkaid.types.QInterval, inp_width: int)

Bases: object

hash: str
inp_width: int
property out_kif: tuple[bool, int, int]
out_qint: QInterval
alkaid.trace.fixed_variable.interpret_as(x: ndarray[tuple[Any, ...], dtype[integer]], k: int, i: int, f: int) ndarray[tuple[Any, ...], dtype[floating]]
alkaid.trace.fixed_variable.interpret_as(x: int, k: int, i: int, f: int) float
alkaid.trace.fixed_variable.to_spec(table: ndarray[tuple[Any, ...], dtype[floating]]) tuple[TableSpec, ndarray[tuple[Any, ...], dtype[int32]], ndarray[tuple[Any, ...], dtype[bool]] | None]

alkaid.trace.fixed_variable_array module

class alkaid.trace.fixed_variable_array.FVArray(vars: ndarray[tuple[Any, ...], dtype[_ScalarT]], solver_options: solver_options_t | None = None, hwconf: HWConfig | tuple[int, int, int] | None = None)

Bases: ndarray

Symbolic array of FVariable for tracing operations. Supports numpy ufuncs and array functions.

apply(fn: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]]) RetardedFVArray

Apply a unary operator to all elements, returning a RetardedFVArray.

as_new()

Create a new FVArray with the same shape and hardware configuration, but new FVariable instances.

property collapsed
classmethod from_kif(k: ndarray[tuple[Any, ...], dtype[bool | integer]], i: ndarray[tuple[Any, ...], dtype[integer]], f: ndarray[tuple[Any, ...], dtype[integer]], hwconf: HWConfig | tuple[int, int, int] = (1, 1, -1), latency: ndarray[tuple[Any, ...], dtype[floating]] | float = 0.0, solver_options: solver_options_t | None = None)
classmethod from_lhs(low: ndarray[tuple[Any, ...], dtype[floating]], high: ndarray[tuple[Any, ...], dtype[floating]], step: ndarray[tuple[Any, ...], dtype[floating]], hwconf: HWConfig | tuple[int, int, int] = (1, 1, -1), latency: ndarray | float = 0.0, solver_options: solver_options_t | None = None)
property kif

[k, i, f] array

property latency

Maximum latency among all elements.

property lhs

[low, high, step] array

classmethod new(shape: tuple[int, ...] | int, hwconf: HWConfig | tuple[int, int, int] = (1, 1, -1), solver_options: solver_options_t | None = None, latency=0.0) FVArray
quantize(k: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, i: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, f: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, overflow_mode: str = 'WRAP', round_mode: str = 'TRN')
relu(i: ndarray[tuple[Any, ...], dtype[integer]] | None = None, f: ndarray[tuple[Any, ...], dtype[integer]] | None = None, round_mode: str = 'TRN')
to_bool(reduction='any')
class alkaid.trace.fixed_variable_array.FVArrayInput(shape: tuple[int, ...] | int, hwconf: HWConfig | tuple[int, int, int] = (1, 1, -1), solver_options: solver_options_t | None = None, latency=0.0)

Bases: FVArray

Similar to FVArray, but initializes all elements as FVariableInput - the precisions are unspecified when initialized, and the highest precision requested (i.e., quantized to) will be recorded for generation of the logic.

class alkaid.trace.fixed_variable_array.RetardedFVArray(vars: ndarray[tuple[Any, ...], dtype[_ScalarT]], solver_options: solver_options_t | None, operator: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]])

Bases: FVArray

Ephemeral FVArray generated from operations of unspecified output precision. This object translates to normal FVArray upon quantization. Does not inherit the maximum precision like FVArrayInput.

This object can be used in two ways: 1. Quantization with specified precision, which converts to FVArray. 2. Apply an further unary operation, which returns another RetardedFVArray. (e.g., composite functions)

apply(fn: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]]) RetardedFVArray

Apply a unary operator to all elements, returning a RetardedFVArray.

property kif

[k, i, f] array

quantize(k: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, i: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, f: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, overflow_mode: str = 'WRAP', round_mode: str = 'TRN')
alkaid.trace.fixed_variable_array.cmvm(cm: ndarray, v: FVArray, solver_options: solver_options_t) ndarray
alkaid.trace.fixed_variable_array.make_table(fn: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]], qint: QInterval) LookupTable
alkaid.trace.fixed_variable_array.mmm(mat0: ndarray, mat1: ndarray)
alkaid.trace.fixed_variable_array.to_raw_arr(obj: T) T

alkaid.trace.pipeline module

alkaid.trace.pipeline.to_pipeline(comb: CombLogic, n_stages: int | None = None, latency_cutoff: float | None = None, verbose=True) Pipeline

Split a CombLogic program into latency-balanced pipeline stages.

Exactly one of n_stages and latency_cutoff must be specified. The resulting Pipeline is intended for RTL generation.

Parameters:
  • comb (CombLogic) – The combinational logic to be pipelined into multiple stages.

  • n_stages (int | None) – Number of stages to create.

  • latency_cutoff (float | None) – Maximum target latency per stage. The final stage count is derived from the total operation latency.

  • verbose (bool) – Whether to print the latency cutoffs used for splitting.

Returns:

The cascaded solution with multiple stages.

Return type:

Pipeline

alkaid.trace.tracer module

alkaid.trace.tracer.gather_variables(inputs: Sequence[FVariable], outputs: Sequence[FVariable])
alkaid.trace.tracer.needs_negative(variables: Sequence[FVariable], outputs: Sequence[FVariable]) set[UUID]
alkaid.trace.tracer.trace(inputs, outputs, optimize=True, keep_dead_inputs: bool = False) CombLogic

Module contents