diff --git a/README.md b/README.md index 74f35f56a5d1cfb3c9cce5caa54dcc86566a063b..8b0d6835ba6a294a01adee507345c1cfd2131f15 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,37 @@ -# 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: + +### Not properly nested regions + +```cpp +sit::region_start("peter"); + sit::region_start("marie"); + +sit::region_stop("peter"); + sit::region_stop("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 diff --git a/include/sit/sit.hpp b/include/sit/sit.hpp index 72ebb3a6f8c48391d5e6e540f185fb592777e0df..5ff248cfa14a6ad02bf0df00cd1577401fc1d914 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 5825ab7701e7c7eacd803f5f41f44f50a0b572c4..7c539cf7782e3c97a0c8ff2364bbc2a0742540ad 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/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 21fb90a40abab01cd7cc32d5b77875b3b64cd3f0..0d67d7fd150eebf3b66b4f6b492f07c6e5c75946 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(); diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index d1c81886aeea7f0ebc996600865842ef3f1c6a0e..ea0818bbf4f9969ff83ca17e635410102c5f82e8 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 1c7bf3816881eeb86c77ddb24adbe1b01e1f3903..30138632a27d3818dd19ed9615e0315580b45130 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 0b6d712ee30a32463477cf7a30ca516b948bbe51..fd01b859c76a60cd9ac5911daaa775f068a6fda8 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 681c08a9c9514f4f3f52cc81aec780f6dff7fbdd..9468b75b4c643f771407feda75e131f65f201ed3 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 ce1dc6944a481a95fbc4f20409edef165a0d498d..6d62fee0deadf33e9fb7008badac404955ac6700 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 d9ef341bc1a02a3637c77eff760c926f30219f48..52ae1e38f702f4638c1971fdc31303f143dec282 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 b14998cd27218189d63cfb786d2803ca0ffde66f..50b75af0795795a38edf29f8533e64bb6640c404 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 = {std::string(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 07fd128b17fe7de824e4bc915f9549c8b856f206..b103d62d2bf54c64b7e60f8a4733e575eae52920 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 PersistentRegionInformation 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/src/sit_strategy.hpp b/src/sit_strategy.hpp index 34ae59de1ca9f1041afce4321aaf7f7d7f58ae7d..e1ef2070c3cd7f8ef4d93a11a140278215ce493d 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 { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5980f92fb1fce1c0b21ec4c28d49b6032684d0d6..843ef0b4ff03d5eb9ff46b737eb9c64fcdf08dae 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 0000000000000000000000000000000000000000..2b4a4e639998a50aba627fbc2dc0bf1875df7f77 --- /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