Skip to content

Commit

Permalink
Score-P now external as it should be
Browse files Browse the repository at this point in the history
  • Loading branch information
rschoene committed Sep 27, 2024
1 parent 413c4c4 commit 136cdd1
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()

set(FIRESTARTER_TRACING "None" CACHE STRING "FIRESTARTER_TRACING can be any of None, Logger, or ScoreP. This feature is currently under development and static linking might not work.")
set_property(CACHE FIRESTARTER_TRACING PROPERTY STRINGS None Logger ScoreP VampirTrace)
set_property(CACHE FIRESTARTER_TRACING PROPERTY STRINGS None Logger ScoreP External)

set(FIRESTARTER_TRACING_CXX_FLAGS "" CACHE STRING "FIRESTARTER_TRACING_CXX_FLAGS should add include paths for the selected tracing infrastructure.")
set(FIRESTARTER_TRACING_LD_FLAGS "" CACHE STRING "FIRESTARTER_TRACING_LD_FLAGS should set linker flags for the selected tracing infrastructure.")
Expand Down
20 changes: 20 additions & 0 deletions examples/tracing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# In this folder, there are examples on how one could include tracing with an external library

Since these will be mostly shared libraries, we probably will only be able to use them with a dynamic build of FIRESTARTER

## Example 1: Score-P

- Needs Score-P: https://www.vi-hps.org/projects/score-p
- File: `scorep.c`
- Compilation:
- 1. create the adapter configuration: `scorep-config --adapter-init --dynamic --user --nokokkos --nocompiler --thread=pthread > .scorep_init.c`
- 2. compile the adapter and the tracing library: `scorep --user --nocompiler --dynamic --nokokkos --noopenmp --thread=pthread gcc -fPIC -c -DSCOREP_USER_ENABLE scorep.c .scorep_init.c`
- 3. link the tracing library: `scorep --no-as-needed --dynamic --user --nokokkos --nocompiler --noopenmp --thread=pthread gcc -shared -o libfirestarter_scorep.so scorep.o .scorep_init.o`
- 4. cmake FIRESTARTER: `cmake -DFIRESTARTER_TRACING=External -DFIRESTARTER_TRACING_LD_FLAGS="-L/home/rschoene/git/FIRESTARTER/examples/tracing -lfirestarter_scorep" -DFIRESTARTER_LINK_STATIC=OFF ..`
- 5. make FIRESTARTER: `make -j`

- Running:
- Make sure that the library `libfirestarter_scorep.so` can be found in the `LD_LIBRARY_PATH`
- Run `FIRESTARTER` as usual
- Running `FIRESTARTER` should create a profile in your current directory starting with `scorep...`
- You can change environment variables to tune Score-P for your purposes. Have a look at: https://perftools.pages.jsc.fz-juelich.de/cicd/scorep/tags/latest/pdf/scorep.pdf
35 changes: 35 additions & 0 deletions examples/tracing/scorep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/******************************************************************************
* FIRESTARTER - A Processor Stress Test Utility
* Copyright (C) 2024 TU Dresden, Center for Information Services and High
* Performance Computing
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/\>.
*
* Contact: [email protected]
*****************************************************************************/

#include "../../include/firestarter/Tracing/FIRESTARTER_External_Tracing.h"
#include <scorep/SCOREP_User.h>

void firestarter_tracing_initialize(int argc, const char **argv) {
}

void firestarter_tracing_region_begin(char const* region_name) {
SCOREP_USER_REGION_BY_NAME_BEGIN(region_name,
SCOREP_USER_REGION_TYPE_COMMON);
}

void firestarter_tracing_region_end(char const* region_name) {
SCOREP_USER_REGION_BY_NAME_END(region_name);
}
32 changes: 32 additions & 0 deletions include/firestarter/Tracing/FIRESTARTER_Tracing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
* FIRESTARTER - A Processor Stress Test Utility
* Copyright (C) 2024 TU Dresden, Center for Information Services and High
* Performance Computing
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/\>.
*
* Contact: [email protected]
*****************************************************************************/

#pragma once

#ifdef FIRESTARTER_TRACING
void firestarter_tracing_initialize(int argc, const char **argv);
void firestarter_tracing_region_begin(char const* region_name);
void firestarter_tracing_region_end(char const* region_name);
#else
#define firestarter_tracing_initialize(argc, argv) {}
#define firestarter_tracing_region_begin(region_name) {}
#define firestarter_tracing_region_end(region_name) {}
#endif
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ elseif(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER")
endif()

if(NOT "${FIRESTARTER_TRACING}" STREQUAL "None")
string(STRIP "${FIRESTARTER_TRACING_LDFLAGS}" FIRESTARTER_TRACING_LDFLAGS)
string(STRIP "${FIRESTARTER_TRACING_LD_FLAGS}" FIRESTARTER_TRACING_LD_FLAGS)
target_link_libraries("${FIRESTARTER_BUILD_TYPE}"
"${FIRESTARTER_TRACING_LDFLAGS}"
"${FIRESTARTER_TRACING_LD_FLAGS}"
)
endif()

message(STATUS "FIRESTARTER_TRACING_LD_FLAGS: ${FIRESTARTER_TRACING_LD_FLAGS}")
39 changes: 16 additions & 23 deletions src/firestarter/Firestarter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

#include <firestarter/Firestarter.hpp>
#include <firestarter/Logging/Log.hpp>
#include <firestarter/Tracing/Tracing.hpp>

extern "C" {
#include <firestarter/Tracing/FIRESTARTER_Tracing.h>
}

#if defined(linux) || defined(__linux__)
#include <firestarter/Optimizer/Algorithm/NSGA2.hpp>
#include <firestarter/Optimizer/History.hpp>
Expand Down Expand Up @@ -326,9 +330,9 @@ Firestarter::~Firestarter() {
}

void Firestarter::mainThread() {
#ifdef FIRESTARTER_TRACING
firestarter::tracing::regionBegin("Main-Thread");
#endif

firestarter_tracing_region_begin("Main-Thread");
this->environment().printThreadSummary();

#if defined(FIRESTARTER_BUILD_CUDA) || defined(FIRESTARTER_BUILD_HIP)
Expand Down Expand Up @@ -356,9 +360,7 @@ void Firestarter::mainThread() {
int returnCode;
if (EXIT_SUCCESS != (returnCode = this->initDumpRegisterWorker(
_dumpRegistersTimeDelta, _dumpRegistersOutpath))) {
#ifdef FIRESTARTER_TRACING
firestarter::tracing::regionEnd("Main-Thread");
#endif
firestarter_tracing_region_end("Main-Thread");
std::exit(returnCode);
}
}
Expand All @@ -370,9 +372,7 @@ void Firestarter::mainThread() {
#if defined(linux) || defined(__linux__)
// check if optimization is selected
if (_optimize) {
#ifdef FIRESTARTER_TRACING
firestarter::tracing::regionBegin("Main-Thread-Optimize");
#endif
firestarter_tracing_region_begin("Main-Thread-Optimize");
auto startTime = optimizer::History::getTime();

Firestarter::_optimizer = std::make_unique<optimizer::OptimizerWorker>(
Expand All @@ -391,12 +391,9 @@ void Firestarter::mainThread() {
firestarter::optimizer::History::printBest(_optimizationMetrics,
payloadItems);

#ifdef FIRESTARTER_TRACING
firestarter::tracing::regionEnd("Main-Thread-Optimize");
#endif
#ifdef FIRESTARTER_TRACING
firestarter::tracing::regionEnd("Main-Thread");
#endif

firestarter_tracing_region_end("Main-Thread-Optimize");
firestarter_tracing_region_end("Main-Thread");

// stop all the load threads
std::raise(SIGTERM);
Expand Down Expand Up @@ -433,9 +430,7 @@ void Firestarter::mainThread() {
this->printThreadErrorReport();
}

#ifdef FIRESTARTER_TRACING
firestarter::tracing::regionEnd("Main-Thread");
#endif
firestarter_tracing_region_end("Main-Thread");
}

void Firestarter::setLoad(unsigned long long value) {
Expand All @@ -458,12 +453,10 @@ void Firestarter::sigalrmHandler(int signum) { (void)signum; }
void Firestarter::sigtermHandler(int signum) {
(void)signum;

#ifdef FIRESTARTER_TRACING
if (Firestarter::loadVar == LOAD_LOW)
firestarter::tracing::regionEnd("WD_LOW");
firestarter_tracing_region_end("WD_LOW");
if (Firestarter::loadVar == LOAD_HIGH)
firestarter::tracing::regionEnd("WD_HIGH");
#endif
firestarter_tracing_region_end("WD_HIGH");

Firestarter::setLoad(LOAD_STOP);
// exit loop
Expand Down
28 changes: 10 additions & 18 deletions src/firestarter/LoadWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@
#include <firestarter/ErrorDetectionStruct.hpp>
#include <firestarter/Firestarter.hpp>
#include <firestarter/Logging/Log.hpp>
#include <firestarter/Tracing/Tracing.hpp>

extern "C" {
#include <firestarter/Tracing/FIRESTARTER_Tracing.h>
}

#if defined(linux) || defined(__linux__)
extern "C" {
#include <firestarter/Measurement/Metric/IPCEstimate.h>
}
#endif

#ifdef ENABLE_VTRACING
#include <vt_user.h>
#endif
#ifdef ENABLE_SCOREP
#include <SCOREP_User.h>
#endif

#include <cmath>
#include <cstdlib>
Expand Down Expand Up @@ -352,24 +349,19 @@ void Firestarter::loadThreadWorker(std::shared_ptr<LoadWorkerData> td) {
for (;;) {
// call high load function

#ifdef FIRESTARTER_TRACING
tracing::regionBegin("High");
#endif
firestarter_tracing_region_begin("High");

td->iterations = td->config().payload().highLoadFunction(
td->addrMem, td->addrHigh, td->iterations);

#ifdef FIRESTARTER_TRACING
tracing::regionEnd("High");
tracing::regionBegin("Low");
#endif
firestarter_tracing_region_end("High");
firestarter_tracing_region_begin("Low");

// call low load function
td->config().payload().lowLoadFunction(td->addrHigh, td->period);

#ifdef FIRESTARTER_TRACING
tracing::regionEnd("Low");
#endif

firestarter_tracing_region_end("Low");

// terminate if master signals end of run and record stop timestamp
if (*td->addrHigh == LOAD_STOP) {
td->stopTsc = td->environment().topology().timestamp();
Expand Down
9 changes: 5 additions & 4 deletions src/firestarter/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

#include <firestarter/Firestarter.hpp>
#include <firestarter/Logging/Log.hpp>
#include <firestarter/Tracing/Tracing.hpp>

extern "C" {
#include <firestarter/Tracing/FIRESTARTER_Tracing.h>
}

#include <cxxopts.hpp>

Expand Down Expand Up @@ -469,9 +472,7 @@ int main(int argc, const char **argv) {
"Computing"
<< "\n";

#ifdef FIRESTARTER_TRACING
firestarter::tracing::initialize(argc, argv);
#endif
firestarter_tracing_initialize(argc, argv);

Config cfg{argc, argv};

Expand Down
40 changes: 40 additions & 0 deletions src/firestarter/Tracing/External.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/******************************************************************************
* FIRESTARTER - A Processor Stress Test Utility
* Copyright (C) 2024 TU Dresden, Center for Information Services and High
* Performance Computing
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/\>.
*
* Contact: [email protected]
*****************************************************************************/


extern "C" {
#include <firestarter/Tracing/FIRESTARTER_External_Tracing.h>
}


#include <firestarter/Tracing/Tracing.hpp>

void firestarter::tracing::initialize(int argc, const char **argv){
firestarter_tracing_initialize(argc, argv);
}

void firestarter::tracing::regionBegin(char const* region_name) {
firestarter_tracing_region_begin(region_name);
}

void firestarter::tracing::regionEnd(char const* region_name) {
firestarter_tracing_region_begin(region_name);
}
13 changes: 7 additions & 6 deletions src/firestarter/Tracing/LogTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@


#include <firestarter/Logging/Log.hpp>
#include <firestarter/Tracing/Tracing.hpp>
#include <firestarter/Tracing/FIRESTARTER_Tracing.h>

void firestarter::tracing::initialize(int argc, const char **argv){
#ifdef FIRESTARTER_TRACING
void firestarter_tracing_initialize(int argc, const char **argv){

}

void firestarter::tracing::regionBegin(char const* region_name) {
void firestarter_tracing_region_begin(char const* region_name) {
firestarter::log::trace() << "Start " << region_name;
}

void firestarter::tracing::regionEnd(char const* region_name) {
void firestarter_tracing_region_end(char const* region_name) {
firestarter::log::trace() << "End " << region_name;
}
}
#endif
Loading

0 comments on commit 136cdd1

Please sign in to comment.