diff --git a/CMakeLists.txt b/CMakeLists.txt index 81051690488af14b1d9aa46d17a7ec2e80f47493..e9f2cfa94bf9979f33257c326a398d1bf07b4045 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Available backend options option(ENABLE_EXTRAE "Enable Extrae" OFF) option(ENABLE_DLB "Enable DLB" OFF) +option(ENABLE_LIKWID "Enable likwid" OFF) # other options options option(BUILD_C_FORTRAN "Enable C and Fortran Interfaces" ON) @@ -85,6 +86,20 @@ if(ENABLE_DLB) endif() endif() +if(ENABLE_LIKWID) + find_package(LIKWID REQUIRED) + if(LIKWID_FOUND) + target_include_directories(nesmik + PRIVATE ${LIKWID_INCLUDE_DIRS}) + # We link publicy with seqtrace, as we need it to be in the right order to libc to find malloc with dlsym .. + target_link_libraries(nesmik PUBLIC ${LIKWID_LIBRARIES}) + target_compile_definitions(nesmik PRIVATE "ENABLE_LIKWID") + target_compile_definitions(nesmik PRIVATE "LIKWID_PERFMON") + else() + message(FATAL_ERROR "Couldn't find likwid") + endif() +endif() + include(FetchContent) diff --git a/cmake/FindLIKWID.cmake b/cmake/FindLIKWID.cmake new file mode 100644 index 0000000000000000000000000000000000000000..cc1b677fad61cad51d81234048b5254124d9dfd1 --- /dev/null +++ b/cmake/FindLIKWID.cmake @@ -0,0 +1,77 @@ +#[=======================================================================[.rst: +FindLIKWID +------- + +Finds the LIKWID library. https://github.com/RRZE-HPC/LIKWID + +Imported Targets +^^^^^^^^^^^^^^^^ +This module provides the following imported targets, if found: + The LIKWID library + +Result Variables +^^^^^^^^^^^^^^^^ +This will define the following variables: + +``LIKWID_FOUND`` + True if the system has the LIKWID library. +``LIKWID_DIR`` + The root directory of the LIKWID library. +``LIKWID_INCLUDE_DIRS`` + Include directories needed to use LIKWID. +``LIKWID_LIBRARIES`` + Libraries needed to link to LIKWID. + +Cache Variables +^^^^^^^^^^^^^^^ +The following cache variables may also be set: + +``LIKWID_DIR`` + The root directory. +#]=======================================================================] + +if(NOT LIKWID_DIR) + if(DEFINED ENV{LIKWID_HOME}) + message(STATUS "FindLIKWID: LIKWID_DIR not explicitly set, using LIKWID_HOME set to: $ENV{LIKWID_HOME}") + set(LIKWID_DIR $ENV{LIKWID_HOME} ) + elseif(DEFINED ENV{LIKWID_ROOT}) + message(STATUS "FindLIKWID: LIKWID_DIR not explicitly set, using LIKWID_ROOT set to: $ENV{LIKWID_ROOT}") + set(LIKWID_DIR $ENV{LIKWID_ROOT}) + endif() +endif() + +if(DEFINED LIKWID_LIB) + find_library(LIKWID_LIBRARY + NAMES ${LIKWID_LIB} + HINTS ${LIKWID_DIR} + PATH_SUFFIXES lib lib64) +else() + find_library(LIKWID_LIBRARY + NAMES likwid + HINTS ${LIKWID_DIR} + PATH_SUFFIXES lib lib64) +endif() + +find_path(LIKWID_INCLUDE_DIR + NAMES likwid-marker.h + PATHS ${LIKWID_DIR} + PATH_SUFFIXES include + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LIKWID + REQUIRED_VARS + LIKWID_LIBRARY + LIKWID_INCLUDE_DIR + ) + +if(LIKWID_FOUND) + set(LIKWID_LIBRARIES ${LIKWID_LIBRARY}) + set(LIKWID_INCLUDE_DIRS ${LIKWID_INCLUDE_DIR}) +endif() + +if(NOT LIKWID_FOUND) + message(FATAL_ERROR "FindLIKWID: Did not find required library LIKWID") +endif() + +mark_as_advanced(LIKWID_DIR) diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index ccb0564a5397f6b7b703b2413df47dfe5f484d72..18923d3b06e936361bc8bba67d7fb7095b21c5b5 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -7,3 +7,7 @@ endif() if(ENABLE_EXTRAE) add_subdirectory(extrae) endif() + +if(ENABLE_LIKWID) + add_subdirectory(likwid) +endif() diff --git a/src/backends/likwid/CMakeLists.txt b/src/backends/likwid/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..566e518dc68cea919a1d2369f6775b04a602ea7a --- /dev/null +++ b/src/backends/likwid/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(nesmik PRIVATE likwid.cpp) diff --git a/src/backends/likwid/likwid.cpp b/src/backends/likwid/likwid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9a0657585915d59ffb1fd55c70c0f89c54a94019 --- /dev/null +++ b/src/backends/likwid/likwid.cpp @@ -0,0 +1,28 @@ +#include "likwid.hpp" + +extern "C" { +#include +} + +#include + +LIKWIDStrategy::LIKWIDStrategy() { + parallelism_descriptor_ = {.mpi_descriptor_ = MPIDescriptor::DontCare, + .thread_descriptor_ = ThreadDescriptor::Supported}; +} + +void LIKWIDStrategy::RegionStart( + const NotProperlyNestedRegionInformation ®ion) noexcept { + auto error = likwid_markerStartRegion(std::string(region.name).c_str()); +} + +void LIKWIDStrategy::RegionStop( + const NotProperlyNestedRegionInformation ®ion) noexcept { + auto error = likwid_markerStopRegion(std::string(region.name).c_str()); +} + +void LIKWIDStrategy::Init() noexcept { + likwid_markerInit(); + // TODO find out if we want to add OpenMP here to do the thread init +} +void LIKWIDStrategy::Finalize() noexcept { likwid_markerClose(); } diff --git a/src/backends/likwid/likwid.hpp b/src/backends/likwid/likwid.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ec14204880f8aeaf9b43525cb8628c8750f5807a --- /dev/null +++ b/src/backends/likwid/likwid.hpp @@ -0,0 +1,18 @@ +#ifndef NESMIK_LIKWID_H +#define NESMIK_LIKWID_H + +#include +#include + +class LIKWIDStrategy : public NotProperlyNestedAnnotationStrategy { + public: + LIKWIDStrategy(); + inline static const std::string name = "LIKWID"; + virtual void RegionStart( + const NotProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStop( + const NotProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept override; + virtual void Finalize() noexcept override; +}; +#endif // NESMIK_LIKWID_H diff --git a/src/delegator.cpp b/src/delegator.cpp index 60f68f55374260eb8eba5af1cfc61f344c4d57ac..7d9365587355f8b43fb726af665ec09563d2db30 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -19,6 +19,10 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif +#ifdef ENABLE_LIKWID +#include "backends/likwid/likwid.hpp" +#endif + void Delegator::InitDetectionBackend(const std::string &backend) { pn_annotation_strategy_ = std::make_unique(); } @@ -33,6 +37,11 @@ void Delegator::InitNonProperlyNestedBackends(const std::string &backend) { else if (backend.compare(DLBTalpStrategy::name) == 0) { npn_annotation_strategy_ = std::make_unique(); } +#endif +#ifdef ENABLE_LIKWID + else if (backend.compare(LIKWIDStrategy::name) == 0) { + npn_annotation_strategy_ = std::make_unique(); + } #endif else { npn_annotation_strategy_ = std::make_unique();