From 28684ebb1e90f41a4139bbfceb32863ea44c2c9c Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 6 Jun 2024 15:29:12 +0200 Subject: [PATCH 1/4] Added first implementation --- include/sit/sit.hpp | 1 + src/CMakeLists.txt | 2 +- src/bindings/CMakeLists.txt | 18 +++++++++--------- src/bindings/sit.yaml | 1 + src/bindings/wrapfsit.f | 5 +++++ src/bindings/wrapsit.cpp | 7 +++++++ src/bindings/wrapsit.h | 2 ++ src/sit.cpp | 4 ++++ src/sit_delegator.cpp | 4 ++++ src/sit_delegator.hpp | 2 ++ tests/CMakeLists.txt | 10 ++++++++++ tests/cpp/TestRegionCloseLast.cpp | 10 ++++++++++ 12 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 tests/cpp/TestRegionCloseLast.cpp diff --git a/include/sit/sit.hpp b/include/sit/sit.hpp index 72ebb3a..5ff248c 100644 --- a/include/sit/sit.hpp +++ b/include/sit/sit.hpp @@ -4,5 +4,6 @@ namespace sit { void init(const std::string &backend); void region_start(const std::string &name); void region_stop(const std::string &name); +void region_stop_last(void); void finalize(); } // namespace sit diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5825ab7..7c539cf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ add_subdirectory(backends) target_sources(sit PRIVATE sit_delegator.cpp sit.cpp) -if(BUILD_C_FORTRAN) +if(BUILD_C_FORTRAN OR GEN_BINDINGS) add_subdirectory(bindings) endif() diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index d1c8188..ea0818b 100644 --- a/src/bindings/CMakeLists.txt +++ b/src/bindings/CMakeLists.txt @@ -19,19 +19,19 @@ if(GEN_BINDINGS) endif() endif() +if(BUILD_C_FORTRAN) + target_sources(sit PRIVATE wrapsit.cpp) -target_sources(sit PRIVATE wrapsit.cpp) - -if(SPLIT_FORTRAN_LIBRARY) - target_sources(sit_f PRIVATE wrapfsit.f) - target_include_directories(sit_f PRIVATE ${SIT_PUBLIC_HEADERS}) - set_target_properties(sit_f PROPERTIES LINKER_LANGUAGE Fortran) -else() - target_sources(sit PRIVATE wrapfsit.f) + if(SPLIT_FORTRAN_LIBRARY) + target_sources(sit_f PRIVATE wrapfsit.f) + target_include_directories(sit_f PRIVATE ${SIT_PUBLIC_HEADERS}) + set_target_properties(sit_f PROPERTIES LINKER_LANGUAGE Fortran) + else() + target_sources(sit PRIVATE wrapfsit.f) + endif() endif() - #set( CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) #set_source_files_properties(wrapsit.cpp PROPERTIES GENERATED TRUE) #set_source_files_properties(wrapfsit.f PROPERTIES GENERATED TRUE) diff --git a/src/bindings/sit.yaml b/src/bindings/sit.yaml index 1c7bf38..3013863 100644 --- a/src/bindings/sit.yaml +++ b/src/bindings/sit.yaml @@ -8,4 +8,5 @@ declarations: - decl: void init(const std::string &backend) - decl: void region_start(const std::string &name) - decl: void region_stop(const std::string &name) +- decl: void region_stop_last(); - decl: void finalize() \ No newline at end of file diff --git a/src/bindings/wrapfsit.f b/src/bindings/wrapfsit.f index 0b6d712..fd01b85 100644 --- a/src/bindings/wrapfsit.f +++ b/src/bindings/wrapfsit.f @@ -61,6 +61,11 @@ module sit_mod integer(C_INT), value, intent(IN) :: SHT_name_len end subroutine c_region_stop_bufferify + subroutine region_stop_last() & + bind(C, name="sit_region_stop_last") + implicit none + end subroutine region_stop_last + subroutine finalize() & bind(C, name="sit_finalize") implicit none diff --git a/src/bindings/wrapsit.cpp b/src/bindings/wrapsit.cpp index 681c08a..9468b75 100644 --- a/src/bindings/wrapsit.cpp +++ b/src/bindings/wrapsit.cpp @@ -80,6 +80,13 @@ void sit_region_stop_bufferify(char *name, int SHT_name_len) // splicer end function.region_stop_bufferify } +void sit_region_stop_last(void) +{ + // splicer begin function.region_stop_last + sit::region_stop_last(); + // splicer end function.region_stop_last +} + void sit_finalize(void) { // splicer begin function.finalize diff --git a/src/bindings/wrapsit.h b/src/bindings/wrapsit.h index ce1dc69..6d62fee 100644 --- a/src/bindings/wrapsit.h +++ b/src/bindings/wrapsit.h @@ -33,6 +33,8 @@ void sit_region_stop(const char * name); void sit_region_stop_bufferify(char *name, int SHT_name_len); +void sit_region_stop_last(void); + void sit_finalize(void); #ifdef __cplusplus diff --git a/src/sit.cpp b/src/sit.cpp index d9ef341..52ae1e3 100644 --- a/src/sit.cpp +++ b/src/sit.cpp @@ -13,5 +13,9 @@ void region_start(const std::string &name) { void region_stop(const std::string &name) { return SITDelegator::region_stop(name); } + +void region_stop_last(){ + return SITDelegator::region_stop_last(); +} void finalize() { return SITDelegator::finalize(); } } // namespace sit diff --git a/src/sit_delegator.cpp b/src/sit_delegator.cpp index b14998c..edfe41c 100644 --- a/src/sit_delegator.cpp +++ b/src/sit_delegator.cpp @@ -41,10 +41,14 @@ void SITDelegator::init(std::string_view backend) { // should be thread safe to call? void SITDelegator::region_start(std::string_view name) { + lastRegion = {name}; profiling_strategy->region_start({name}); } void SITDelegator::region_stop(std::string_view name) { profiling_strategy->region_stop({name}); }; +void SITDelegator::region_stop_last() { + profiling_strategy->region_stop({lastRegion.name}); +}; void SITDelegator::finalize() { profiling_strategy->finalize(); }; diff --git a/src/sit_delegator.hpp b/src/sit_delegator.hpp index 07fd128..0c12464 100644 --- a/src/sit_delegator.hpp +++ b/src/sit_delegator.hpp @@ -9,11 +9,13 @@ class SITDelegator { private: inline static std::unique_ptr profiling_strategy; + inline static thread_local SITRegionInformation lastRegion; public: static void init(std::string_view backend); static void region_start(std::string_view name); static void region_stop(std::string_view name); + static void region_stop_last(); static void finalize(); }; #endif // SIT_DELEGATOR_HPP \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5980f92..843ef0b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,16 @@ add_test(NAME TestCppLink COMMAND TestCppLink) +add_executable(TestRegionCloseLast cpp/TestRegionCloseLast.cpp) +target_link_libraries(TestRegionCloseLast sit::sit) +target_include_directories(TestRegionCloseLast + PRIVATE ${SIT_PUBLIC_HEADERS}) + +add_test(NAME TestRegionCloseLast + COMMAND TestRegionCloseLast) + + + if(ENABLE_DLB) add_executable(TestCppDLB cpp/TestCppDLB.cpp) target_link_libraries(TestCppDLB sit::sit) diff --git a/tests/cpp/TestRegionCloseLast.cpp b/tests/cpp/TestRegionCloseLast.cpp new file mode 100644 index 0000000..2b4a4e6 --- /dev/null +++ b/tests/cpp/TestRegionCloseLast.cpp @@ -0,0 +1,10 @@ +#include "sit/sit.hpp" + +int main() { + sit::init("Default"); + sit::region_start("outer_region1"); + sit::region_start("inner_region1"); + sit::region_stop_last(); + sit::region_stop("outer_region1"); + sit::finalize(); +} \ No newline at end of file -- GitLab From f9f50913be866dc198ba43c8482c300f68030f1e Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 6 Jun 2024 15:56:11 +0200 Subject: [PATCH 2/4] actually store the string, not the view --- src/sit_delegator.cpp | 2 +- src/sit_delegator.hpp | 2 +- src/sit_strategy.hpp | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sit_delegator.cpp b/src/sit_delegator.cpp index edfe41c..50b75af 100644 --- a/src/sit_delegator.cpp +++ b/src/sit_delegator.cpp @@ -41,7 +41,7 @@ void SITDelegator::init(std::string_view backend) { // should be thread safe to call? void SITDelegator::region_start(std::string_view name) { - lastRegion = {name}; + lastRegion = {std::string(name)}; profiling_strategy->region_start({name}); } void SITDelegator::region_stop(std::string_view name) { diff --git a/src/sit_delegator.hpp b/src/sit_delegator.hpp index 0c12464..b103d62 100644 --- a/src/sit_delegator.hpp +++ b/src/sit_delegator.hpp @@ -9,7 +9,7 @@ class SITDelegator { private: inline static std::unique_ptr profiling_strategy; - inline static thread_local SITRegionInformation lastRegion; + inline static thread_local PersistentRegionInformation lastRegion; public: static void init(std::string_view backend); diff --git a/src/sit_strategy.hpp b/src/sit_strategy.hpp index 34ae59d..e1ef207 100644 --- a/src/sit_strategy.hpp +++ b/src/sit_strategy.hpp @@ -9,6 +9,10 @@ struct SITRegionInformation { std::string_view name; }; +struct PersistentRegionInformation { + std::string name; +}; + // The Strategy Interface each backend needs to implement class SITProfilingStrategy { -- GitLab From 343667f0246a2f67aec22d2cc1955a6657939ef9 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 6 Jun 2024 20:06:13 +0200 Subject: [PATCH 3/4] test svg inline --- README.md | 37 ++++++++++++++++++++++- src/backends/extrae/extrae_type_stack.cpp | 2 ++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 74f35f5..d2d1752 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,39 @@ -# SIT? +# neSmiK? + +## General Ideas + +In the following we will lay out some theoretical groundwork which is important to understand the operating modes of `neSmiK`. + +In general we can define 2 types of region modes: Either regions are able to overlap or they dont. +To explain a bit better what we mean by that consider the following example: + +```cpp +sit::region_start("peter"); + sit::region_start("marie"); + +sit::region_stop("peter"); + sit::region_stop("marie"); +``` + +When viszualizing this call sequence we can see: + +
peter
marie
# Bindings diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 21fb90a..0d67d7f 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -167,6 +167,8 @@ void ExtraeTypeStackStrategy::region_stop( std::cout << "imbalanced region stop REASON: Emtpy stack " << region.name << std::endl; return; } + + const auto &lastRegionName = regionStackData.regionNameStack.top(); -- GitLab From f5da5a36c24f13e4340e086dfc51efc487bd288e Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Fri, 7 Jun 2024 10:41:25 +0200 Subject: [PATCH 4/4] Add some ideas on PN vs NPN regions --- README.md | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d2d1752..8b0d683 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ In the following we will lay out some theoretical groundwork which is important In general we can define 2 types of region modes: Either regions are able to overlap or they dont. To explain a bit better what we mean by that consider the following example: +### Not properly nested regions + ```cpp sit::region_start("peter"); sit::region_start("marie"); @@ -15,25 +17,21 @@ sit::region_stop("peter"); sit::region_stop("marie"); ``` -When viszualizing this call sequence we can see: - -
peter
marie
+As we can see this calling order overlaps the regions. On the other hand, we can have properly nested functions, where there the regions are nested in levels and are mutually exclusive on one level like: + +### Properly nested regions + +```cpp +sit::region_start("peter"); + sit::region_start("marie"); + sit::region_stop("marie"); +sit::region_stop("peter"); +``` + +The newly introduced `region_stop_last()` API assumes that the users annotated the code in the **properly nested regions** fashion. +If this is not the case, the user should use the other APIs or undefined behavior might occur. Note, that actual behavior is backend dependent. + +For now, its really hard to think of a case where the user actually wants to use the not properly nested regions, but as some backends enable it, we will make `neSmiK` aware of this issues. # Bindings -- GitLab