da4ml.cmvm.core package
Submodules
da4ml.cmvm.core.indexers module
- da4ml.cmvm.core.indexers.idx_mc_dc(state: DAState, absolute: bool = False)
Choose the pair with highest frequency with latency penalty. If absolute is True, return -1 if any latency overhead may present.
- da4ml.cmvm.core.indexers.idx_wmc(state: DAState)
Choose the pair with the highest weighted most common subexpression (WMC) score.
da4ml.cmvm.core.state_opr module
- da4ml.cmvm.core.state_opr.cost_add(qint0: QInterval, qint1: QInterval, shift: int, sub: bool = False, adder_size: int = -1, carry_size: int = -1) tuple[float, float]
Calculate the latency and cost of an addition operation.
- Parameters:
- Returns:
The latency and cost of the addition operation.
- Return type:
tuple[float, float]
- da4ml.cmvm.core.state_opr.create_state(kernel: ndarray, qintervals: list[QInterval], inp_latencies: list[float], no_stat_init: bool = False)
- da4ml.cmvm.core.state_opr.gather_matching_idxs(state: DAState, pair: Pair)
Generates all i_out, j0, j1 ST expr[i_out][in0, j0] and expr[i_out][in1, j1] corresponds to op provided.
- da4ml.cmvm.core.state_opr.pair_to_op(pair: Pair, state: DAState, adder_size: int = -1, carry_size: int = -1)
- da4ml.cmvm.core.state_opr.qint_add(qint0: QInterval, qint1: QInterval, shift: int, sub0=False, sub1=False) QInterval
- da4ml.cmvm.core.state_opr.update_expr(state: DAState, pair: Pair, adder_size: int, carry_size: int)
Updates the state by implementing the operation op, excepts common 2-term pair freq update.
Module contents
- da4ml.cmvm.core.cmvm(kernel: ndarray, method: str = 'wmc', qintervals: list[QInterval] | None = None, inp_latencies: list[float] | None = None, adder_size: int = -1, carry_size: int = -1) DAState
Optimizes the kernel using the CMVM algorithm.
- Parameters:
kernel (np.ndarray) – The kernel to optimize.
method (str, optional) – Which indexing method to use, by default ‘wmc’ (weighted most common) Must be one of [mc, mc-dc, mc-pdc, wmc, wmc-dc, wmc-pdc, dummy]
qintervals (list[QInterval] | None, optional) – List of QIntervals for each input, by default None If None, defaults to [-128., 127., 1.] for each input.
inp_latencies (list[float] | None, optional) – List of latencies for each input, by default None If None, defaults to 0. for each input.
adder_size (int, optional) – The atomic size of the adder for cost computation, by default -1 if -1, each adder can be arbitrary large, and the cost will be the number of adders
carry_size (int, optional) – The size of the carry unit for latency computation, by default -1 if -1, each carry unit can be arbitrary large, and the cost will be the depth of the adder tree
- Returns:
The optimized kernel as a DAState object.
- Return type:
- da4ml.cmvm.core.to_solution(state: DAState, adder_size: int, carry_size: int)
Converts the DAState to a Solution object with balanced tree reduction for the non-extracted bits in the kernel.
- Parameters:
state (DAState) – The DAState to convert.
adder_size (int, optional) – The atomic size of the adder for cost computation, by default -1 if -1, each adder can be arbitrary large, and the cost will be the number of adders
carry_size (int, optional) – The size of the carry unit for latency computation, by default -1 if -1, each carry unit can be arbitrary large, and the cost will be the depth of the adder tree
- Returns:
The Solution object with the optimized kernel.
- Return type: