From 1f001c742dc1e0f9eaf1134e02edc4c0e889ad4c Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 28 May 2024 15:55:12 +0200 Subject: [PATCH 1/6] Added intital dlb backend code --- src/backends/dlb/dlb.cpp | 20 ++++++++++++++------ src/backends/dlb/dlb.hpp | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backends/dlb/dlb.cpp b/src/backends/dlb/dlb.cpp index 4521a7f..c37ce5b 100644 --- a/src/backends/dlb/dlb.cpp +++ b/src/backends/dlb/dlb.cpp @@ -1,15 +1,23 @@ #include "dlb.hpp" - +#include "dlb.h" class DLBTalpStrategy : public SITProfilingStrategy { public: inline static const std::string_view name = "DLB"; - void - region_start(const SITRegionInformation ®ion) const noexcept override {} - void region_stop(const SITRegionInformation ®ion) const noexcept override { + void region_start(const SITRegionInformation ®ion) const noexcept override { + auto handle = DLB_MonitoringRegionRegister(region.name.c_str()); + DLB_MonitoringRegionStart(handle); } + void region_stop(const SITRegionInformation ®ion) const noexcept override { + auto handle = DLB_MonitoringRegionRegister(region.name.c_str()); + DLB_MonitoringRegionStop(handle); + } - virtual void init() const noexcept {} - virtual void finalize() const noexcept {} + virtual void init() const noexcept { + std::cout << "SIT::" < Date: Tue, 28 May 2024 15:58:28 +0200 Subject: [PATCH 2/6] added cmake stuff --- cmake/FindDLB.cmake | 76 +++++++++++++++++++++++++++++++++ src/backends/dlb/CMakeLists.txt | 9 +++- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 cmake/FindDLB.cmake diff --git a/cmake/FindDLB.cmake b/cmake/FindDLB.cmake new file mode 100644 index 0000000..590d7e7 --- /dev/null +++ b/cmake/FindDLB.cmake @@ -0,0 +1,76 @@ +#[=======================================================================[.rst: +FindDLB +------- + +Finds the DLB library. (https://pm.bsc.es/dlb) + +Imported Targets +^^^^^^^^^^^^^^^^ +This module provides the following imported targets, if found: + The DLB library + +Result Variables +^^^^^^^^^^^^^^^^ +This will define the following variables: + +``DLB_FOUND`` + True if the system has the DLB library. +``DLB_DIR`` + The root directory of the DLB library. +``DLB_INCLUDE_DIRS`` + Include directories needed to use DLB. +``DLB_LIBRARIES`` + Libraries needed to link to DLB. + +Cache Variables +^^^^^^^^^^^^^^^ +The following cache variables may also be set: + +``DLB_DIR`` + The root directory. +#]=======================================================================] + +if(NOT DLB_DIR) + if(DEFINED ENV{DLB_HOME}) + message(STATUS "FindDLB: DLB_DIR not explicity set, using DLB_HOME set to: $ENV{DLB_HOME}") + set(DLB_DIR $ENV{DLB_HOME} ) + else() + message(FATAL_ERROR "FindDLB: Couldn't auto-detect DLB_DIR, please provide the installation location of DLB with -DDLB_DIR=") + endif() +endif() + +if(DEFINED DLB_LIB) + find_library(DLB_LIBRARY + NAMES ${DLB_LIB} + HINTS ${DLB_DIR} + PATH_SUFFIXES lib lib64) +else() + find_library(DLB_LIBRARY + NAMES dlb + HINTS ${DLB_DIR} + PATH_SUFFIXES lib lib64) +endif() + +find_path(DLB_INCLUDE_DIR + NAMES dlb.h + PATHS ${DLB_DIR} + PATH_SUFFIXES include + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(DLB + REQUIRED_VARS + DLB_LIBRARY + DLB_INCLUDE_DIR + ) + +if(DLB_FOUND) + set(DLB_LIBRARIES ${DLB_LIBRARY}) + set(DLB_INCLUDE_DIRS ${DLB_INCLUDE_DIR}) +endif() + +if(NOT DLB_FOUND) + message(FATAL_ERROR "FindDLB: Did not find required library DLB") +endif() + +mark_as_advanced(DLB_DIR) diff --git a/src/backends/dlb/CMakeLists.txt b/src/backends/dlb/CMakeLists.txt index 2360107..b10f672 100644 --- a/src/backends/dlb/CMakeLists.txt +++ b/src/backends/dlb/CMakeLists.txt @@ -1,2 +1,9 @@ find_package(DLB REQUIRED) -target_sources(sit PRIVATE dlb.cpp) \ No newline at end of file +target_sources(sit PRIVATE dlb.cpp) +if(DLB_FOUND) +target_include_directories(sit + PRIVATE ${DLB_INCLUDE_DIRS}) +target_link_libraries(sit PUBLIC ${DLB_LIBRARIES}) +target_compile_definitions(sit PRIVATE "ENABLE_DLB") + +endif() -- GitLab From 65c2152ceaaedc44890f937a0f30243af80461ee Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 28 May 2024 16:04:30 +0200 Subject: [PATCH 3/6] fixed some compiler issues :) --- src/backends/dlb/dlb.cpp | 23 +++++++++++------------ src/sit_delegator.cpp | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/backends/dlb/dlb.cpp b/src/backends/dlb/dlb.cpp index c37ce5b..95aa35a 100644 --- a/src/backends/dlb/dlb.cpp +++ b/src/backends/dlb/dlb.cpp @@ -1,23 +1,22 @@ #include "dlb.hpp" -#include "dlb.h" -class DLBTalpStrategy : public SITProfilingStrategy { +#include "dlb_talp.h" -public: - inline static const std::string_view name = "DLB"; - void region_start(const SITRegionInformation ®ion) const noexcept override { - auto handle = DLB_MonitoringRegionRegister(region.name.c_str()); - DLB_MonitoringRegionStart(handle); +#include + void DLBTalpStrategy::region_start(const SITRegionInformation ®ion) const noexcept { + // we have to create a small std::string thing because we cannot assume that the string_view passed is properly null terminated + auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); + DLB_MonitoringRegionStart(handle); } - void region_stop(const SITRegionInformation ®ion) const noexcept override { - auto handle = DLB_MonitoringRegionRegister(region.name.c_str()); + + void DLBTalpStrategy::region_stop(const SITRegionInformation ®ion) const noexcept { + auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); DLB_MonitoringRegionStop(handle); } - virtual void init() const noexcept { + void DLBTalpStrategy::init() const noexcept { std::cout << "SIT::" < Date: Tue, 28 May 2024 16:11:52 +0200 Subject: [PATCH 4/6] Added a small but maybe working descritpion of how to use the dlb thing --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index c13af42..9e7f280 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # SIT? +# Bindings + ## CXX bindings How to configure and install: @@ -23,9 +25,25 @@ int main() { sit::region_stop("peter"); sit::finalize(); } +``` You **must** call `sit::init` exactly once to init the datastructures before you can use the other functionality. Also some backends require finalization, so please make sure to also call `finalize` in the end. To add it to your code, currently just install it and use something similar to: `-I/include -L-I/lib -lsit` in the compiler options + +# Backends + +## DLB + +### Building + +To build the DLB backend please make sure you have `DLB_HOME` set in your enviroment or provide the installation dir of dlb with `-DDLB_DIR` +To configure: `cmake .. -DENABLE_DLB=ON -DCMAKE_INSTALL_PREFIX= -DBUILD_C_FORTRAN=OFF` + +Please note, that you may have to add the DLB location to the library path, but as you probably preload it anyway, this shoule be fine :) + +### Usage + +`sit::init("DLB")` -- GitLab From 9d8178a0733a5b84fd52c1dab67cffa6ba5690d4 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 28 May 2024 16:12:53 +0200 Subject: [PATCH 5/6] applied clang_format --- src/backends/dlb/dlb.cpp | 33 ++++++++++++++++++--------------- src/backends/dlb/dlb.hpp | 1 - 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/backends/dlb/dlb.cpp b/src/backends/dlb/dlb.cpp index 95aa35a..030254c 100644 --- a/src/backends/dlb/dlb.cpp +++ b/src/backends/dlb/dlb.cpp @@ -3,20 +3,23 @@ #include - void DLBTalpStrategy::region_start(const SITRegionInformation ®ion) const noexcept { - // we have to create a small std::string thing because we cannot assume that the string_view passed is properly null terminated - auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); - DLB_MonitoringRegionStart(handle); - } +void DLBTalpStrategy::region_start( + const SITRegionInformation ®ion) const noexcept { + // we have to create a small std::string thing because we cannot assume that + // the string_view passed is properly null terminated + auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); + DLB_MonitoringRegionStart(handle); +} - void DLBTalpStrategy::region_stop(const SITRegionInformation ®ion) const noexcept { - auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); - DLB_MonitoringRegionStop(handle); - } +void DLBTalpStrategy::region_stop( + const SITRegionInformation ®ion) const noexcept { + auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); + DLB_MonitoringRegionStop(handle); +} - void DLBTalpStrategy::init() const noexcept { - std::cout << "SIT::" < Date: Tue, 28 May 2024 16:42:42 +0200 Subject: [PATCH 6/6] Added init and finalize, As well as a small test --- src/backends/dlb/dlb.cpp | 5 ++++- tests/CMakeLists.txt | 13 ++++++++++++- tests/cpp/TestCppDLB.cpp | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/cpp/TestCppDLB.cpp diff --git a/src/backends/dlb/dlb.cpp b/src/backends/dlb/dlb.cpp index 030254c..4b34700 100644 --- a/src/backends/dlb/dlb.cpp +++ b/src/backends/dlb/dlb.cpp @@ -1,6 +1,6 @@ #include "dlb.hpp" +#include "dlb.h" #include "dlb_talp.h" - #include void DLBTalpStrategy::region_start( @@ -18,8 +18,11 @@ void DLBTalpStrategy::region_stop( } void DLBTalpStrategy::init() const noexcept { + + DLB_Init(0, NULL, "--talp"); std::cout << "SIT::" << name << " init()" << std::endl; } void DLBTalpStrategy::finalize() const noexcept { + DLB_Finalize(); std::cout << "SIT::" << name << " finalize()" << std::endl; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 279243e..f5d1e18 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,11 +3,22 @@ target_link_libraries(TestCppLink sit::sit) target_include_directories(TestCppLink PRIVATE ${SIT_PUBLIC_HEADERS}) - add_test(NAME TestCppLink COMMAND TestCppLink) +if(ENABLE_DLB) +add_executable(TestCppDLB cpp/TestCppDLB.cpp) +target_link_libraries(TestCppDLB sit::sit) +target_include_directories(TestCppDLB + PRIVATE ${SIT_PUBLIC_HEADERS}) + +add_test(NAME TestCppDLB + COMMAND TestCppDLB) + + +endif() + if(BUILD_C_FORTRAN) add_executable(TestCLink c/TestCLink.c) target_link_libraries(TestCLink sit) diff --git a/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp new file mode 100644 index 0000000..360958a --- /dev/null +++ b/tests/cpp/TestCppDLB.cpp @@ -0,0 +1,8 @@ +#include "sit/sit.hpp" + +int main() { + sit::init("DLB"); + sit::region_start("Default"); + sit::region_stop("Default"); + sit::finalize(); +} \ No newline at end of file -- GitLab