diff --git a/README.md b/README.md index c13af4204a7904d0ecd569d7480490993f32d46d..9e7f280e993c669c13d08dd8c6bf2da8a3ba2d76 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")` diff --git a/cmake/FindDLB.cmake b/cmake/FindDLB.cmake new file mode 100644 index 0000000000000000000000000000000000000000..590d7e7b38bc08aeb12b000d156d797afed66973 --- /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 2360107e9d5274668f3ae188a9aad99c31945e47..b10f672d63987e7d42361551a1a0edff3be89be0 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() diff --git a/src/backends/dlb/dlb.cpp b/src/backends/dlb/dlb.cpp index 4521a7f49bc869cde6386d8d04798c5eaa91a7f5..4b34700af71a7fa96b708f97594a498439b7c5b4 100644 --- a/src/backends/dlb/dlb.cpp +++ b/src/backends/dlb/dlb.cpp @@ -1,15 +1,28 @@ #include "dlb.hpp" +#include "dlb.h" +#include "dlb_talp.h" +#include -class DLBTalpStrategy : public SITProfilingStrategy { +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); +} -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 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 { - virtual void init() const noexcept {} - virtual void finalize() 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/src/sit_delegator.cpp b/src/sit_delegator.cpp index 1386f827de0bf1986fd23fc99cde40bd93d83c42..77b237240f8aa8e5384dcbb458f8145d97404951 100644 --- a/src/sit_delegator.cpp +++ b/src/sit_delegator.cpp @@ -9,7 +9,7 @@ #include "backends/default/default.hpp" #ifdef ENABLE_DLB -#include "backends/default/default.cpp" +#include "backends/dlb/dlb.hpp" #endif #ifdef ENABLE_EXTRAE diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 279243ee98c1d55a456b1ab141169b6d71285720..f5d1e18fd1ae040c601f8591640582f0305e8bfa 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 0000000000000000000000000000000000000000..360958a7c661482a986cfedbb109116cb307ea59 --- /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