diff --git a/CMakeLists.txt b/CMakeLists.txt index 81051690488af14b1d9aa46d17a7ec2e80f47493..d5937e872731ad0083f1350eddf1804424f3a36d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Available backend options option(ENABLE_EXTRAE "Enable Extrae" OFF) option(ENABLE_DLB "Enable DLB" OFF) +option(ENABLE_NVTX "Enable NVTX" OFF) # other options options option(BUILD_C_FORTRAN "Enable C and Fortran Interfaces" ON) @@ -86,6 +87,13 @@ if(ENABLE_DLB) endif() +if(ENABLE_NVTX) + find_package(CUDAToolkit REQUIRED COMPONENTS CUDA::nvtx3) + target_link_libraries(nesmik PRIVATE CUDA::nvtx3) + target_compile_definitions(nesmik PRIVATE "ENABLE_NVTX") +endif() + + include(FetchContent) FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index ccb0564a5397f6b7b703b2413df47dfe5f484d72..f8b0022f8c1c241b1256c18fef10d82d481fbc8d 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -7,3 +7,7 @@ endif() if(ENABLE_EXTRAE) add_subdirectory(extrae) endif() + +if(ENABLE_NVTX) + add_subdirectory(nvtx) +endif() diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 7158c24880387e08a69638d141458b364b3ccaab..824c9099f1da7c2e37b8f2574cc09ab1f92cf4fa 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -10,6 +10,6 @@ class NPNDefault : public NotProperlyNestedAnnotationStrategy { &info_to_start) noexcept override; virtual void RegionStop( const NotProperlyNestedRegionInformation &info_to_stop) noexcept override; - virtual void Init() noexcept; - virtual void Finalize() noexcept; + virtual void Init() noexcept override; + virtual void Finalize() noexcept override; }; diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index e1d87582e2d2f52046fa0e987b060145784abef8..f077a6fc99176f76af5c829d09256134f6aed636 100644 --- a/src/backends/detection/detection.hpp +++ b/src/backends/detection/detection.hpp @@ -51,7 +51,7 @@ class DetectionStrategy : public ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation& region) noexcept override; virtual void RegionStopLast( const ProperlyNestedRegionInformation& region) noexcept override; - virtual void Init() noexcept; - virtual void Finalize() noexcept; + virtual void Init() noexcept override; + virtual void Finalize() noexcept override; }; #endif // NESMIK_DETECTION_H diff --git a/src/backends/nvtx/CMakeLists.txt b/src/backends/nvtx/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1fe769843c76edb3b04ca615888f65228ac604b1 --- /dev/null +++ b/src/backends/nvtx/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(nesmik PRIVATE nvtx_pushpop.cpp) diff --git a/src/backends/nvtx/nvtx_pushpop.cpp b/src/backends/nvtx/nvtx_pushpop.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91abf328bfbb850bdd0ebdba5cbe80f0c85d7dff --- /dev/null +++ b/src/backends/nvtx/nvtx_pushpop.cpp @@ -0,0 +1,32 @@ +#include "nvtx_pushpop.hpp" + +#include +extern "C" { +#include +} +NVTXPushPopStrategy::NVTXPushPopStrategy() { + parallelism_descriptor_ = { + .mpi_descriptor_ = MPIDescriptor::DontCare, + .thread_descriptor_ = ThreadDescriptor::Unsupported}; + + domain_ = nvtxDomainCreateA("neSmiK"); +} + +void NVTXPushPopStrategy::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { + nvtxEventAttributes_t eventAttrib; + eventAttrib.version = NVTX_VERSION; + eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; + // Configure the Attributes + eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; + eventAttrib.category = 0; + eventAttrib.message.ascii = std::string(region.name).c_str(); + nvtxDomainRangePushEx(domain_, &eventAttrib); +} + +void NVTXPushPopStrategy::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { + nvtxDomainRangePop(domain_); +} +void NVTXPushPopStrategy::Init() noexcept { return; } +void NVTXPushPopStrategy::Finalize() noexcept { return; } diff --git a/src/backends/nvtx/nvtx_pushpop.hpp b/src/backends/nvtx/nvtx_pushpop.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1a6b9abe1c1a7838560a7663d608e2ae69785568 --- /dev/null +++ b/src/backends/nvtx/nvtx_pushpop.hpp @@ -0,0 +1,23 @@ +#ifndef NESMIK_NVTX_PUSHPOP_H +#define NESMIK_NVTX_PUSHPOP_H + +#include +extern "C" { +#include +} +class NVTXPushPopStrategy : public ProperlyNestedAnnotationStrategy { + private: + nvtxDomainHandle_t domain_; + + public: + NVTXPushPopStrategy(); + inline static const std::string name = "NVTX"; + void RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept override; + void RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; +}; + +#endif // NESMIK_NVTX_PUSHPOP_H diff --git a/src/delegator.cpp b/src/delegator.cpp index 60f68f55374260eb8eba5af1cfc61f344c4d57ac..890eb06ed4e33a6cd5d90e35a85bf4a43c60e403 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -19,6 +19,9 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif +#ifdef ENABLE_NVTX +#include "backends/nvtx/nvtx_pushpop.hpp" +#endif void Delegator::InitDetectionBackend(const std::string &backend) { pn_annotation_strategy_ = std::make_unique(); } @@ -56,6 +59,12 @@ void Delegator::InitProperlyNestedBackends(const std::string &backend) { pn_annotation_strategy_ = std::make_unique(); } #endif +#ifdef ENABLE_NVTX + else if (backend.compare(NVTXPushPopStrategy::name) == 0) { + + pn_annotation_strategy_ = std::make_unique(); + } +#endif } void Delegator::Init(std::string_view nesting_mode, @@ -140,7 +149,6 @@ void Delegator::Init(std::string_view nesting_mode, << std::endl; nesting_mode_ = NestingMode::ProperlyNestedButOtherBackend; } - InitNonProperlyNestedBackends(backend); break; }