From c29bac30eed963dbaa79375dcb5aba5919b21d88 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 11 Jun 2024 15:57:04 +0200 Subject: [PATCH 1/7] refactored a bit --- README.md | 26 ++-- src/backends/default/default.cpp | 35 ++++- src/backends/default/default.hpp | 23 ++- src/backends/dlb/CMakeLists.txt | 2 +- src/backends/dlb/dlb/dlb.cpp | 15 +- src/backends/dlb/dlb/dlb.hpp | 12 +- src/backends/extrae/extrae_type_stack.cpp | 14 +- src/backends/extrae/extrae_type_stack.hpp | 10 +- src/delegator.cpp | 181 +++++++++++++++++++--- src/delegator.hpp | 30 +++- src/nesmik.cpp | 14 +- src/strategies.hpp | 35 +++-- tests/cpp/TestCppDLB.cpp | 2 +- tests/cpp/TestCppExtraeTypeStack.cpp | 2 +- tests/cpp/TestCppLink.cpp | 2 +- tests/fortran/TestFortranModule.f90 | 2 +- 16 files changed, 294 insertions(+), 111 deletions(-) diff --git a/README.md b/README.md index ac5a9a8..7de28f5 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,19 @@ How to configure and install: #include "nesmik/nesmik.hpp" int main() { - nesmik::init("Default"); - nesmik::region_start("peter"); + nesmik::Init("Default"); + nesmik::RegionStart("peter"); - nesmik::region_start("marie"); + nesmik::RegionStart("marie"); - nesmik::region_stop("marie"); + nesmik::RegionStop("marie"); - nesmik::region_stop("peter"); - nesmik::finalize(); + nesmik::RegionStop("peter"); + nesmik::Finalize(); } ``` -You **must** call `nesmik::init` exactly once to init the datastructures before you can use the other functionality. +You **must** call `nesmik::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: @@ -45,16 +45,16 @@ How to configure and install: ```fortran program test use nesmik_mod - call init("Default") - call region_start("test") - call region_stop("test") - call finalize() + call Init("Default") + call RegionStart("test") + call RegionStop("test") + call Finalize() end program test ``` -You **must** call `init` exactly once to init the datastructures before you can use the other functionality. +You **must** call `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: @@ -74,4 +74,4 @@ Please note, that you may have to add the DLB location to the library path, but ### Usage -`nesmik::init("DLB")` +`nesmik::Init("DLB")` diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index ff11385..d460168 100644 --- a/src/backends/default/default.cpp +++ b/src/backends/default/default.cpp @@ -3,19 +3,38 @@ #include "default.hpp" -void DefaultStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +void PNDefault::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { std::cout << "Region start: " << region.name << std::endl; } -void DefaultStrategy::region_stop( - const PNRegionInformation ®ion) noexcept { +void PNDefault::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { std::cout << "Region stop: " << region.name << std::endl; } -void DefaultStrategy::init() noexcept { - std::cout << "nesmik_init() Backend: Default " << std::endl; +void PNDefault::Init() noexcept { + std::cout << "nesmik::Init() Backend: PN;Default " << std::endl; } -void DefaultStrategy::finalize() noexcept { - std::cout << "nesmik_finalize() Backend: Default " << std::endl; +void PNDefault::Finalize() noexcept { + std::cout << "nesmik::Finalize() Backend: PN;Default " << std::endl; } + +// NPN + +void NPNDefault::RegionStart( + const NotProperlyNestedRegionInformation ®ion) noexcept { + std::cout << "Region start: " << region.name << std::endl; +} + +void NPNDefault::RegionStop( + const NotProperlyNestedRegionInformation ®ion) noexcept { + std::cout << "Region stop: " << region.name << std::endl; +} + +void NPNDefault::Init() noexcept { + std::cout << "nesmik::Init() Backend: NPN;Default " << std::endl; +} +void NPNDefault::Finalize() noexcept { + std::cout << "nesmik::Finalize() Backend: NPN;Default " << std::endl; +} \ No newline at end of file diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 2160aed..9d8b8e4 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -1,12 +1,23 @@ #include "strategies.hpp" #include -class DefaultStrategy : public PNProfilingStrategy { +class PNDefault : public ProperlyNestedAnnotationStrategy { public: - inline static const std::string_view name = "Default"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + inline static const std::string name = "Default"; + void RegionStart(const ProperlyNestedRegionInformation &info_to_start) noexcept override; + void RegionStopLast(const ProperlyNestedRegionInformation &info_to_stop) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; +}; + + +class NPNDefault : public NotProperlyNestedAnnotationStrategy { + +public: + inline static const std::string name = "Default"; + virtual void RegionStart(const NotProperlyNestedRegionInformation &info_to_start) noexcept override; + virtual void RegionStop(const NotProperlyNestedRegionInformation &info_to_stop) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; diff --git a/src/backends/dlb/CMakeLists.txt b/src/backends/dlb/CMakeLists.txt index 3a432c4..593fa9d 100644 --- a/src/backends/dlb/CMakeLists.txt +++ b/src/backends/dlb/CMakeLists.txt @@ -3,7 +3,7 @@ if(DLB_FOUND) target_include_directories(nesmik PRIVATE ${DLB_INCLUDE_DIRS}) target_link_libraries(nesmik PUBLIC ${DLB_LIBRARIES}) -target_compile_definitions(nesmik PRIVATE "ENABLE_DLB") +target_compile_defInitions(nesmik PRIVATE "ENABLE_DLB") add_subdirectory(dlb) add_subdirectory(dlb_talp_tree) diff --git a/src/backends/dlb/dlb/dlb.cpp b/src/backends/dlb/dlb/dlb.cpp index 3c8b5d9..3a7b076 100644 --- a/src/backends/dlb/dlb/dlb.cpp +++ b/src/backends/dlb/dlb/dlb.cpp @@ -3,25 +3,26 @@ #include "dlb_talp.h" #include -void DLBTalpStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +void DLBTalpStrategy::RegionStart( + const NotProperlyNestedRegionInformation ®ion) 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 PNRegionInformation ®ion) noexcept { +void DLBTalpStrategy::RegionStop( + const NotProperlyNestedRegionInformation ®ion) noexcept { auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); DLB_MonitoringRegionStop(handle); } -void DLBTalpStrategy::init() noexcept { +void DLBTalpStrategy::Init() noexcept { + DLB_Init(0, NULL, "--talp"); std::cout << "nesmik::" << name << " init()" << std::endl; } -void DLBTalpStrategy::finalize() noexcept { +void DLBTalpStrategy::Finalize() noexcept { DLB_Finalize(); - std::cout << "nesmik::" << name << " finalize()" << std::endl; + std::cout << "nesmik::" << name << " Finalize()" << std::endl; } diff --git a/src/backends/dlb/dlb/dlb.hpp b/src/backends/dlb/dlb/dlb.hpp index ebdeb6c..83201cc 100644 --- a/src/backends/dlb/dlb/dlb.hpp +++ b/src/backends/dlb/dlb/dlb.hpp @@ -3,13 +3,13 @@ #include -class DLBTalpStrategy : public PNProfilingStrategy { +class DLBTalpStrategy : public NotProperlyNestedAnnotationStrategy { public: - inline static const std::string_view name = "TALP"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + inline static const std::string name = "TALP"; + virtual void RegionStart(const NotProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStop(const NotProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; #endif // SIT_DLB_H diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 31eb536..ab69008 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -100,7 +100,7 @@ window_filter_module evt_type 1 NESMIK_REPLACE_EVENT_TYPE )"; -void ExtraeTypeStackStrategy::init() noexcept { +void ExtraeTypeStackStrategy::Init() noexcept { auto isInitializedVal = Extrae_is_initialized(); if (isInitializedVal == 0) { @@ -143,8 +143,8 @@ ExtraeTypeStackStrategy::get_value_by_region_name(const std::string &name) { } } -void ExtraeTypeStackStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +void ExtraeTypeStackStrategy::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { // First push to stack const auto regionName = std::string(region.name); @@ -159,8 +159,8 @@ void ExtraeTypeStackStrategy::region_start( Extrae_eventandcounters(type, value); } -void ExtraeTypeStackStrategy::region_stop( - const PNRegionInformation ®ion) noexcept { +void ExtraeTypeStackStrategy::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { if (regionStackData.regionNameStack.empty()) { // whoops @@ -182,7 +182,7 @@ void ExtraeTypeStackStrategy::region_stop( } } -void ExtraeTypeStackStrategy::finalize() noexcept { +void ExtraeTypeStackStrategy::Finalize() noexcept { unsigned int numberOfRegionsRegistered = regionMapData.regionNameToValue.size(); @@ -260,7 +260,7 @@ void ExtraeTypeStackStrategy::finalize() noexcept { if (didInitialize) { // Assumption is that if we needed to initialize the lib we also need to - // finalize it + // Finalize it Extrae_fini(); } } diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index 9b86450..7906dd3 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -16,7 +16,7 @@ struct RegionMapData{ }; -class ExtraeTypeStackStrategy : public PNProfilingStrategy { +class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { private: inline static bool EXTRAE_WRITE_CONFIG_FILE=false; @@ -33,8 +33,8 @@ private: public: inline static const std::string_view name = "Extrae::TypeStack"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + virtual void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; diff --git a/src/delegator.cpp b/src/delegator.cpp index 2a651b2..d1dbe4b 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -1,13 +1,14 @@ #include +#include #include #include +#include "backends/default/default.hpp" #include +#include #include -#include "backends/default/default.hpp" - #ifdef ENABLE_DLB #include "backends/dlb/dlb/dlb.hpp" #include "backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp" @@ -17,38 +18,172 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif -void Delegator::init(std::string_view backend) { - std::cout << backend << std::endl; - if (backend.compare(DefaultStrategy::name) == 0) { - std::cout << "alloc" << std::endl; - pn_profiling_strategy = std::make_unique(); - } -#ifdef ENABLE_EXTRAE - else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { - pn_profiling_strategy = std::make_unique(); +std::vector Delegator::SplitString(const std::string &str, + char delimiter) { + std::stringstream string_stream(str); + std::vector v; + std::string s; + while (std::getline(string_stream, s, delimiter)) { + v.push_back(s); } -#endif + return v; +} + +void Delegator::InitDetectionBackend( + const std::vector &init_strings) { + std::cout << "Not supported currnently, come back later pls" << std::endl; + exit(1); +} + +void Delegator::InitNonProperlyNestedBackends( + const std::vector &init_strings) { + // check if backend is supplied + + npn_annotation_strategy_ = std::make_unique(); + if (init_strings.size() > 1) { + const auto &backend_string = init_strings[1]; + if (backend_string.compare(NPNDefault::name) == 0) { + npn_annotation_strategy_ = std::make_unique(); + } #ifdef ENABLE_DLB - else if (backend.compare(DLBTalpStrategy::name) == 0) { - pn_profiling_strategy = std::make_unique(); + else if (backend_string.compare(DLBTalpStrategy::name) == 0) { + npn_annotation_strategy_ = std::make_unique(); + } +#endif + else { + std::cout << "Could not find a matching backend with name" + << backend_string << " now selecting the Default" << std::endl; + } } - else if (backend.compare(DLBTalpTreeStrategy::name) == 0) { - pn_profiling_strategy = std::make_unique(); + // no backend supplied + else { + std::cout << "No backend name supplied, now selecting the Default" + << std::endl; + npn_annotation_strategy_ = std::make_unique(); } +} + +void Delegator::InitProperlyNestedBackends( + const std::vector &init_strings) { + + pn_annotation_strategy_ = std::make_unique(); + if (init_strings.size() > 1) { + const auto &backend_string = init_strings[1]; + if (backend_string.compare(PNDefault::name) == 0) { + pn_annotation_strategy_ = std::make_unique(); + } +#ifdef ENABLE_EXTRAE + else if (backend_string.compare(ExtraeTypeStackStrategy::name) == 0) { + pn_annotation_strategy_ = std::make_unique(); + } #endif + else { + std::cout << "Could not find a matching backend with name" + << backend_string << " now selecting the Default" << std::endl; + } + } + // no backend supplied else { - exit(1); // fail non gracefully for now + std::cout << "No backend name supplied, now selecting the Default" + << std::endl; + pn_annotation_strategy_ = std::make_unique(); + } +} + +void Delegator::Init(std::string_view initString) { + + std::cout << initString << std::endl; + + // First lets check split the init string by "," + std::vector init_strings = + SplitString(std::string(initString), ';'); + + // check if init_string is long enough + if (init_strings.size() > 0) { + const auto nesting_mode_str = init_strings[0]; + + // detect nesting mode requested by the user + if (nesting_mode_str.compare("?") == 0) { + nesting_mode_ = NestingMode::Detecion; + } else if (nesting_mode_str.compare("PN") == 0) { + nesting_mode_ = NestingMode::ProperlyNested; + } else if (nesting_mode_str.compare("PN") == 0) { + nesting_mode_ = NestingMode::NotProperlyNested; + } + // Some debug output + switch (nesting_mode_) { + case NestingMode::Detecion: + std::cout << "Selecting nesting mode to: " + << "detecting nesting behavior" << std::endl; + break; + case NestingMode::NotProperlyNested: + std::cout << "Selecting nesting mode to: " + << "non properly nested behavior" << std::endl; + break; + case NestingMode::ProperlyNested: + std::cout << "Selecting nesting mode to: " + << "assume properly nested behavior" << std::endl; + break; + } + + // next choose backend + + switch (nesting_mode_) { + case NestingMode::Detecion: + InitDetectionBackend(init_strings); + break; + case NestingMode::NotProperlyNested: + InitNonProperlyNestedBackends(init_strings); + break; + case NestingMode::ProperlyNested: + InitProperlyNestedBackends(init_strings); + break; + } + } else { + InitDetectionBackend(init_strings); } - return pn_profiling_strategy->init(); + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->Init(); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->Init(); + break; + } + } // should be thread safe to call? -void Delegator::region_start(std::string_view name) { - pn_profiling_strategy->region_start({name}); +void Delegator::RegionStart(std::string_view name) { + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->RegionStart({name}); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->RegionStart({name}); + break; + } } -void Delegator::region_stop(std::string_view name) { - pn_profiling_strategy->region_stop({name}); +void Delegator::RegionStop(std::string_view name) { + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->RegionStop({name}); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->RegionStopLast({name}); + break; + } }; -void Delegator::finalize() { pn_profiling_strategy->finalize(); }; +void Delegator::Finalize() { + + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->Finalize(); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->Finalize(); + break; + } + }; diff --git a/src/delegator.hpp b/src/delegator.hpp index bfc8f76..20eddcc 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -3,18 +3,34 @@ #include #include +#include #include +enum class NestingMode { Detecion, ProperlyNested, NotProperlyNested }; + class Delegator { private: - inline static std::unique_ptr pn_profiling_strategy; - inline static std::unique_ptr npn_profiling_strategy; - + inline static std::unique_ptr + pn_annotation_strategy_; + inline static std::unique_ptr + npn_annotation_strategy_; + inline static NestingMode nesting_mode_ = NestingMode::Detecion; + 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 finalize(); + static void Init(std::string_view initString); + static void RegionStart(std::string_view name); + static void RegionStop(std::string_view name); + static void Finalize(); + +private: + static std::vector SplitString(const std::string &str, + char delimiter); + static void + InitDetectionBackend(const std::vector &init_strings); + static void + InitNonProperlyNestedBackends(const std::vector &init_strings); + static void + InitProperlyNestedBackends(const std::vector &init_strings); }; #endif // NESMIK_DELEGATOR_HPP \ No newline at end of file diff --git a/src/nesmik.cpp b/src/nesmik.cpp index 3f4186a..7c15bb1 100644 --- a/src/nesmik.cpp +++ b/src/nesmik.cpp @@ -1,17 +1,17 @@ -#include #include #include +#include -// provides a c-like way to call things with just a fuction compared to instanciate a class. +// provides a c-like way to call things with just a fuction compared to +// instanciate a class. namespace nesmik { -void init(const std::string &backend) { return Delegator::init(backend); -} +void init(const std::string &backend) { return Delegator::Init(backend); } void region_start(const std::string &name) { - return Delegator::region_start(name); + return Delegator::RegionStart(name); } void region_stop(const std::string &name) { - return Delegator::region_stop(name); + return Delegator::RegionStop(name); } -void finalize() { return Delegator::finalize(); } +void finalize() { return Delegator::Finalize(); } } // namespace nesmik diff --git a/src/strategies.hpp b/src/strategies.hpp index 4d63982..7880da0 100644 --- a/src/strategies.hpp +++ b/src/strategies.hpp @@ -5,34 +5,35 @@ #include #include -struct PNRegionInformation { +struct ProperlyNestedRegionInformation { std::string_view name; }; - -struct NPNRegionInformation { +struct NotProperlyNestedRegionInformation { std::string_view name; }; - // A backend implementing the Properly Nested Profiling -class PNProfilingStrategy { +class ProperlyNestedAnnotationStrategy { public: - virtual ~PNProfilingStrategy() = default; - virtual void region_start(const PNRegionInformation ®ion) noexcept = 0; - virtual void region_stop(const PNRegionInformation ®ion) noexcept = 0; - virtual void init() noexcept = 0; - virtual void finalize() noexcept = 0; + virtual ~ProperlyNestedAnnotationStrategy() = default; + virtual void Init() noexcept = 0; + virtual void + RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void + RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void Finalize() noexcept = 0; }; -class NPNProfilingStrategy { +class NotProperlyNestedAnnotationStrategy { public: - virtual ~NPNProfilingStrategy() = default; - virtual void region_start(const NPNRegionInformation ®ion) noexcept = 0; - virtual void region_stop(const NPNRegionInformation ®ion) noexcept = 0; - virtual void init() noexcept = 0; - virtual void finalize() noexcept = 0; + virtual void Init() noexcept = 0; + virtual ~NotProperlyNestedAnnotationStrategy() = default; + virtual void + RegionStart(const NotProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void + RegionStop(const NotProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void Finalize() noexcept = 0; }; - #endif // NESMIK_STRATEGY_HPP \ No newline at end of file diff --git a/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp index a91b6d7..f1f57bd 100644 --- a/tests/cpp/TestCppDLB.cpp +++ b/tests/cpp/TestCppDLB.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("TALP"); + nesmik::init("PN;TALP"); nesmik::region_start("Default"); nesmik::region_stop("Default"); nesmik::finalize(); diff --git a/tests/cpp/TestCppExtraeTypeStack.cpp b/tests/cpp/TestCppExtraeTypeStack.cpp index d88f34f..07cb779 100644 --- a/tests/cpp/TestCppExtraeTypeStack.cpp +++ b/tests/cpp/TestCppExtraeTypeStack.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("Extrae::TypeStack"); + nesmik::init("PN;Extrae::TypeStack"); nesmik::region_start("init"); nesmik::region_start("init_ts"); diff --git a/tests/cpp/TestCppLink.cpp b/tests/cpp/TestCppLink.cpp index 1a0dfe0..6edeb78 100644 --- a/tests/cpp/TestCppLink.cpp +++ b/tests/cpp/TestCppLink.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("Default"); + nesmik::init("PN;Default"); nesmik::region_start("Default"); nesmik::region_stop("Default"); nesmik::finalize(); diff --git a/tests/fortran/TestFortranModule.f90 b/tests/fortran/TestFortranModule.f90 index e742b0e..1578a52 100644 --- a/tests/fortran/TestFortranModule.f90 +++ b/tests/fortran/TestFortranModule.f90 @@ -1,5 +1,5 @@ program do_sample use nesmik_mod - call init("Default") + call init("PN;Default") call region_start("test") end program do_sample \ No newline at end of file -- GitLab From 7176d9fa76befd8282cbfdf632bae7d48eb14dcb Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 11 Jun 2024 15:58:56 +0200 Subject: [PATCH 2/7] apply clang format --- src/delegator.cpp | 67 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/src/delegator.cpp b/src/delegator.cpp index d1dbe4b..8fd5f41 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -144,46 +144,45 @@ void Delegator::Init(std::string_view initString) { } switch (nesting_mode_) { - case NestingMode::Detecion: - case NestingMode::NotProperlyNested: - return npn_annotation_strategy_->Init(); - case NestingMode::ProperlyNested: - return pn_annotation_strategy_->Init(); - break; - } - + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->Init(); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->Init(); + break; + } } // should be thread safe to call? void Delegator::RegionStart(std::string_view name) { - switch (nesting_mode_) { - case NestingMode::Detecion: - case NestingMode::NotProperlyNested: - return npn_annotation_strategy_->RegionStart({name}); - case NestingMode::ProperlyNested: - return pn_annotation_strategy_->RegionStart({name}); - break; - } + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->RegionStart({name}); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->RegionStart({name}); + break; + } } void Delegator::RegionStop(std::string_view name) { - switch (nesting_mode_) { - case NestingMode::Detecion: - case NestingMode::NotProperlyNested: - return npn_annotation_strategy_->RegionStop({name}); - case NestingMode::ProperlyNested: - return pn_annotation_strategy_->RegionStopLast({name}); - break; - } + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->RegionStop({name}); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->RegionStopLast({name}); + break; + } }; -void Delegator::Finalize() { +void Delegator::Finalize() { - switch (nesting_mode_) { - case NestingMode::Detecion: - case NestingMode::NotProperlyNested: - return npn_annotation_strategy_->Finalize(); - case NestingMode::ProperlyNested: - return pn_annotation_strategy_->Finalize(); - break; - } - }; + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->Finalize(); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->Finalize(); + break; + } +}; -- GitLab From d1c210a8d18b753fa23807579b23000536a563ea Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 11 Jun 2024 17:01:54 +0200 Subject: [PATCH 3/7] REfacrtreed even more --- include/nesmik/nesmik.hpp | 2 +- src/bindings/nesmik.json | 128 ++++++++++++++++++++++--- src/bindings/nesmik.log | 10 +- src/bindings/nesmik.yaml | 2 +- src/bindings/wrapfnesmik.f | 16 +++- src/bindings/wrapnesmik.cpp | 12 ++- src/bindings/wrapnesmik.h | 5 +- src/delegator.cpp | 136 ++++++++++----------------- src/delegator.hpp | 8 +- src/nesmik.cpp | 2 +- tests/cpp/TestCppDLB.cpp | 2 +- tests/cpp/TestCppExtraeTypeStack.cpp | 2 +- tests/cpp/TestCppLink.cpp | 2 +- tests/fortran/TestFortranModule.f90 | 2 +- 14 files changed, 207 insertions(+), 122 deletions(-) diff --git a/include/nesmik/nesmik.hpp b/include/nesmik/nesmik.hpp index bea4375..e7d14ea 100644 --- a/include/nesmik/nesmik.hpp +++ b/include/nesmik/nesmik.hpp @@ -1,7 +1,7 @@ #include namespace nesmik { -void init(const std::string &backend); +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 finalize(); diff --git a/src/bindings/nesmik.json b/src/bindings/nesmik.json index 9eb5a9e..f124649 100644 --- a/src/bindings/nesmik.json +++ b/src/bindings/nesmik.json @@ -18,6 +18,25 @@ }, "name": "init", "params": [ + { + "const": true, + "declarator": { + "metaattrs": { + "intent": "in" + }, + "name": "nesting_mode", + "pointer": [ + { + "ptr": "&" + } + ], + "typemap_name": "std::string" + }, + "specifier": [ + "std::string" + ], + "typemap_name": "std::string" + }, { "const": true, "declarator": { @@ -45,8 +64,8 @@ ], "typemap_name": "void" }, - "decl": "void init(const std::string &backend)", - "declgen": "void init(const std::string & backend)", + "decl": "void init(const std::string &nesting_mode, const std::string &backend)", + "declgen": "void init(const std::string & nesting_mode, const std::string & backend)", "linenumber": 8, "name": "init", "options": {}, @@ -83,20 +102,49 @@ "f_var": "backend", "sh_type": "SH_TYPE_OTHER" } + }, + "nesting_mode": { + "fmtc": { + "c_addr": "", + "c_const": "const ", + "c_deref": "*", + "c_member": "->", + "c_type": "char", + "c_var": "nesting_mode", + "cfi_type": "CFI_type_other", + "cxx_addr": "&", + "cxx_member": ".", + "cxx_nonconst_ptr": "const_cast\t(&SHCXX_nesting_mode)", + "cxx_type": "std::string", + "cxx_var": "SHCXX_nesting_mode", + "idtor": "0", + "sh_type": "SH_TYPE_OTHER", + "stmt0": "c_in_string_&", + "stmt1": "c_in_string_&" + }, + "fmtf": { + "F_C_var": "nesting_mode", + "c_var": "nesting_mode", + "f_intent": "IN", + "f_kind": "C_CHAR", + "f_type": "character(*)", + "f_var": "nesting_mode", + "sh_type": "SH_TYPE_OTHER" + } } }, "zz_fmtdict": { - "C_call_list": "SHCXX_backend", + "C_call_list": "SHCXX_nesting_mode,\t SHCXX_backend", "C_name": "nesmik_init", "C_name_api": "init", - "C_prototype": "const char * backend", + "C_prototype": "const char * nesting_mode,\t const char * backend", "C_return_type": "void", - "F_C_arguments": "backend", + "F_C_arguments": "nesting_mode,\t backend", "F_C_call": "c_init_bufferify", "F_C_name": "c_init", "F_C_subprogram": "subroutine", - "F_arg_c_call": "backend,\t SHT_backend_len", - "F_arguments": "backend", + "F_arg_c_call": "nesting_mode,\t SHT_nesting_mode_len,\t backend,\t SHT_backend_len", + "F_arguments": "nesting_mode,\t backend", "F_name_api": "init", "F_name_function": "init", "F_name_generic": "init", @@ -119,6 +167,26 @@ }, "name": "init", "params": [ + { + "const": true, + "declarator": { + "metaattrs": { + "api": "buf", + "intent": "in" + }, + "name": "nesting_mode", + "pointer": [ + { + "ptr": "&" + } + ], + "typemap_name": "std::string" + }, + "specifier": [ + "std::string" + ], + "typemap_name": "std::string" + }, { "const": true, "declarator": { @@ -147,8 +215,8 @@ ], "typemap_name": "void" }, - "decl": "void init(const std::string &backend)", - "declgen": "void init(const std::string & backend)", + "decl": "void init(const std::string &nesting_mode, const std::string &backend)", + "declgen": "void init(const std::string & nesting_mode, const std::string & backend)", "linenumber": 8, "name": "init", "options": {}, @@ -193,15 +261,51 @@ "stmtc0": "c_in_string_&_buf", "stmtc1": "c_in_string_&_buf" } + }, + "nesting_mode": { + "fmtc": { + "c_addr": "", + "c_const": "const ", + "c_deref": "*", + "c_member": "->", + "c_type": "char", + "c_var": "nesting_mode", + "c_var_len": "SHT_nesting_mode_len", + "cfi_type": "CFI_type_other", + "cxx_addr": "&", + "cxx_member": ".", + "cxx_nonconst_ptr": "const_cast\t(&SHCXX_nesting_mode)", + "cxx_type": "std::string", + "cxx_var": "SHCXX_nesting_mode", + "hnamefunc0": "ShroudLenTrim", + "idtor": "0", + "sh_type": "SH_TYPE_OTHER", + "stmt0": "c_in_string_&_buf", + "stmt1": "c_in_string_&_buf" + }, + "fmtf": { + "F_C_var": "nesting_mode", + "c_var": "nesting_mode", + "c_var_len": "SHT_nesting_mode_len", + "f_intent": "IN", + "f_kind": "C_CHAR", + "f_type": "character(*)", + "f_var": "nesting_mode", + "sh_type": "SH_TYPE_OTHER", + "stmt0": "f_in_string_&_buf", + "stmt1": "f_in_string_&_buf", + "stmtc0": "c_in_string_&_buf", + "stmtc1": "c_in_string_&_buf" + } } }, "zz_fmtdict": { - "C_call_list": "SHCXX_backend", + "C_call_list": "SHCXX_nesting_mode,\t SHCXX_backend", "C_name": "nesmik_init_bufferify", "C_name_api": "init", - "C_prototype": "char *backend,\t int SHT_backend_len", + "C_prototype": "char *nesting_mode,\t int SHT_nesting_mode_len,\t char *backend,\t int SHT_backend_len", "C_return_type": "void", - "F_C_arguments": "backend,\t SHT_backend_len", + "F_C_arguments": "nesting_mode,\t SHT_nesting_mode_len,\t backend,\t SHT_backend_len", "F_C_name": "c_init_bufferify", "F_C_subprogram": "subroutine", "F_name_api": "init", diff --git a/src/bindings/nesmik.log b/src/bindings/nesmik.log index d2cf656..d90a031 100644 --- a/src/bindings/nesmik.log +++ b/src/bindings/nesmik.log @@ -1,6 +1,6 @@ Read yaml nesmik.yaml -C void init(const std::string & backend) +intent(subroutine) -C void init(const std::string & backend) +intent(subroutine) +C void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) +C void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) 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) @@ -8,12 +8,12 @@ C void region_stop(const std::string & name) +intent(subroutine) C void finalize(void) +intent(subroutine) Close wrapnesmik.h Close wrapnesmik.cpp -Fortran void init(const std::string & backend) +intent(subroutine) +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 finalize(void) +intent(subroutine) -C-interface void init(const std::string & backend) +intent(subroutine) -C-interface void init(const std::string & backend) +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) 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) diff --git a/src/bindings/nesmik.yaml b/src/bindings/nesmik.yaml index a599075..2905d1d 100644 --- a/src/bindings/nesmik.yaml +++ b/src/bindings/nesmik.yaml @@ -5,7 +5,7 @@ format: C_prefix: 'nesmik_' declarations: -- decl: void init(const std::string &backend) +- 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 finalize() \ No newline at end of file diff --git a/src/bindings/wrapfnesmik.f b/src/bindings/wrapfnesmik.f index c04ff1b..74029b1 100644 --- a/src/bindings/wrapfnesmik.f +++ b/src/bindings/wrapfnesmik.f @@ -16,17 +16,21 @@ module nesmik_mod interface - subroutine c_init(backend) & + subroutine c_init(nesting_mode, backend) & bind(C, name="nesmik_init") use iso_c_binding, only : C_CHAR implicit none + character(kind=C_CHAR), intent(IN) :: nesting_mode(*) character(kind=C_CHAR), intent(IN) :: backend(*) end subroutine c_init - subroutine c_init_bufferify(backend, SHT_backend_len) & + subroutine c_init_bufferify(nesting_mode, SHT_nesting_mode_len, & + backend, SHT_backend_len) & bind(C, name="nesmik_init_bufferify") use iso_c_binding, only : C_CHAR, C_INT implicit none + character(kind=C_CHAR), intent(IN) :: nesting_mode(*) + integer(C_INT), value, intent(IN) :: SHT_nesting_mode_len character(kind=C_CHAR), intent(IN) :: backend(*) integer(C_INT), value, intent(IN) :: SHT_backend_len end subroutine c_init_bufferify @@ -72,13 +76,17 @@ module nesmik_mod contains - subroutine init(backend) + subroutine init(nesting_mode, backend) use iso_c_binding, only : C_INT + character(len=*), intent(IN) :: nesting_mode character(len=*), intent(IN) :: backend ! splicer begin function.init + integer(C_INT) SHT_nesting_mode_len integer(C_INT) SHT_backend_len + SHT_nesting_mode_len = len(nesting_mode, kind=C_INT) SHT_backend_len = len(backend, kind=C_INT) - call c_init_bufferify(backend, SHT_backend_len) + call c_init_bufferify(nesting_mode, SHT_nesting_mode_len, & + backend, SHT_backend_len) ! splicer end function.init end subroutine init diff --git a/src/bindings/wrapnesmik.cpp b/src/bindings/wrapnesmik.cpp index 03e841b..9253128 100644 --- a/src/bindings/wrapnesmik.cpp +++ b/src/bindings/wrapnesmik.cpp @@ -29,20 +29,24 @@ static int ShroudLenTrim(const char *src, int nsrc) { // splicer begin C_definitions // splicer end C_definitions -void nesmik_init(const char * backend) +void nesmik_init(const char * nesting_mode, const char * backend) { // splicer begin function.init + const std::string SHCXX_nesting_mode(nesting_mode); const std::string SHCXX_backend(backend); - nesmik::init(SHCXX_backend); + nesmik::init(SHCXX_nesting_mode, SHCXX_backend); // splicer end function.init } -void nesmik_init_bufferify(char *backend, int SHT_backend_len) +void nesmik_init_bufferify(char *nesting_mode, int SHT_nesting_mode_len, + char *backend, int SHT_backend_len) { // splicer begin function.init_bufferify + const std::string SHCXX_nesting_mode(nesting_mode, + ShroudLenTrim(nesting_mode, SHT_nesting_mode_len)); const std::string SHCXX_backend(backend, ShroudLenTrim(backend, SHT_backend_len)); - nesmik::init(SHCXX_backend); + nesmik::init(SHCXX_nesting_mode, SHCXX_backend); // splicer end function.init_bufferify } diff --git a/src/bindings/wrapnesmik.h b/src/bindings/wrapnesmik.h index 30f4f2d..d8833af 100644 --- a/src/bindings/wrapnesmik.h +++ b/src/bindings/wrapnesmik.h @@ -21,9 +21,10 @@ extern "C" { // splicer begin C_declarations // splicer end C_declarations -void nesmik_init(const char * backend); +void nesmik_init(const char * nesting_mode, const char * backend); -void nesmik_init_bufferify(char *backend, int SHT_backend_len); +void nesmik_init_bufferify(char *nesting_mode, int SHT_nesting_mode_len, + char *backend, int SHT_backend_len); void nesmik_region_start(const char * name); diff --git a/src/delegator.cpp b/src/delegator.cpp index 8fd5f41..e068d61 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -18,130 +18,98 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif -std::vector Delegator::SplitString(const std::string &str, - char delimiter) { - std::stringstream string_stream(str); - std::vector v; - std::string s; - while (std::getline(string_stream, s, delimiter)) { - v.push_back(s); - } - return v; -} void Delegator::InitDetectionBackend( - const std::vector &init_strings) { + const std::string_view backend) { std::cout << "Not supported currnently, come back later pls" << std::endl; exit(1); } void Delegator::InitNonProperlyNestedBackends( - const std::vector &init_strings) { + const std::string_view backend) { // check if backend is supplied - - npn_annotation_strategy_ = std::make_unique(); - if (init_strings.size() > 1) { - const auto &backend_string = init_strings[1]; - if (backend_string.compare(NPNDefault::name) == 0) { + + if (backend.compare(NPNDefault::name) == 0) { npn_annotation_strategy_ = std::make_unique(); } #ifdef ENABLE_DLB - else if (backend_string.compare(DLBTalpStrategy::name) == 0) { + else if (backend.compare(DLBTalpStrategy::name) == 0) { npn_annotation_strategy_ = std::make_unique(); } #endif else { - std::cout << "Could not find a matching backend with name" - << backend_string << " now selecting the Default" << std::endl; + npn_annotation_strategy_ = std::make_unique(); + + std::cout << "Could not find a matching PNP backend with name" + << backend << " now selecting the Default" << std::endl; } } - // no backend supplied - else { - std::cout << "No backend name supplied, now selecting the Default" - << std::endl; - npn_annotation_strategy_ = std::make_unique(); - } -} -void Delegator::InitProperlyNestedBackends( - const std::vector &init_strings) { - pn_annotation_strategy_ = std::make_unique(); - if (init_strings.size() > 1) { - const auto &backend_string = init_strings[1]; - if (backend_string.compare(PNDefault::name) == 0) { +void Delegator::InitProperlyNestedBackends( + const std::string_view backend) { + if (backend.compare(PNDefault::name) == 0) { pn_annotation_strategy_ = std::make_unique(); } #ifdef ENABLE_EXTRAE - else if (backend_string.compare(ExtraeTypeStackStrategy::name) == 0) { + else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { pn_annotation_strategy_ = std::make_unique(); } #endif else { - std::cout << "Could not find a matching backend with name" - << backend_string << " now selecting the Default" << std::endl; + std::cout << "Could not find a matching properly nested backend with name" + << backend << " skipping." << std::endl; } } - // no backend supplied - else { - std::cout << "No backend name supplied, now selecting the Default" - << std::endl; - pn_annotation_strategy_ = std::make_unique(); - } -} - -void Delegator::Init(std::string_view initString) { - std::cout << initString << std::endl; +void Delegator::Init(std::string_view nesting_mode ,std::string_view backend) { - // First lets check split the init string by "," - std::vector init_strings = - SplitString(std::string(initString), ';'); + std::cout << nesting_mode << "Backend:" << backend << std::endl; - // check if init_string is long enough - if (init_strings.size() > 0) { - const auto nesting_mode_str = init_strings[0]; + + // detect nesting mode requested by the user + if (nesting_mode.compare("?") == 0) { + nesting_mode_ = NestingMode::Detecion; + } else if (nesting_mode.compare("ProperlyNested") == 0) { + nesting_mode_ = NestingMode::ProperlyNested; + } else if (nesting_mode.compare("NotProperlyNested") == 0) { + nesting_mode_ = NestingMode::NotProperlyNested; + } - // detect nesting mode requested by the user - if (nesting_mode_str.compare("?") == 0) { - nesting_mode_ = NestingMode::Detecion; - } else if (nesting_mode_str.compare("PN") == 0) { - nesting_mode_ = NestingMode::ProperlyNested; - } else if (nesting_mode_str.compare("PN") == 0) { - nesting_mode_ = NestingMode::NotProperlyNested; - } - // Some debug output - switch (nesting_mode_) { - case NestingMode::Detecion: - std::cout << "Selecting nesting mode to: " - << "detecting nesting behavior" << std::endl; - break; - case NestingMode::NotProperlyNested: - std::cout << "Selecting nesting mode to: " - << "non properly nested behavior" << std::endl; - break; - case NestingMode::ProperlyNested: - std::cout << "Selecting nesting mode to: " - << "assume properly nested behavior" << std::endl; - break; - } + // Some debug output + switch (nesting_mode_) { + case NestingMode::Detecion: + std::cout << "Selecting nesting mode to: " + << "detecting nesting behavior" << std::endl; + break; + case NestingMode::NotProperlyNested: + std::cout << "Selecting nesting mode to: " + << "non properly nested behavior" << std::endl; + break; + case NestingMode::ProperlyNested: + std::cout << "Selecting nesting mode to: " + << "assume properly nested behavior" << std::endl; + break; + } // next choose backend - switch (nesting_mode_) { case NestingMode::Detecion: - InitDetectionBackend(init_strings); - break; - case NestingMode::NotProperlyNested: - InitNonProperlyNestedBackends(init_strings); + InitDetectionBackend(backend); break; case NestingMode::ProperlyNested: - InitProperlyNestedBackends(init_strings); + case NestingMode::NotProperlyNested: + // we preferably use a Propely nested backend, + // but if this is not possible, we will select the not properly nested one + InitProperlyNestedBackends(backend); + if(pn_annotation_strategy_ == nullptr){ + std::cout << "No ProperlyNested backend found, proceeding with Not Properly Nested Backend" << std::endl; + InitNonProperlyNestedBackends(backend); + nesting_mode_ = NestingMode::NotProperlyNested; + } break; } - } else { - InitDetectionBackend(init_strings); - } + switch (nesting_mode_) { case NestingMode::Detecion: diff --git a/src/delegator.hpp b/src/delegator.hpp index 20eddcc..124ce99 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -18,7 +18,7 @@ private: inline static NestingMode nesting_mode_ = NestingMode::Detecion; public: - static void Init(std::string_view initString); + 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 Finalize(); @@ -27,10 +27,10 @@ private: static std::vector SplitString(const std::string &str, char delimiter); static void - InitDetectionBackend(const std::vector &init_strings); + InitDetectionBackend(const std::string_view backend); static void - InitNonProperlyNestedBackends(const std::vector &init_strings); + InitNonProperlyNestedBackends(const std::string_view backend); static void - InitProperlyNestedBackends(const std::vector &init_strings); + InitProperlyNestedBackends(const std::string_view backend); }; #endif // NESMIK_DELEGATOR_HPP \ No newline at end of file diff --git a/src/nesmik.cpp b/src/nesmik.cpp index 7c15bb1..f622d43 100644 --- a/src/nesmik.cpp +++ b/src/nesmik.cpp @@ -6,7 +6,7 @@ // provides a c-like way to call things with just a fuction compared to // instanciate a class. namespace nesmik { -void init(const std::string &backend) { return Delegator::Init(backend); } +void init(const std::string &nesting_mode, const std::string &backend) { return Delegator::Init(nesting_mode,backend); } void region_start(const std::string &name) { return Delegator::RegionStart(name); } diff --git a/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp index f1f57bd..2ba1cba 100644 --- a/tests/cpp/TestCppDLB.cpp +++ b/tests/cpp/TestCppDLB.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("PN;TALP"); + nesmik::init("NotProperlyNested","TALP"); nesmik::region_start("Default"); nesmik::region_stop("Default"); nesmik::finalize(); diff --git a/tests/cpp/TestCppExtraeTypeStack.cpp b/tests/cpp/TestCppExtraeTypeStack.cpp index 07cb779..25bb92f 100644 --- a/tests/cpp/TestCppExtraeTypeStack.cpp +++ b/tests/cpp/TestCppExtraeTypeStack.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("PN;Extrae::TypeStack"); + nesmik::init("ProperlyNested","Extrae::TypeStack"); nesmik::region_start("init"); nesmik::region_start("init_ts"); diff --git a/tests/cpp/TestCppLink.cpp b/tests/cpp/TestCppLink.cpp index 6edeb78..79d5ae2 100644 --- a/tests/cpp/TestCppLink.cpp +++ b/tests/cpp/TestCppLink.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("PN;Default"); + nesmik::init("ProperlyNested","Default"); nesmik::region_start("Default"); nesmik::region_stop("Default"); nesmik::finalize(); diff --git a/tests/fortran/TestFortranModule.f90 b/tests/fortran/TestFortranModule.f90 index 1578a52..f201873 100644 --- a/tests/fortran/TestFortranModule.f90 +++ b/tests/fortran/TestFortranModule.f90 @@ -1,5 +1,5 @@ program do_sample use nesmik_mod - call init("PN;Default") + call init("ProperlyNested","Default") call region_start("test") end program do_sample \ No newline at end of file -- GitLab From ac5c799dc2223f45cce13d0c75fd8448e2124534 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 11 Jun 2024 17:03:05 +0200 Subject: [PATCH 4/7] apply clang-format --- src/delegator.cpp | 93 ++++++++++++++++++++++------------------------- src/delegator.hpp | 11 ++---- src/nesmik.cpp | 4 +- 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/src/delegator.cpp b/src/delegator.cpp index e068d61..105f979 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -18,55 +18,49 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif - -void Delegator::InitDetectionBackend( - const std::string_view backend) { +void Delegator::InitDetectionBackend(const std::string_view backend) { std::cout << "Not supported currnently, come back later pls" << std::endl; exit(1); } -void Delegator::InitNonProperlyNestedBackends( - const std::string_view backend) { +void Delegator::InitNonProperlyNestedBackends(const std::string_view backend) { // check if backend is supplied - - if (backend.compare(NPNDefault::name) == 0) { - npn_annotation_strategy_ = std::make_unique(); - } + + if (backend.compare(NPNDefault::name) == 0) { + npn_annotation_strategy_ = std::make_unique(); + } #ifdef ENABLE_DLB - else if (backend.compare(DLBTalpStrategy::name) == 0) { - npn_annotation_strategy_ = std::make_unique(); - } + else if (backend.compare(DLBTalpStrategy::name) == 0) { + npn_annotation_strategy_ = std::make_unique(); + } #endif - else { - npn_annotation_strategy_ = std::make_unique(); + else { + npn_annotation_strategy_ = std::make_unique(); - std::cout << "Could not find a matching PNP backend with name" - << backend << " now selecting the Default" << std::endl; - } + std::cout << "Could not find a matching PNP backend with name" << backend + << " now selecting the Default" << std::endl; } +} - -void Delegator::InitProperlyNestedBackends( - const std::string_view backend) { - if (backend.compare(PNDefault::name) == 0) { - pn_annotation_strategy_ = std::make_unique(); - } +void Delegator::InitProperlyNestedBackends(const std::string_view backend) { + if (backend.compare(PNDefault::name) == 0) { + pn_annotation_strategy_ = std::make_unique(); + } #ifdef ENABLE_EXTRAE - else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { - pn_annotation_strategy_ = std::make_unique(); - } + else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { + pn_annotation_strategy_ = std::make_unique(); + } #endif - else { - std::cout << "Could not find a matching properly nested backend with name" - << backend << " skipping." << std::endl; - } + else { + std::cout << "Could not find a matching properly nested backend with name" + << backend << " skipping." << std::endl; } +} -void Delegator::Init(std::string_view nesting_mode ,std::string_view backend) { +void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { std::cout << nesting_mode << "Backend:" << backend << std::endl; - // detect nesting mode requested by the user if (nesting_mode.compare("?") == 0) { nesting_mode_ = NestingMode::Detecion; @@ -92,24 +86,25 @@ void Delegator::Init(std::string_view nesting_mode ,std::string_view backend) { break; } - // next choose backend - switch (nesting_mode_) { - case NestingMode::Detecion: - InitDetectionBackend(backend); - break; - case NestingMode::ProperlyNested: - case NestingMode::NotProperlyNested: - // we preferably use a Propely nested backend, - // but if this is not possible, we will select the not properly nested one - InitProperlyNestedBackends(backend); - if(pn_annotation_strategy_ == nullptr){ - std::cout << "No ProperlyNested backend found, proceeding with Not Properly Nested Backend" << std::endl; - InitNonProperlyNestedBackends(backend); - nesting_mode_ = NestingMode::NotProperlyNested; - } - break; + // next choose backend + switch (nesting_mode_) { + case NestingMode::Detecion: + InitDetectionBackend(backend); + break; + case NestingMode::ProperlyNested: + case NestingMode::NotProperlyNested: + // we preferably use a Propely nested backend, + // but if this is not possible, we will select the not properly nested one + InitProperlyNestedBackends(backend); + if (pn_annotation_strategy_ == nullptr) { + std::cout << "No ProperlyNested backend found, proceeding with Not " + "Properly Nested Backend" + << std::endl; + InitNonProperlyNestedBackends(backend); + nesting_mode_ = NestingMode::NotProperlyNested; } - + break; + } switch (nesting_mode_) { case NestingMode::Detecion: diff --git a/src/delegator.hpp b/src/delegator.hpp index 124ce99..1e67cf0 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -18,7 +18,7 @@ private: inline static NestingMode nesting_mode_ = NestingMode::Detecion; public: - static void Init(std::string_view nesting_mode ,std::string_view backend); + 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 Finalize(); @@ -26,11 +26,8 @@ public: private: static std::vector SplitString(const std::string &str, char delimiter); - static void - InitDetectionBackend(const std::string_view backend); - static void - InitNonProperlyNestedBackends(const std::string_view backend); - static void - InitProperlyNestedBackends(const std::string_view backend); + static void InitDetectionBackend(const std::string_view backend); + static void InitNonProperlyNestedBackends(const std::string_view backend); + static void InitProperlyNestedBackends(const std::string_view backend); }; #endif // NESMIK_DELEGATOR_HPP \ No newline at end of file diff --git a/src/nesmik.cpp b/src/nesmik.cpp index f622d43..34fa942 100644 --- a/src/nesmik.cpp +++ b/src/nesmik.cpp @@ -6,7 +6,9 @@ // provides a c-like way to call things with just a fuction compared to // instanciate a class. namespace nesmik { -void init(const std::string &nesting_mode, const std::string &backend) { return Delegator::Init(nesting_mode,backend); } +void init(const std::string &nesting_mode, const std::string &backend) { + return Delegator::Init(nesting_mode, backend); +} void region_start(const std::string &name) { return Delegator::RegionStart(name); } -- GitLab From 73b86dba750dcef6995a90f8a46e737f6f236c30 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 13 Jun 2024 10:51:48 +0200 Subject: [PATCH 5/7] minor fixes --- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 22 +++++++++---------- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 10 ++++----- tests/cpp/TestCppTalpTree.cpp | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 292cd18..cefe614 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -8,8 +8,8 @@ #include #include -void DLBTalpTreeStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +void DLBTalpTreeStrategy::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. @@ -36,11 +36,11 @@ void DLBTalpTreeStrategy::region_start( this->current_region = region_hash; std::string name = std::to_string((unsigned int) region_hash); - this->talp_profiling_strategy.region_start({name}); + this->talp_profiling_strategy.RegionStart({name}); } -void DLBTalpTreeStrategy::region_stop( - const PNRegionInformation ®ion) noexcept { +void DLBTalpTreeStrategy::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { auto current_region = this->regions[this->current_region]; @@ -62,10 +62,10 @@ void DLBTalpTreeStrategy::region_stop( this->current_region = current_region.parent; - this->talp_profiling_strategy.region_stop({name}); + this->talp_profiling_strategy.RegionStart({name}); } -void DLBTalpTreeStrategy::init() noexcept { +void DLBTalpTreeStrategy::Init() noexcept { this->current_region = std::hash{}(this->top_region); this->regions[this->current_region] = { @@ -75,12 +75,12 @@ void DLBTalpTreeStrategy::init() noexcept { /* .childs */ {}, }; - this->talp_profiling_strategy.init(); + this->talp_profiling_strategy.Init(); } -void DLBTalpTreeStrategy::finalize() noexcept { +void DLBTalpTreeStrategy::Finalize() noexcept { - this->talp_profiling_strategy.region_stop({.name = this->top_region}); + this->talp_profiling_strategy.RegionStop({.name = this->top_region}); std::size_t max_width = 0; @@ -203,5 +203,5 @@ void DLBTalpTreeStrategy::finalize() noexcept { csv_stream.open("nesmik_talp_tree.csv", std::ios::trunc); csv_stream << region_stream_csv.str() << std::endl; - this->talp_profiling_strategy.finalize(); + this->talp_profiling_strategy.Finalize(); } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index d2a58ca..a1c7823 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -15,7 +15,7 @@ struct TalpRegionNode { std::vector childs; }; -class DLBTalpTreeStrategy : public PNProfilingStrategy { +class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { private: DLBTalpStrategy talp_profiling_strategy; @@ -27,10 +27,10 @@ private: public: inline static const std::string_view name = "TALP-Tree"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; #endif // DLB_TALP_TREE_H diff --git a/tests/cpp/TestCppTalpTree.cpp b/tests/cpp/TestCppTalpTree.cpp index 35610bc..bfe90d2 100644 --- a/tests/cpp/TestCppTalpTree.cpp +++ b/tests/cpp/TestCppTalpTree.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("TALP-Tree"); + nesmik::init("ProperlyNested","TALP-Tree"); nesmik::region_start("Top"); nesmik::region_start("child-1"); nesmik::region_start("child-1.1"); -- GitLab From cbf3a5063bfa940383b8d6055f8a5d4f06ecfbe4 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 13 Jun 2024 11:49:09 +0200 Subject: [PATCH 6/7] actually enable the thing again --- src/delegator.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/delegator.cpp b/src/delegator.cpp index 105f979..f389174 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -50,6 +50,11 @@ void Delegator::InitProperlyNestedBackends(const std::string_view backend) { else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { pn_annotation_strategy_ = std::make_unique(); } +#endif +#ifdef ENABLE_DLB + else if (backend.compare(DLBTalpTreeStrategy::name) == 0) { + pn_annotation_strategy_ = std::make_unique(); + } #endif else { std::cout << "Could not find a matching properly nested backend with name" -- GitLab From 26a65dce5c53cfebe645a1ab05c037d8bd3a5990 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Thu, 13 Jun 2024 16:30:30 +0200 Subject: [PATCH 7/7] Apply 1 suggestion(s) to 1 file(s) --- src/backends/dlb/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/dlb/CMakeLists.txt b/src/backends/dlb/CMakeLists.txt index 593fa9d..3a432c4 100644 --- a/src/backends/dlb/CMakeLists.txt +++ b/src/backends/dlb/CMakeLists.txt @@ -3,7 +3,7 @@ if(DLB_FOUND) target_include_directories(nesmik PRIVATE ${DLB_INCLUDE_DIRS}) target_link_libraries(nesmik PUBLIC ${DLB_LIBRARIES}) -target_compile_defInitions(nesmik PRIVATE "ENABLE_DLB") +target_compile_definitions(nesmik PRIVATE "ENABLE_DLB") add_subdirectory(dlb) add_subdirectory(dlb_talp_tree) -- GitLab