Skip to content

Commit

Permalink
fixed tracing. Now it finds scorep (if avail) and can compile (even t…
Browse files Browse the repository at this point in the history
…hough not with static)
  • Loading branch information
rschoene committed Sep 26, 2024
1 parent 9b4cff2 commit 0946cd2
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 25 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ endif()
set(FIRESTARTER_TRACING "None" CACHE STRING "FIRESTARTER_TRACING can be any of None, Logger, ScoreP, or VampirTrace.")
set_property(CACHE FIRESTARTER_TRACING PROPERTY STRINGS None Logger ScoreP VampirTrace)

option(FIRESTARTER_TRACING_CXX_FLAGS "FIRESTARTER_TRACING_CXX_FLAGS should add include paths for the selected tracing infrastructure." "${FIRESTARTER_TRACING_CXX_FLAGS}")
option(FIRESTARTER_TRACING_LD_FLAGS "FIRESTARTER_TRACING_LD_FLAGS should set linker flags for the selected tracing infrastructure." "${FIRESTARTER_TRACING_CXX_FLAGS}")
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.")
set(FIRESTARTER_TRACING_ADDITIONAL_FILES "" CACHE STRING "FIRESTARTER_TRACING_ADDITIONAL_FILES can be used to add files to the compilation process that are needed for tracing.")


set(FIRESTARTER_BUILD_TYPE "FIRESTARTER" CACHE STRING "FIRESTARTER_BUILD_TYPE can be any of FIRESTARTER, FIRESTARTER_CUDA, FIRESTARTER_ONEAPI, or FIRESTARTER_HIP.")
set_property(CACHE FIRESTARTER_BUILD_TYPE PROPERTY STRINGS FIRESTARTER FIRESTARTER_CUDA FIRESTARTER_ONEAPI)
Expand Down
90 changes: 72 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ endif()

if(NOT "${FIRESTARTER_TRACING}" STREQUAL "None")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_TRACING")
SET(FIRESTARTER_FILES
${FIRESTARTER_FILES}
${FIRESTARTER_TRACING_ADDITIONAL_FILES}
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FIRESTARTER_TRACING_CXXFLAGS}")
endif()

if("${FIRESTARTER_TRACING}" STREQUAL "Logger")
Expand All @@ -51,12 +56,69 @@ if("${FIRESTARTER_TRACING}" STREQUAL "Logger")
firestarter/Tracing/LogTracing.cpp
)
elseif("${FIRESTARTER_TRACING}" STREQUAL "ScoreP")
SET(FIRESTARTER_FILES
${FIRESTARTER_FILES}
firestarter/Tracing/ScoreP.cpp
)
#todo find folder
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSCOREP_USER_ENABLE ${FIRESTARTER_TRACING_CXXFLAGS}")
find_program(SCOREP_CONFIG scorep-config)
if(SCOREP_CONFIG)
message(STATUS "Found 'scorep-config' at: ${SCOREP_CONFIG}")
SET(FIRESTARTER_FILES
${FIRESTARTER_FILES}
firestarter/Tracing/ScoreP.cpp
${FIRESTARTER_TRACING_ADDITIONAL_FILES}
)
SET(SCOREP_CONFIG_FLAGS "--nocompiler" "--user" "--nopomp" "--thread=pthread")
if ("${FIRESTARTER_LINK_STATIC}")
SET(SCOREP_CONFIG_FLAGS "--nocompiler" "--user" "--nopomp" "--thread=pthread" "--static")
endif()
execute_process(
COMMAND ${SCOREP_CONFIG} --cppflags
OUTPUT_VARIABLE SCOREP_CPP_FLAGS
ERROR_VARIABLE PROGRAM_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (PROGRAM_ERROR)
message(FATAL_ERROR "Error when calling scorep-config: ${PROGRAM_ERROR}")
endif()

execute_process(
COMMAND ${SCOREP_CONFIG} --adapter-init ${SCOREP_CONFIG_FLAGS}
OUTPUT_VARIABLE SCOREP_ADAPTER_INIT_CONTENT
ERROR_VARIABLE PROGRAM_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (PROGRAM_ERROR)
message(FATAL_ERROR "Error when calling scorep-config: ${PROGRAM_ERROR}")
endif()

file(WRITE ${CMAKE_BINARY_DIR}/.scorep_init.c "${SCOREP_ADAPTER_INIT_CONTENT}\n")
SET(FIRESTARTER_FILES
${FIRESTARTER_FILES}
${CMAKE_BINARY_DIR}/.scorep_init.c
)

execute_process(
COMMAND ${SCOREP_CONFIG} --ldflags "--nocompiler" "--user" "--nopomp"
OUTPUT_VARIABLE SCOREP_LD_FLAGS
ERROR_VARIABLE PROGRAM_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (PROGRAM_ERROR)
message(FATAL_ERROR "Error when calling scorep-config: ${PROGRAM_ERROR}")
endif()

execute_process(
COMMAND ${SCOREP_CONFIG} --libs ${SCOREP_CONFIG_FLAGS}
OUTPUT_VARIABLE SCOREP_LIBS
ERROR_VARIABLE PROGRAM_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (PROGRAM_ERROR)
message(FATAL_ERROR "Error when calling scorep-config: ${PROGRAM_ERROR}")
endif()

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSCOREP_USER_ENABLE ${SCOREP_CPP_FLAGS}")
SET(FIRESTARTER_TRACING_LDFLAGS "${FIRESTARTER_TRACING_LDFLAGS} ${SCOREP_LD_FLAGS} ${SCOREP_LIBS}")
else()
message(FATAL_ERROR "You want to compile with Score-P support, but scorep-config could not be found in PATH")
endif()
elseif("${FIRESTARTER_TRACING}" STREQUAL "VampirTrace")
SET(FIRESTARTER_FILES
${FIRESTARTER_FILES}
Expand All @@ -73,10 +135,6 @@ elseif("${FIRESTARTER_TRACING}" STREQUAL "Caliper")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FIRESTARTER_TRACING_CXXFLAGS}")
endif()


SET(FIRESTARTER_LINK_LIBRARIES
)

if (FIRESTARTER_THREAD_AFFINITY)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_THREAD_AFFINITY")
endif()
Expand Down Expand Up @@ -264,14 +322,10 @@ elseif(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER")
nlohmann_json::nlohmann_json
)
endif()
if("${FIRESTARTER_TRACING}" STREQUAL "ScoreP")
#todo link scorep
target_link_libraries("${FIRESTARTER_BUILD_TYPE}"
"${FIRESTARTER_TRACING_LDFLAGS}"
)
elseif("${FIRESTARTER_TRACING}" STREQUAL "VampirTrace")
#todo link vt user

if(NOT "${FIRESTARTER_TRACING}" STREQUAL "None")
string(STRIP "${FIRESTARTER_TRACING_LDFLAGS}" FIRESTARTER_TRACING_LDFLAGS)
target_link_libraries("${FIRESTARTER_BUILD_TYPE}"
"${FIRESTARTER_TRACING_LDFLAGS}"
)
endif()
endif()
8 changes: 8 additions & 0 deletions src/firestarter/Firestarter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <firestarter/Firestarter.hpp>
#include <firestarter/Logging/Log.hpp>
#include <firestarter/Tracing/Tracing.hpp>
#if defined(linux) || defined(__linux__)
#include <firestarter/Optimizer/Algorithm/NSGA2.hpp>
#include <firestarter/Optimizer/History.hpp>
Expand Down Expand Up @@ -457,6 +458,13 @@ 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");
if (Firestarter::loadVar == LOAD_HIGH)
firestarter::tracing::regionEnd("WD_HIGH");
#endif

Firestarter::setLoad(LOAD_STOP);
// exit loop
// used in case of 0 < load < 100
Expand Down
3 changes: 2 additions & 1 deletion src/firestarter/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

#include <cxxopts.hpp>

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

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

Config cfg{argc, argv};
Expand Down
2 changes: 1 addition & 1 deletion src/firestarter/Tracing/Caliper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <adiak.hpp>
#include <caliper/cali.h>

void firestarter::tracing::rinitialize(int argc, const char **argv){
void firestarter::tracing::initialize(int argc, const char **argv){
// Single adiak call to collect default adiak values
adiak::init(NULL);
adiak::uid();
Expand Down
3 changes: 2 additions & 1 deletion src/firestarter/Tracing/LogTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
#include <firestarter/Logging/Log.hpp>
#include <firestarter/Tracing/Tracing.hpp>

void firestarter::tracing::rinitialize(int argc, const char **argv){
void firestarter::tracing::initialize(int argc, const char **argv){

}

void firestarter::tracing::regionBegin(char const* region_name) {
firestarter::log::trace() << "Start " << region_name;
}
Expand Down
3 changes: 2 additions & 1 deletion src/firestarter/Tracing/ScoreP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

#include <firestarter/Tracing/Tracing.hpp>

void firestarter::tracing::rinitialize(int argc, const char **argv){
void firestarter::tracing::initialize(int argc, const char **argv){

}

void firestarter::tracing::regionBegin(char const* region_name) {
SCOREP_USER_REGION_BY_NAME_BEGIN(region_name,
SCOREP_USER_REGION_TYPE_COMMON);
Expand Down
3 changes: 2 additions & 1 deletion src/firestarter/Tracing/VampirTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#include <vt_user.h>
#include <firestarter/Tracing/Tracing.hpp>

void firestarter::tracing::rinitialize(int argc, const char **argv){
void firestarter::tracing::initialize(int argc, const char **argv){

}

void firestarter::tracing::regionBegin(char const* region_name) {
VT_USER_START(region_name);
}
Expand Down
7 changes: 7 additions & 0 deletions src/firestarter/WatchdogWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*****************************************************************************/

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

#include <cerrno>
#include <csignal>
Expand Down Expand Up @@ -138,6 +139,12 @@ int Firestarter::watchdogWorker(std::chrono::microseconds period,
Firestarter::_watchdogTerminateAlert.wait_for(
lk, timeout, []() { return Firestarter::_watchdog_terminate; });
}
#ifdef FIRESTARTER_TRACING
if (Firestarter::loadVar == LOAD_LOW)
firestarter::tracing::regionEnd("WD_LOW");
if (Firestarter::loadVar == LOAD_HIGH)
firestarter::tracing::regionEnd("WD_HIGH");
#endif

this->setLoad(LOAD_STOP);

Expand Down

0 comments on commit 0946cd2

Please sign in to comment.