Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basics of sst core #5

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added P38_Nov2020/01_Overview_Using.pptx
Binary file not shown.
Binary file added P38_Nov2020/03_developing-2020-11-05-final.pptx
Binary file not shown.
Binary file added P38_Nov2020/04_scatterGather_p38.pptx
Binary file not shown.
Binary file added P38_Nov2020/20201106-SST-Lime-presentation.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions P38_Nov2020/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tutorial given for Project 38 in November 2020
Binary file added P38_Nov2020/sst_gpgpusim.pptx
Binary file not shown.
66 changes: 66 additions & 0 deletions basics_of_logging_in_sst-core/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Use baseimage-docker which is a modified Ubuntu specifically for Docker
# https://hub.docker.com/r/phusion/baseimage
# https://github.com/phusion/baseimage-docker
FROM phusion/baseimage:0.11

# Use baseimage-docker's init system
CMD ["/sbin/my_init"]

# Update and install packages
RUN apt update && apt -y upgrade && apt -y install \
build-essential \
doxygen \
libtool-bin \
graphviz \
time \
mpich \
python3-dev \
python3-pip \
automake

# Clean up apt mess
RUN apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ARG USER=sst
ARG UID=1000
ARG GID=1000
# default password for user
ARG PW=sst

RUN useradd -m ${USER} --uid=${UID} && echo "${USER}:${PW}" | chpasswd

USER ${UID}:${GID}
WORKDIR /home/${USER}

# Setup Environment for SST
ARG dir=/home/sst/build
RUN mkdir -p $dir
ARG SST_CORE_HOME=/home/sst/sst-core
ENV SST_CORE_HOME=/home/sst/sst-core
ENV PATH="$PATH:$SST_CORE_HOME/bin"

WORKDIR $dir

#ARG SSTver=11.1.0
ARG SSTver=11.0.0

# from https://github.com/sstsimulator/sst-core/releases/tag/v11.0.0_Final
COPY sstcore-${SSTver}.tar.gz .
RUN tar zxvf sstcore-${SSTver}.tar.gz
RUN mv sstcore-${SSTver} sst-core

# Build SST Core
RUN cd $dir/sst-core && ./autogen.sh && \
./configure --prefix=$SST_CORE_HOME && \
make all install

# the following permissions change is necessary to address the problem that when the command
# sst-register example example_LIBDIR=/scratch/Example00
# gets run, there is an error message that says
# Unable to open configuration at either: /home/sst/sst-core/etc/sst/sstsimulator.conf or //.sst/sstsimulator.conf, one of these files must be editable.
RUN chmod o+w /home/sst/sst-core/etc/sst/sstsimulator.conf

WORKDIR /home/sst/

# Clean up SST junk
#RUN rm -rf $dir
97 changes: 97 additions & 0 deletions basics_of_logging_in_sst-core/Example00/ExampleComponent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Created for SST-Core Version (9.1.0)
//
#include "ExampleComponent.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "#include <sst_config.h>" before any other include.

See http://sst-simulator.org/SSTPages/SSTDeveloperCodingStandards/.

#include <iostream>

using namespace Example00;

// Component constructor.
//
ExampleComponent::ExampleComponent(SST::ComponentId_t id, SST::Params &params) :
SST::Component(id),
componentId_(id),
Copy link

@feldergast feldergast Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, you should avoid using or storing the component's id. If it were possible to make the id unavailable to the end component, we would have done that. The id should just be passed to the parent constructor. The id is a value that is generally meaningless to the end user because it is assigned opaquely by the core with no guarantees other than it is unique on each rank. In anything other than a trivial simulation, the number will not allow the user to know which component it refers to. And, while this is a trivial example, it is better not to teach this as something that is acceptable.

Better in this example would likely be to use the getName() function that exists in the BaseComponent API. This will return the name given to the component in the python file and will be meaningful to the end user.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above comment applies through all of the files that store the component id.

clockTickCount_(0)
{
// Read in the parameters from the python config file. See SST_ELI_DOCUMENT_PARAMS
// for an explanation of what each parameter represents.
//
std::string clock =
params.find<std::string>("clock", "1GHz");
clockTicks_ = static_cast<uint64_t>(
params.find<int>("clockTicks", 10));

// Create the logger.
//
logger_ = SST::Output("Time=@t; File=@f; Func=@p; Line=@l; Thread=@I -- ", TRACE, 0x00, SST::Output::STDOUT);
logger_.verbose(CALL_INFO, TRACE, 0x00, "Entering constructor for component id %lu\n", componentId_);

// Initialize the debug output instance.
// Strings for debug output use the printf format.
//
logger_.verbose(CALL_INFO, INFO, 0x00, "Initializing component %lu.\n", id);
logger_.verbose(CALL_INFO, DEBUG, 0x00, "Parameters successfully read from config file.\n");
logger_.verbose(CALL_INFO, DEBUG, 0x00, "clockTicks = %lu\n", clockTicks_);
logger_.verbose(CALL_INFO, INFO, 0x00, "Constructing new Example Instance.\n");

// Configure the component clock.
//
logger_.verbose(CALL_INFO, DEBUG, 0x00, "Clock rate is: %s\n", clock.c_str());
registerClock(clock,
new SST::Clock::Handler<ExampleComponent>(this, &ExampleComponent::clockTick));
logger_.verbose(CALL_INFO, INFO, 0x00, "Successfully initialized clock.\n");

// Register this component with the simulation.
//
registerAsPrimaryComponent();
logger_.verbose(CALL_INFO, DEBUG, 0x00, "Component registered as primary component.\n");
primaryComponentDoNotEndSim();
logger_.verbose(CALL_INFO, DEBUG, 0x00, "Simulation notified it should not end.\n");
logger_.verbose(CALL_INFO, TRACE, 0x00, "Leaving constructor for component id %lu\n", componentId_);
}


// Called after all components have been constructed and initialization
// has completed, but before simulation time has begin.
//
// This is where you should do any other initialization that needs done
// but could be accomplished in the constructure.
//
void ExampleComponent::setup(void)
{
logger_.verbose(CALL_INFO, TRACE, 0x00, "Entering setup for component id %lu\n", componentId_);
logger_.verbose(CALL_INFO, TRACE, 0x00, "Leaving setup for component id %lu\n", componentId_);
}


// Called after the simulation is complete but before the objects are
// destroyed. This is a good place to print out statistics.
//
void ExampleComponent::finish(void)
{
logger_.verbose(CALL_INFO, TRACE, 0x00, "Entering finish for component id %lu\n", componentId_);
logger_.verbose(CALL_INFO, TRACE, 0x00, "Leaving finish for component id %lu\n", componentId_);
}


// Clock event handler.
//
bool ExampleComponent::clockTick(SST::Cycle_t cycle)
{
logger_.verbose(CALL_INFO, TRACE, 0x00, "Entering clock for component id %lu\n", componentId_);

// Increment the clock tick counter and end when you get to
// the specified value.
//
clockTickCount_ += 1;
bool done = (clockTickCount_ == clockTicks_);

logger_.verbose(CALL_INFO, INFO, 0x00, "Clock tick count = %lu out of %lu\n", clockTickCount_, clockTicks_);
if (done)
{
logger_.verbose(CALL_INFO, INFO, 0x00, "Ending sim.\n");
primaryComponentOKToEndSim();
}

logger_.verbose(CALL_INFO, TRACE, 0x00, "Leaving clock for component id %lu\n", componentId_);
return done;
}
72 changes: 72 additions & 0 deletions basics_of_logging_in_sst-core/Example00/ExampleComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef MY_COMPONENT_H
#define MY_COMPONENT_H

#include <sst/core/component.h>
#include <sst/core/output.h>
#include <sst/core/params.h>

namespace Example00
{
// Define the log levels. Each level displays its own message and the
// levels above it.
//
#define FATAL 0
#define ERROR 100
#define WARN 200
#define INFO 300
#define DEBUG 400
#define TRACE 500

// This is a very simple component. It only registers a clock and
// prints log messages as the clock handler is called.
//
// Remember, all components inherit from SST::Component
//
class ExampleComponent : public SST::Component
{
public:
// Constructor/Destructor
//
ExampleComponent(SST::ComponentId_t id, SST::Params &params);
~ExampleComponent() {}

// Standard SST::Component functions. These all need to
// be implemented in the component, even if they are empty.
//
void setup(void);
void finish(void);

// Clock handler. This is the method called from the clock event.
//
bool clockTick(SST::Cycle_t cycle);

// Shared documentation macros.
//
SST_ELI_DOCUMENT_PARAMS(
{ "clock", "Component clock rate", "1GHz" },
{ "clockTicks", "Number of times the handler is called before ending.", "10" }
)

SST_ELI_REGISTER_COMPONENT(
ExampleComponent, // Class name
"example", // Library name (the *.so)
"ExampleComponent", // Name used to reference the component. This can be
// whatever you want it to be and will be referenced
// in the python configuration file.
SST_ELI_ELEMENT_VERSION( 1, 0, 0 ), // Version number
"Clock element example", // Description
COMPONENT_CATEGORY_UNCATEGORIZED // Component category
)

private:
// Member variables for this example.
//
SST::Output logger_; // For displaying log messages.
uint64_t componentId_; // SST supplied component id.
uint64_t clockTicks_; // Maximum number of clock ticks.
uint64_t clockTickCount_; // Clock ticks counter.

}; // Close the class
} // Close the namespace

#endif
19 changes: 19 additions & 0 deletions basics_of_logging_in_sst-core/Example00/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

CXX=$(shell sst-config --CXX)
CXXFLAGS=$(shell sst-config --ELEMENT_CXXFLAGS)
LDFLAGS=$(shell sst-config --ELEMENT_LDFLAGS)

all: libexample.so install

libexample.so: ExampleComponent.cc\
ExampleComponent.h
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $<

install:
sst-register example example_LIBDIR=$(CURDIR)

run:
sst tests/ExampleConfig.py

clean:
rm -f *.o libexample.so
3 changes: 3 additions & 0 deletions basics_of_logging_in_sst-core/Example00/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Example project for Simplified SST Logging

Shows logging with log levels defined by `#define`
27 changes: 27 additions & 0 deletions basics_of_logging_in_sst-core/Example00/tests/ExampleConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Execute from the command line with the command:
# sst Example00Config.py 2>&1 | tee test.log
#
import sst

# Initialize local variables.
#
clockTicks = "10" # Number of clock ticks before the simulation ends
clock = "1GHz" # Simulation clock rate

componentName0 = "example00"

# Define the component.
#
# The parameters are a dictionary and can be any key/value pair defined
# by the component itself.
#
# The second parameter is <library>.<registered_name>
# These correspond to the second and third parameters of the
# SST_ELI_REGISTER_COMPONENT macro in Example00Component.h,
# respectively.
#
obj = sst.Component(componentName0, "example.ExampleComponent")
obj.addParams({
"clock" : clock,
"clockTicks" : clockTicks,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
WARNING: Building component "example00" with no links assigned.
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=26; Thread=0 -- Entering constructor for component id 0
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=31; Thread=0 -- Initializing component 0.
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=32; Thread=0 -- Parameters successfully read from config file.
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=33; Thread=0 -- clockTicks = 10
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=34; Thread=0 -- Constructing new Example Instance.
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=38; Thread=0 -- Clock rate is: 1GHz
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=41; Thread=0 -- Successfully initialized clock.
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=46; Thread=0 -- Component registered as primary component.
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=48; Thread=0 -- Simulation notified it should not end.
Time=0; File=ExampleComponent.cc; Func=ExampleComponent; Line=49; Thread=0 -- Leaving constructor for component id 0
Time=0; File=ExampleComponent.cc; Func=setup; Line=61; Thread=0 -- Entering setup for component id 0
Time=0; File=ExampleComponent.cc; Func=setup; Line=62; Thread=0 -- Leaving setup for component id 0
Time=1000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=1000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 1 out of 10
Time=1000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=2000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=2000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 2 out of 10
Time=2000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=3000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=3000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 3 out of 10
Time=3000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=4000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=4000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 4 out of 10
Time=4000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=5000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=5000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 5 out of 10
Time=5000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=6000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=6000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 6 out of 10
Time=6000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=7000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=7000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 7 out of 10
Time=7000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=8000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=8000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 8 out of 10
Time=8000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=9000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=9000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 9 out of 10
Time=9000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=10000; File=ExampleComponent.cc; Func=clockTick; Line=80; Thread=0 -- Entering clock for component id 0
Time=10000; File=ExampleComponent.cc; Func=clockTick; Line=88; Thread=0 -- Clock tick count = 10 out of 10
Time=10000; File=ExampleComponent.cc; Func=clockTick; Line=91; Thread=0 -- Ending sim.
Time=10000; File=ExampleComponent.cc; Func=clockTick; Line=95; Thread=0 -- Leaving clock for component id 0
Time=10000; File=ExampleComponent.cc; Func=finish; Line=71; Thread=0 -- Entering finish for component id 0
Time=10000; File=ExampleComponent.cc; Func=finish; Line=72; Thread=0 -- Leaving finish for component id 0
Simulation is complete, simulated time: 10 ns
Loading