CiMLoop HWComponents

The HWComponents (Hardware Components) package, part of the CiMLoop project, provides an interface for the estimation of energy, area, and leakage power of hardware components in hardware architectures. Key features in HWComponents include:

  • A simple Python API for writing energy, area, and leakage power models. New models can be written in minutes.

  • Automatic scaling of parameters to different configurations, including scaling to different technology nodes.

  • Pythonic interfaces for finding components, picking the best components for a given request, and more.

  • Automatic gathering of components from available Python packages. This includes support for different models in virtual environments.

Components are also compatible with Accelergy.

Installation

Clone the repository and install with pip. This repository also contains provided models as submodules.

# Install the main package
git clone --recurse-submodules https://github.com/Accelergy-Project/hwcomponents.git
pip install ./hwcomponents

# Install model packages
cd hwcomponents/models
pip3 install ./hwcomponents/models/*

# List available models
hwc --list # or hwcomponents --list

hwcomponents API

Code

Tutorials

See the tutorials directory for examples of how to use the package and to create models. Additional documentation and tutorials are available on this site:

Example Usage

The following example shows a ternary MAC component written in HWComponents. It uses scaling to scale the width and technology node of the MAC.

Full examples of how to use the package are available in the notebooks directory.

from hwcomponents import EnergyAreaModel, actionDynamicEnergy
from hwcomponents.scaling import tech_node_area, tech_node_energy, tech_node_leak

class TernaryMAC(EnergyAreaModel):
    """

    A ternary MAC unit, which multiplies two ternary values and accumulates the result.

    Parameters
    ----------
    accum_datawidth : int
        The width of the accumulator in bits.
    tech_node : int
        The technology node in meters.

    Attributes
    ----------
    accum_datawidth : int
        The width of the accumulator in bits.
    tech_node : int
        The technology node in meters.
    """

    component_name: str | list[str] = 'TernaryMAC'
    """ Name of the component. Must be a string or list/tuple of strings. """

    priority = 0.8
    """
    Priority determines which model is used when multiple models are available for a
    given component. Higher priority models are used first. Must be a number between 0
    and 1.
    """

    def __init__(self, accum_datawidth: int, tech_node: int):
        # Provide an area and leakage power for the component. All units are in
        # standard units without any prefixes (Joules, Watts, meters, etc.).
        super().__init__(
            area=5e-12 * accum_datawidth,
            leak_power=1e-3 * accum_datawidth
        )

        # The following scales the tech_node to the given tech_node node from 40nm.
        # The scaling functions for area, energy, and leakage are defined in
        # hwcomponents.scaling. The energy scalingw will affect the functions decorated
        # with @actionDynamicEnergy.
        self.tech_node = self.scale(
            "tech_node",
            tech_node,
            40e-9,
            tech_node_area,
            tech_node_energy,
            tech_node_leak,
        )
        self.accum_datawidth = accum_datawidth

        # Raising an error says that this model can't estimate and other models instead
        # should be used instead. Good error messages are essential for users debugging
        # their designs.
        assert 4 <= accum_datawidth <= 8, \
            f'Accumulation datawidth {accum_datawidth} outside supported ' \
            f'range [4, 8]!'

    # The actionDynamicEnergy decorator makes this function visible as an action. The
    # function should return an energy in Joules.
    @actionDynamicEnergy
    def mac(self, clock_gated: bool = False) -> float:
        """
        Returns the energy to perform a ternary MAC operation.

        Parameters
        ----------
        clock_gated : bool
            Whether the MAC is clock gated during this operation.

        Returns
        -------
        float
            The energy to perform a ternary MAC operation in Joules.
        """

        self.logger.info(f'TernaryMAC Model is estimating '
                         f'energy for mac_random.')
        if clock_gated:
            return 0.0
        return 0.002e-12 * (self.accum_datawidth + 0.25)

mac = TernaryMAC(accum_datawidth=8, tech_node=16e-9) # Scale the TernaryMAC to 16nm
print(f'TernaryMAC energy is {mac.mac():.2e}J. Area is {mac.area:.2e}m^2. Leak power is {mac.leak_power:.2e}W')

Contributing

Contributions are welcome! Please issue a pull request on GitHub with any changes.

Citing HWComponents

If you use this package in your work, please cite the CiMLoop project:

@INPROCEEDINGS{10590023,
author={Andrulis, Tanner and Emer, Joel S. and Sze, Vivienne},
booktitle={2024 IEEE International Symposium on Performance Analysis of Systems and Software (ISPASS)},
title={CiMLoop: A Flexible, Accurate, and Fast Compute-In-Memory Modeling Tool},
year={2024},
volume={},
number={},
pages={10-23},
keywords={Performance evaluation;Accuracy;Computational modeling;Computer architecture;Artificial neural networks;In-memory computing;Data models;Compute-In-Memory;Processing-In-Memory;Analog;Deep Neural Networks;Systems;Hardware;Modeling;Open-Source},
doi={10.1109/ISPASS61541.2024.00012}
}
@INPROCEEDINGS{8942149,
author={Wu, Yannan Nellie and Emer, Joel S. and Sze, Vivienne},
booktitle={2019 IEEE/ACM International Conference on Computer-Aided Design (ICCAD)},
title={Accelergy: An Architecture-Level Energy Estimation Methodology for Accelerator Designs},
year={2019},
volume={},
number={},
pages={1-8},
keywords={Program processors;Electric breakdown;Neural networks;Estimation;Hardware;Energy efficiency;Compounds},
doi={10.1109/ICCAD45719.2019.8942149}
}