Structural Simulation Toolkit (SST)

repository·master·Indexed 41 days ago

https://github.com/sstsimulator/sst-core

A modular, parallel simulation framework for exploring highly concurrent systems, including ISA, microarchitecture, memory, and communication systems. SST-Core provides the foundation for modeling these interactions in an MPI-based parallel environment, featuring a Python-based testing framework (sst-test-core, sst-test-elements) and an element library system utilizing C++ Concepts for interface definition.

Tokens
18.5K
Snippets
38
Records
80
Agent score
52%

What's inside SST

  1. Overview of SST Testing Frameworks

    master

    The SST Testing Frameworks is a Python-based system built upon the unittest module, modified specifically for SST. It supports Python 2.7 through Python 3.x and requires no 3rd party modules for basic operation.

    Key Behaviors

    • Automatic Discovery: The system automatically discovers testsuites (though this can be controlled by the user).
    • Test Execution: Each testsuite contains multiple tests. While all tests are given the opportunity to run, individual test code may decide to skip a test based on build settings, environment conditions, or specific scenarios.
    • Execution Order: There is no guarantee on the order of testsuites or the order of tests within a testsuite. However, by default, all tests within a single testsuite complete before the next testsuite begins (unless concurrent testing is enabled).
  2. Understand TinyXML printing and output modes

    master

    TinyXML provides several ways to output XML data, depending on whether you need human readability or network efficiency:

    1. Print( FILE* ) and SaveFile(): Uses C-style FILE* streams. It produces "pretty printed" (human-readable) output with whitespace. It is fast and tolerant of some ill-formed XML.
    2. operator<<: Uses C++ std::ostream. It produces condensed "network printing" mode without line breaks, ideal for transmission between C++ objects. It is less tolerant of ill-formed XML (requires exactly one root element).
    3. TiXmlPrinter: A class used to output to a std::string or memory buffer. This is a more specialized API for custom printing needs.
  3. Implement the Constructor Concept

    master

    The Constructor Concept encapsulates one or more valid constructors for a base class using a variadic template Args.... To satisfy this concept, a class must provide:

    1. A template function add(): This function registers the derived type to the Base class's registry for all matching constructors.
    2. A template type alias is_constructible<T>: This alias defines whether a given type T provides any of the valid constructors for the Base class (e.g., using std::is_constructible).
    template <class T> void add(){
      // ... logic to register with Base
      Base::addBuilder(...);
    }
    
    template <class T>
    using is_constructible = std::is_constructible<T, Args...>;
  4. Naming and Discovering Testsuites

    master

    Testsuites are typically located in the tests subdirectory of core or elements.

    Naming Convention

    All testsuite files must use the prefix testsuite_. The format is: testsuite_<testtype>_<testsuitename>.py

    • <testtype>: A category. Files with type default are run under normal conditions. Other types are only run if explicitly discovered.
    • <testsuitename>: The general name of the suite.

    Examples:

    • testsuite_default_merlin.py
    • testsuite_sweep_memHierarchy_openMP.py

    Discovery Logic

    Discovery is controlled by -p (paths), -y (type), and -w (wildcard).

    1. Path Selection (-p):

      • If -p is empty (default), the framework searches directories listed in sstsimulator.conf (in <sstcore_install>/etc).
      • If -p points to a file, that specific file is added to the run list.
      • If -p points to a directory, that directory is searched.
    2. Filtering (-y or -w):

      • No -y or -w: Only files named testsuite_default_*.py are run.
      • -y <type_name>: Runs files named testsuite_<type_name>_*.py (e.g., -y autotester).
      • -y all: Runs all files named testsuite_*.py.
      • -w <wildcard>: Runs files matching the pattern testsuite_<wildcard>.py. Note: Use quotes to prevent shell expansion (e.g., -w "*merlin*").
  5. Understand the SST Testing Framework architecture

    master

    The SST testing framework is built on top of Python's unittest infrastructure and is designed to be transparent to the user. It supports any registered component (sst-core, sst-elements, or 3rd party elements) regardless of its directory path.

    Core Components

    • Launching Scripts: sst-test-core (for core testing) and sst-test-elements (for element testing).
    • Engine: test_engine.py handles discovery and execution.
    • Base Classes: sst_unittest.py provides the primary SSTTestCase class.
    • Support Modules: sst_unittest_support.py and sst_unittest_parameterized.py provide utility functions and parameterized testing support.

    Output Directories

    Every test run automatically creates three subdirectories in the output directory:

    1. tmp_data: For temporary output or generated files using unique names.
    2. run_data: For final output result files.
    3. xml_data: For JUnit-formatted XML results (compatible with Jenkins).
  6. Understand Element Library Concepts and C++ Concepts

    master
    SST element libraries rely on C++ Concepts to define interfaces between functions. To integrate a class into a specific context within the library, the class must implement a minimal set of required type aliases (typedefs) and functions defined by these concepts.
  7. Use TiXmlHandle for safer DOM traversal

    master

    Standard DOM traversal requires frequent null checks for every element returned. To simplify this, use the TiXmlHandle class, which allows for a more concise, chainable syntax for navigating the tree.

    Standard approach:

    TiXmlElement* root = document.FirstChildElement( "Document" );
    if ( root ) {
        TiXmlElement* element = root->FirstChildElement( "Element" );
        if ( element ) {
            // ...
        }
    }

    Using TiXmlHandle:

    TiXmlHandle docHandle( &document );
    TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
    if ( child2 ) {
        // Finally do something useful
    }
  8. Implement different Constructor types: SingleCtor, CtorList, and Extended Constructor

    master

    Depending on the complexity of your element's instantiation, you can implement one of three constructor patterns:

    • SingleCtor: The simplest implementation, representing exactly one valid constructor with a specific set of Args....
    • CtorList: Represents a list of multiple possible valid constructors. The class must register builders that match at least one constructor in the list.
    • Extended Constructor: Used when a derived class Derived can be created via multiple base classes (e.g., Base1 and Base2, where Base2 inherits from Base1). The constructor for Base2 must register the class T to both itself and the original Base1. In this case, the is_constructible type alias applies only to the most derived base class.
  9. Verify your SST-Core installation

    master

    After completing the build and installation process, you can verify that the installation was successful by running the sst-test-core binary located in the bin directory of your installation prefix.

    /path/to/sst-core/install/bin/sst-test-core
  10. Build SST-Core using CMake

    master

    To build the SST-Core infrastructure from source, follow these steps:

    1. Download the SST release or clone the repository from GitHub.
    2. Create and enter a build directory.
    3. Run cmake pointing to the experimental directory with your desired build directives.
    4. Run make to compile the source code. You can use -j for parallel builds or make install to install the built software.
    $> cd sstcore-VERSION
    $> mkdir build
    $> cd build
    $> cmake ../experimental
    $> make -j
    $> make install
  11. Enable Concurrent Testing and Colorized Output

    master

    While the framework works out-of-the-box, you can install optional 3rd party Python modules to enable advanced features:

    • Concurrent Testing: To run tests in multiple threads, install testtools.
    • Colorized Output: To enable colorized terminal output, install blessings and pygments.
    # For concurrent testing
    pip install testtools
    
    # For colorized output
    pip install blessings pygments
  12. Build SST-Core from source on Ubuntu 20.04

    master

    To build SST-Core on Ubuntu 20.04, install the necessary build tools and OpenMPI via apt, clone the repository, and use autogen.sh to prepare the source tree. Configure the build with a --prefix pointing to your desired installation directory.

    DEBIAN_FRONTEND=noninteractive sudo apt install openmpi-bin openmpi-common libtool libtool-bin autoconf python3 python3-dev automake build-essential git
    mkdir sst-core && cd sst-core
    git clone https://github.com/sstsimulator/sst-core.git sst-core-src
    (cd sst-core-src && ./autogen.sh)
    mkdir build && cd build
    ../sst-core-src/configure --prefix=$PWD/../sst-core-install
    make install