From b96a0c5f9ec932b92b109d877c8120cfe4dd1a17 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 27 Jun 2024 21:23:14 +0200 Subject: [PATCH] Added RegionStopLast --- include/nesmik/nesmik.hpp | 1 + src/bindings/nesmik.json | 62 ++++++++++++++++++++++++++++---- src/bindings/nesmik.log | 3 ++ src/bindings/nesmik.yaml | 1 + src/bindings/wrapfnesmik.f | 5 +++ src/bindings/wrapnesmik.cpp | 7 ++++ src/bindings/wrapnesmik.h | 2 ++ src/delegator.cpp | 15 ++++++++ src/delegator.hpp | 1 + src/nesmik.cpp | 4 +++ tests/CMakeLists.txt | 10 ++++++ tests/cpp/TestRegionStopLast.cpp | 12 +++++++ 12 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 tests/cpp/TestRegionStopLast.cpp diff --git a/include/nesmik/nesmik.hpp b/include/nesmik/nesmik.hpp index e7d14ea..d350cf1 100644 --- a/include/nesmik/nesmik.hpp +++ b/include/nesmik/nesmik.hpp @@ -4,5 +4,6 @@ namespace nesmik { void init(const std::string &nesting_mode, const std::string &backend); void region_start(const std::string &name); void region_stop(const std::string &name); +void region_stop_last(void); // only supported in PN backends void finalize(); } // namespace nesmik diff --git a/src/bindings/nesmik.json b/src/bindings/nesmik.json index f124649..71ba994 100644 --- a/src/bindings/nesmik.json +++ b/src/bindings/nesmik.json @@ -10,7 +10,7 @@ "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "4", + "_PTR_F_C_index": "5", "ast": { "declarator": { "metaattrs": { @@ -158,7 +158,7 @@ } }, { - "": "4 ****************************************", + "": "5 ****************************************", "_generated": "arg_to_buffer", "ast": { "declarator": { @@ -320,7 +320,7 @@ "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "5", + "_PTR_F_C_index": "6", "ast": { "declarator": { "metaattrs": { @@ -420,7 +420,7 @@ } }, { - "": "5 ****************************************", + "": "6 ****************************************", "_PTR_C_CXX_index": "1", "_generated": "arg_to_buffer", "ast": { @@ -527,7 +527,7 @@ "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "6", + "_PTR_F_C_index": "7", "ast": { "declarator": { "metaattrs": { @@ -627,7 +627,7 @@ } }, { - "": "6 ****************************************", + "": "7 ****************************************", "_PTR_C_CXX_index": "2", "_generated": "arg_to_buffer", "ast": { @@ -731,6 +731,54 @@ }, { "": "3 ****************************************", + "ast": { + "declarator": { + "metaattrs": { + "intent": "subroutine" + }, + "name": "region_stop_last", + "params": [], + "typemap_name": "void" + }, + "specifier": [ + "void" + ], + "typemap_name": "void" + }, + "decl": "void region_stop_last(void)", + "declgen": "void region_stop_last(void)", + "linenumber": 11, + "name": "region_stop_last", + "options": {}, + "wrap": { + "c": true, + "f_c": true, + "fortran": true + }, + "zz_fmtdict": { + "C_name": "nesmik_region_stop_last", + "C_name_api": "region_stop_last", + "C_prototype": "void", + "C_return_type": "void", + "F_C_arguments": "", + "F_C_call": "c_region_stop_last", + "F_C_name": "region_stop_last", + "F_C_subprogram": "subroutine", + "F_arguments": "", + "F_name_api": "region_stop_last", + "F_name_function": "region_stop_last", + "F_name_generic": "region_stop_last", + "F_name_impl": "region_stop_last", + "F_subprogram": "subroutine", + "function_name": "region_stop_last", + "stmt0": "f_subroutine", + "stmt1": "f_subroutine", + "stmtc0": "c_subroutine", + "stmtc1": "c_subroutine" + } + }, + { + "": "4 ****************************************", "ast": { "declarator": { "metaattrs": { @@ -747,7 +795,7 @@ }, "decl": "void finalize()", "declgen": "void finalize(void)", - "linenumber": 11, + "linenumber": 12, "name": "finalize", "options": {}, "wrap": { diff --git a/src/bindings/nesmik.log b/src/bindings/nesmik.log index d90a031..3fbcba9 100644 --- a/src/bindings/nesmik.log +++ b/src/bindings/nesmik.log @@ -5,12 +5,14 @@ C void region_start(const std::string & name) +intent(subroutine) C void region_start(const std::string & name) +intent(subroutine) C void region_stop(const std::string & name) +intent(subroutine) C void region_stop(const std::string & name) +intent(subroutine) +C void region_stop_last(void) +intent(subroutine) C void finalize(void) +intent(subroutine) Close wrapnesmik.h Close wrapnesmik.cpp Fortran void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) Fortran void region_start(const std::string & name) +intent(subroutine) Fortran void region_stop(const std::string & name) +intent(subroutine) +Fortran void region_stop_last(void) +intent(subroutine) Fortran void finalize(void) +intent(subroutine) C-interface void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) C-interface void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) @@ -18,6 +20,7 @@ C-interface void region_start(const std::string & name) +intent(subroutine) C-interface void region_start(const std::string & name) +intent(subroutine) C-interface void region_stop(const std::string & name) +intent(subroutine) C-interface void region_stop(const std::string & name) +intent(subroutine) +C-interface void region_stop_last(void) +intent(subroutine) C-interface void finalize(void) +intent(subroutine) Close wrapfnesmik.f Close utilnesmik.cpp diff --git a/src/bindings/nesmik.yaml b/src/bindings/nesmik.yaml index 2905d1d..eb9d6b5 100644 --- a/src/bindings/nesmik.yaml +++ b/src/bindings/nesmik.yaml @@ -8,4 +8,5 @@ declarations: - decl: void init(const std::string &nesting_mode, 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(void) - decl: void finalize() \ No newline at end of file diff --git a/src/bindings/wrapfnesmik.f b/src/bindings/wrapfnesmik.f index 74029b1..9e9b1ca 100644 --- a/src/bindings/wrapfnesmik.f +++ b/src/bindings/wrapfnesmik.f @@ -65,6 +65,11 @@ module nesmik_mod integer(C_INT), value, intent(IN) :: SHT_name_len end subroutine c_region_stop_bufferify + subroutine region_stop_last() & + bind(C, name="nesmik_region_stop_last") + implicit none + end subroutine region_stop_last + subroutine finalize() & bind(C, name="nesmik_finalize") implicit none diff --git a/src/bindings/wrapnesmik.cpp b/src/bindings/wrapnesmik.cpp index 9253128..7940f9c 100644 --- a/src/bindings/wrapnesmik.cpp +++ b/src/bindings/wrapnesmik.cpp @@ -84,6 +84,13 @@ void nesmik_region_stop_bufferify(char *name, int SHT_name_len) // splicer end function.region_stop_bufferify } +void nesmik_region_stop_last(void) +{ + // splicer begin function.region_stop_last + nesmik::region_stop_last(); + // splicer end function.region_stop_last +} + void nesmik_finalize(void) { // splicer begin function.finalize diff --git a/src/bindings/wrapnesmik.h b/src/bindings/wrapnesmik.h index d8833af..ec1afc6 100644 --- a/src/bindings/wrapnesmik.h +++ b/src/bindings/wrapnesmik.h @@ -34,6 +34,8 @@ void nesmik_region_stop(const char * name); void nesmik_region_stop_bufferify(char *name, int SHT_name_len); +void nesmik_region_stop_last(void); + void nesmik_finalize(void); #ifdef __cplusplus diff --git a/src/delegator.cpp b/src/delegator.cpp index 910ae94..112ee24 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -152,6 +152,21 @@ void Delegator::RegionStop(std::string_view name) { } }; +void Delegator::RegionStopLast(){ + switch (nesting_mode_) { + + case NestingMode::NotProperlyNested: + std::cout << "Calling region_stop_last() is not supported in NotProperlyNested Backends" << std::endl; + break; + case NestingMode::Detection: + case NestingMode::ProperlyNested: + const std::string& last_region_name = name_stack_.top(); + pn_annotation_strategy_->RegionStopLast({last_region_name,name_stack_}); + if(!name_stack_.empty()) {name_stack_.pop();} + break; + } +} + void Delegator::Finalize() { switch (nesting_mode_) { diff --git a/src/delegator.hpp b/src/delegator.hpp index b942783..68b97de 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -24,6 +24,7 @@ public: static void Init(std::string_view nesting_mode, std::string_view backend); static void RegionStart(std::string_view name); static void RegionStop(std::string_view name); + static void RegionStopLast(); static void Finalize(); private: diff --git a/src/nesmik.cpp b/src/nesmik.cpp index 34fa942..1783839 100644 --- a/src/nesmik.cpp +++ b/src/nesmik.cpp @@ -15,5 +15,9 @@ void region_start(const std::string &name) { void region_stop(const std::string &name) { return Delegator::RegionStop(name); } + +void region_stop_last() { + return Delegator::RegionStopLast(); +} void finalize() { return Delegator::Finalize(); } } // namespace nesmik diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 32c9d06..dab8f22 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,16 @@ add_test(NAME TestCppLink COMMAND TestCppLink) +add_executable(TestRegionStopLast cpp/TestRegionStopLast.cpp) +target_link_libraries(TestRegionStopLast nesmik::nesmik) +target_include_directories(TestRegionStopLast + PRIVATE ${NESMIK_PUBLIC_HEADERS}) + +add_test(NAME TestRegionStopLast + COMMAND TestRegionStopLast) + + + if(ENABLE_DLB) add_executable(TestCppDLB cpp/TestCppDLB.cpp) target_link_libraries(TestCppDLB nesmik::nesmik) diff --git a/tests/cpp/TestRegionStopLast.cpp b/tests/cpp/TestRegionStopLast.cpp new file mode 100644 index 0000000..77a7e28 --- /dev/null +++ b/tests/cpp/TestRegionStopLast.cpp @@ -0,0 +1,12 @@ +#include "nesmik/nesmik.hpp" + +int main() { + nesmik::init("ProperlyNested","Default"); + nesmik::region_start("Test0-1"); + nesmik::region_start("Test1-1"); + nesmik::region_stop_last(); + nesmik::region_start("Test1-2"); + nesmik::region_stop_last(); + nesmik::region_stop_last(); + nesmik::finalize(); +} -- GitLab