From 492bc7f791ae8897a7ae5c73187fb69b0b475083 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 24 Jul 2024 12:53:24 +0200 Subject: [PATCH 1/2] Add likwid --- cmake/FindLIKWID.cmake | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 cmake/FindLIKWID.cmake diff --git a/cmake/FindLIKWID.cmake b/cmake/FindLIKWID.cmake new file mode 100644 index 0000000..70e5cad --- /dev/null +++ b/cmake/FindLIKWID.cmake @@ -0,0 +1,79 @@ +#[=======================================================================[.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}) + else() + message(FATAL_ERROR "FindLIKWID: Couldn't auto-detect LIKWID_DIR, please provide the installation location of LIKWID with -DLIKWID_DIR=") + 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.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) -- GitLab From 1d4efc6fafa7322122e0f2e2d36e4a81dccf8fde Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 24 Jul 2024 15:59:41 +0200 Subject: [PATCH 2/2] Add likwid --- CMakeLists.txt | 15 +++++++++++++++ cmake/FindLIKWID.cmake | 6 ++---- src/backends/CMakeLists.txt | 4 ++++ src/backends/likwid/CMakeLists.txt | 1 + src/backends/likwid/likwid.cpp | 28 ++++++++++++++++++++++++++++ src/backends/likwid/likwid.hpp | 18 ++++++++++++++++++ src/delegator.cpp | 9 +++++++++ 7 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/backends/likwid/CMakeLists.txt create mode 100644 src/backends/likwid/likwid.cpp create mode 100644 src/backends/likwid/likwid.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8105169..e9f2cfa 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 index 70e5cad..cc1b677 100644 --- a/cmake/FindLIKWID.cmake +++ b/cmake/FindLIKWID.cmake @@ -37,8 +37,6 @@ if(NOT LIKWID_DIR) 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}) - else() - message(FATAL_ERROR "FindLIKWID: Couldn't auto-detect LIKWID_DIR, please provide the installation location of LIKWID with -DLIKWID_DIR=") endif() endif() @@ -49,13 +47,13 @@ if(DEFINED LIKWID_LIB) PATH_SUFFIXES lib lib64) else() find_library(LIKWID_LIBRARY - NAMES LIKWID + NAMES likwid HINTS ${LIKWID_DIR} PATH_SUFFIXES lib lib64) endif() find_path(LIKWID_INCLUDE_DIR - NAMES LIKWID.h + NAMES likwid-marker.h PATHS ${LIKWID_DIR} PATH_SUFFIXES include ) diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index ccb0564..18923d3 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 0000000..566e518 --- /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 0000000..9a06575 --- /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 0000000..ec14204 --- /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 60f68f5..7d93655 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(); -- GitLab