From 52f425cba2c2162b16d4c6808c0e49eda27aecc5 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Fri, 9 May 2025 13:55:29 -0700 Subject: [PATCH 01/34] Start with moving over docs, the easiest part... --- docs/CaliperIntegration.rst | 77 +++++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + 2 files changed, 78 insertions(+) create mode 100644 docs/CaliperIntegration.rst diff --git a/docs/CaliperIntegration.rst b/docs/CaliperIntegration.rst new file mode 100644 index 00000000..879359d4 --- /dev/null +++ b/docs/CaliperIntegration.rst @@ -0,0 +1,77 @@ +.. + # Copyright 2021 Lawrence Livermore National Security, LLC and other + # PerfFlowAspect Project Developers. See the top-level LICENSE file for + # details. + # + # SPDX-License-Identifier: LGPL-3.0 + +##################### + Caliper Integration +##################### + +PerfFlowAspect can be built with Caliper to leverage collection of additional +performance data, such as hardware performance counters on CPUs and GPU measurements on +NVIDIA GPUs. `Caliper `_ is an instrumentation and +performance annotation library. A Caliper install is required before building +PerfFlowAspect: + +.. code:: bash + + cmake -Dcaliper_DIR=/share/lib/caliper ../ + +Caliper can be configured at runtime, for example: + +.. code:: bash + + CALI_CONFIG=runtime-report ./smoketest + CALI_CONFIG=runtime-report,output=test.cali ./smoketest + +.. code:: bash + + Path Min time/rank Max time/rank Avg time/rank Time % + _Z3fooRKSs 0.004527 0.004527 0.004527 45.778137 + _Z3barv 0.004511 0.004511 0.004511 45.616341 + _Z3basv 0.000079 0.000079 0.000079 0.798867 + +.. code:: bash + + CALI_PAPI_COUNTERS=PAPI_TOT_CYC,PAPI_L2_DCM CALI_SERVICES_ENABLE=event,trace,papi,report ./smoketest + +.. code:: bash + + event.begin#annotation papi.PAPI_TOT_CYC papi.PAPI_L2_DCM annotation region.count event.end#annotation + _Z3fooRKSs 118289 679 + _Z3barv 200050 765 _Z3fooRKSs + _Z3basv 115098 352 _Z3fooRKSs/_Z3barv + 66564 242 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 117061 385 _Z3fooRKSs/_Z3barv 1 _Z3barv + 93592 206 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 146308 332 + _Z3barv 87811 255 _Z3fooRKSs + _Z3basv 84904 244 _Z3fooRKSs/_Z3barv + 34547 66 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 82540 168 _Z3fooRKSs/_Z3barv 1 _Z3barv + 80711 144 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 127765 183 + _Z3barv 85440 241 _Z3fooRKSs + _Z3basv 82100 250 _Z3fooRKSs/_Z3barv + 33969 67 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 81511 161 _Z3fooRKSs/_Z3barv 1 _Z3barv + 77498 128 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 119853 164 + _Z3barv 83285 227 _Z3fooRKSs + _Z3basv 82702 297 _Z3fooRKSs/_Z3barv + 34170 78 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 81589 149 _Z3fooRKSs/_Z3barv 1 _Z3barv + 78920 119 _Z3fooRKSs 1 _Z3fooRKSs + +.. code:: bash + + PERFFLOW_OPTIONS='cpu-mem-usage=True:log-event=compact' CALI_CONFIG="load(time_exclusive.json),spot" ./smoketest + +.. code:: bash + + Path Min time/rank Max time/rank Avg time/rank Total time spot.channel + _Z3fooRKSs 0.018068 0.018068 0.018068 0.018068 regionprofile + _Z3barv 0.009124 0.009124 0.009124 0.009124 regionprofile + _Z3basv 0.000074 0.000074 0.000074 0.000074 regionprofile diff --git a/docs/index.rst b/docs/index.rst index a8de2d9b..1d0fa902 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -85,6 +85,7 @@ uniformity as to how performance is measured and controlled. BuildingPerfFlowAspect Annotations + CaliperIntegration UpcomingFeatures .. toctree:: From ee8821d89eb2760638865b788e0d57cfaf1da059 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Fri, 9 May 2025 14:16:25 -0700 Subject: [PATCH 02/34] Update github-actions to include Caliper --- .github/workflows/github-actions.yml | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 38d15ed6..c8202934 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-24.04 strategy: matrix: - config: [boilerplate, release, debug_cuda_only, debug_mpi_only, debug_threads_only] + config: [boilerplate, release, debug_cuda_only, debug_mpi_only, debug_threads_only, boilerplate_caliper] include: - config: boilerplate @@ -17,31 +17,43 @@ jobs: PERFFLOWASPECT_WITH_MPI: ON PERFFLOWASPECT_WITH_MULTITHREADS: ON CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF - config: release PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: ON PERFFLOWASPECT_WITH_MULTITHREADS: ON CMAKE_BUILD_TYPE: Release + PERFFLOWASPECT_WITH_CALIPER: OFF - config: debug_cuda_only PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: OFF PERFFLOWASPECT_WITH_MULTITHREADS: OFF CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF - config: debug_mpi_only PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: ON PERFFLOWASPECT_WITH_MULTITHREADS: OFF CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF - config: debug_threads_only PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: OFF PERFFLOWASPECT_WITH_MULTITHREADS: ON CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF + - config: boilerplate_caliper + PERFFLOWASPECT_WITH_CUDA: OFF + PERFFLOWASPECT_WITH_MPI: OFF + PERFFLOWASPECT_WITH_MULTITHREADS: OFF + CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: ON + steps: # Checkout PerfFlowAspect repository under $GITHUB_WORKSPACE - uses: actions/checkout@v2 @@ -52,6 +64,21 @@ jobs: sudo apt install clang-18 llvm-dev libjansson-dev libssl-dev bison flex make cmake mpich clang++ --version + - name: Clone Caliper + uses: actions/checkout@v2 + with: + repository: LLNL/Caliper + path: Caliper + + - name: Build Caliper + working-directory: Caliper + run: | + mkdir build && mkdir install + cd build + cmake -DCMAKE_INSTALL_PREFIX=../install ../ + make VERBOSE=1 + make install + - name: Compile check run: | cd src/c @@ -62,6 +89,7 @@ jobs: export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_CUDA=${{matrix.PERFFLOWASPECT_WITH_CUDA}}" export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_MPI=${{matrix.PERFFLOWASPECT_WITH_MPI}}" export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_MULTITHREADS=${{matrix.PERFFLOWASPECT_WITH_MULTITHREADS}}" + export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_CALIPER=${{matrix.PERFFLOWASPECT_WITH_CALIPER}} -Dcaliper_DIR=/home/runner/work/PerfFlowAspect/PerfFlowAspect/Caliper/install" echo -e ${CMAKE_OPTS} cmake ${CMAKE_OPTS} .. # build From 2cbe9f1aef94f0a748540b56eea68dd13c69de81 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Fri, 9 May 2025 14:29:24 -0700 Subject: [PATCH 03/34] Add Caliper build option, FindCaliper.cmake, and update Setup3rdparty.cmake --- src/c/CMakeLists.txt | 3 +++ src/c/cmake/Setup3rdParty.cmake | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/c/CMakeLists.txt b/src/c/CMakeLists.txt index 8d12a5a8..fd87b485 100644 --- a/src/c/CMakeLists.txt +++ b/src/c/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.12) project(PerfFlowAspect VERSION "0.1.0") +# Higher-level build options. +option(PERFFLOWASPECT_WITH_CALIPER "Build with Caliper support" ON) + # Fail if using Clang < 18.0 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) diff --git a/src/c/cmake/Setup3rdParty.cmake b/src/c/cmake/Setup3rdParty.cmake index d7f203a6..28e7e088 100644 --- a/src/c/cmake/Setup3rdParty.cmake +++ b/src/c/cmake/Setup3rdParty.cmake @@ -19,3 +19,19 @@ include(cmake/thirdparty/FindOpenSSL.cmake) if(PERFFLOWASPECT_WITH_MULTITHREADS) include(cmake/thirdparty/FindThreads.cmake) endif() + +if(PERFFLOWASPECT_WITH_CALIPER) + # first Check for CALIPER_DIR + if(NOT caliper_DIR) + MESSAGE(FATAL_ERROR "Caliper support needs explicit caliper_DIR") + endif() + + if(caliper_DIR) + message(STATUS "PPP ${caliper_DIR}") + include(cmake/thirdparty/FindCaliper.cmake) + endif() + + if(CALIPER_FOUND) + add_definitions(-DPERFFLOWASPECT_WITH_CALIPER) + endif() +endif() \ No newline at end of file From df3c61faae77d4ad61c077e7615e6aab7a4a43c1 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Fri, 9 May 2025 15:07:23 -0700 Subject: [PATCH 04/34] update cmake setup_targets and setup_deps --- src/c/cmake/thirdparty/FindCaliper.cmake | 31 +++++++++++++++++++ src/c/config/perfflowaspect_setup_deps.cmake | 17 ++++++++++ .../config/perfflowaspect_setup_targets.cmake | 6 ++++ 3 files changed, 54 insertions(+) create mode 100644 src/c/cmake/thirdparty/FindCaliper.cmake create mode 100644 src/c/config/perfflowaspect_setup_deps.cmake create mode 100644 src/c/config/perfflowaspect_setup_targets.cmake diff --git a/src/c/cmake/thirdparty/FindCaliper.cmake b/src/c/cmake/thirdparty/FindCaliper.cmake new file mode 100644 index 00000000..585cd921 --- /dev/null +++ b/src/c/cmake/thirdparty/FindCaliper.cmake @@ -0,0 +1,31 @@ +## most common case: caliper is built with adiak support +## and caliper needs us to find adiak, or else find_pacakge caliper +## will fail +# +## Check for ADIAK_DIR +# +#if(NOT ADIAK_DIR) +# MESSAGE(FATAL_ERROR "Caliper support needs explicit ADIAK_DIR") +#endif() +# +#message(STATUS "Looking for Adiak in: ${ADIAK_DIR}") +# +#find_package(adiak REQUIRED +# NO_DEFAULT_PATH +# PATHS ${ADIAK_DIR}/lib/cmake/adiak) + +message(STATUS "Looking for Caliper in: ${caliper_DIR}") + +find_package(caliper REQUIRED + PATHS ${caliper_DIR}/share/cmake/caliper + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + +message(STATUS "FOUND Caliper: ${caliper_INSTALL_PREFIX}") + +#set(ADIAK_FOUND TRUE) +set(CALIPER_FOUND TRUE) +set(PERFFLOWASPECT_CALIPER_ENABLED TRUE) diff --git a/src/c/config/perfflowaspect_setup_deps.cmake b/src/c/config/perfflowaspect_setup_deps.cmake new file mode 100644 index 00000000..98f6ba02 --- /dev/null +++ b/src/c/config/perfflowaspect_setup_deps.cmake @@ -0,0 +1,17 @@ +include(CMakeFindDependencyMacro) + +if (NOT caliper_DIR) + set(caliper_DIR ${PERFFLOWASPECT_CALIPER_DIR}) +endif() + +if(caliper_DIR) + if(NOT PerfFlowAspect_FIND_QUIETLY) + message(STATUS "PerfFlowAspect was built with Caliper Support") + message(STATUS "Looking for Caliper at: ${caliper_DIR}/share/cmake/caliper") + endif() + + # find caliper + find_package(caliper REQUIRED + NO_DEFAULT_PATH + PATHS ${caliper_DIR}/share/cmake/caliper) +endif() diff --git a/src/c/config/perfflowaspect_setup_targets.cmake b/src/c/config/perfflowaspect_setup_targets.cmake new file mode 100644 index 00000000..ed5d28c7 --- /dev/null +++ b/src/c/config/perfflowaspect_setup_targets.cmake @@ -0,0 +1,6 @@ +# create convenience target that bundles all reg perfflowaspect deps +add_library(perfflowaspect::perfflowaspect INTERFACE IMPORTED) + +set_property(TARGET perfflowaspect::perfflowaspect + PROPERTY INTERFACE_LINK_LIBRARIES + perfflowaspect) From 43fc48f9acc52575317929acc98fc7ef84840759 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Fri, 9 May 2025 19:20:21 -0700 Subject: [PATCH 05/34] Update to src/c/runtime/CMakeLists.txt --- src/c/runtime/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/c/runtime/CMakeLists.txt b/src/c/runtime/CMakeLists.txt index 12e4fba5..05130853 100644 --- a/src/c/runtime/CMakeLists.txt +++ b/src/c/runtime/CMakeLists.txt @@ -14,12 +14,20 @@ set(perfflow_runtime_sources include_directories(${JANSSON_INCLUDE_DIRS}) +if(PERFFLOWASPECT_WITH_CALIPER) + include_directories(${caliper_INCLUDE_DIR}) +endif() + add_library(perfflow_runtime SHARED ${perfflow_runtime_sources} ${perfflow_runtime_headers} ) -target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto) +if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto caliper) +else() + target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto) +endif() install(TARGETS perfflow_runtime EXPORT perfflow_export From 5899e0274374798a56f60aed442084ceecabe829 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Mon, 12 May 2025 18:14:43 -0700 Subject: [PATCH 06/34] Add Caliper linking to src/c/test/CMakeLists.txt --- src/c/test/CMakeLists.txt | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index cb1fa0ee..40f4e3c9 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -12,8 +12,11 @@ foreach(TEST ${SMOKETESTS}) message(STATUS " [*] Adding test: ${TEST}") add_executable(${TEST} ${TEST}.cpp) set_source_files_properties(${TEST}.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fpass-plugin=../weaver/weave/libWeavePass.so -fPIC") + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(${TEST} ${perfflow_deps} caliper) +else() target_link_libraries(${TEST} ${perfflow_deps}) -endforeach() +endif()endforeach() # Build Options option(PERFFLOWASPECT_WITH_MULTITHREADS "Build multi-threaded smoketest" ON) @@ -35,7 +38,11 @@ if(PERFFLOWASPECT_WITH_MULTITHREADS) add_executable(smoketest_MT smoketest_MT.cpp) set_source_files_properties(smoketest_MT.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fpass-plugin=../weaver/weave/libWeavePass.so -fPIC") set(THREADS_PREFER_PTHREAD_FLAG ON) - target_link_libraries(smoketest_MT ${perfflow_deps} pthread) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(smoketest_MT ${perfflow_deps} pthread caliper) + else() + target_link_libraries(smoketest_MT ${perfflow_deps} pthread) + endif() endif() if(PERFFLOWASPECT_WITH_MPI) @@ -43,14 +50,22 @@ if(PERFFLOWASPECT_WITH_MPI) add_executable(smoketest_MPI smoketest_MPI.cpp) set_source_files_properties(smoketest_MPI.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fpass-plugin=../weaver/weave/libWeavePass.so -fPIC") include_directories(${MPI_INCLUDE_PATH}) - target_link_libraries(smoketest_MPI ${perfflow_deps} ${MPI_LIBRARIES}) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(smoketest_MPI ${perfflow_deps} ${MPI_LIBRARIES} caliper) + else() + target_link_libraries(smoketest_MPI ${perfflow_deps} ${MPI_LIBRARIES}) + endif() endif() if(PERFFLOWASPECT_WITH_CUDA) message(STATUS " [*] Adding test: smoketest_cuda") set(CUDA_NVCC_FLAGS "-ccbin ${CMAKE_CXX_COMPILER} -Xcompiler=-Xclang -Xcompiler=-load -Xcompiler=-Xclang -Xcompiler=../../../weaver/weave/libWeavePass.so -Xcompiler=-fpass-plugin=../../../weaver/weave/libWeavePass.so") cuda_add_executable(smoketest_cuda smoketest_cuda_wrapper.cpp smoketest_cuda_kernel.cu) - target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES}) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES} caliper) + else() + target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES}) + endif() endif() configure_file(t0001-cbinding-basic.t.in From f693ee8d17f481978aa1721584beeed4e4fa8ecd Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Mon, 12 May 2025 18:20:36 -0700 Subject: [PATCH 07/34] Add deps and targers to src/c/config/ --- src/c/config/CMakeLists.txt | 2 ++ src/c/config/perfflowaspect-config.cmake.in | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/c/config/CMakeLists.txt b/src/c/config/CMakeLists.txt index 455c4089..959f6897 100644 --- a/src/c/config/CMakeLists.txt +++ b/src/c/config/CMakeLists.txt @@ -42,6 +42,8 @@ configure_package_config_file( install(FILES ${CMAKE_CURRENT_BINARY_DIR}/perfflowaspect-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/perfflowaspect-config-version.cmake + perfflowaspect_setup_deps.cmake + perfflowaspect_setup_targets.cmake DESTINATION ${PERFFLOWASPECT_INSTALL_CMAKE_MODULE_DIR}) # Create pkg-config .pc file diff --git a/src/c/config/perfflowaspect-config.cmake.in b/src/c/config/perfflowaspect-config.cmake.in index 60a9d4a7..7514b7da 100644 --- a/src/c/config/perfflowaspect-config.cmake.in +++ b/src/c/config/perfflowaspect-config.cmake.in @@ -3,6 +3,9 @@ if (NOT PERFFLOWASPECT_CONFIG_LOADED) set(PERFFLOWASPECT_DIR "@CMAKE_INSTALL_PREFIX@") set(PERFFLOWASPECT_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@") + set(PERFFLOWASPECT_CALIPER_ENABLED "@PERFFLOWASPECT_CALIPER_ENABLED@") + set(PERFFLOWASPECT_CALIPER_DIR "@caliper_DIR@") + include(CMakeFindDependencyMacro) find_dependency(OpenSSL REQUIRED) From 8f51e7d8d72724683f9178e3fb44e0a8c17ab3a3 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 14 May 2025 13:56:35 -0700 Subject: [PATCH 08/34] Add caliper instrumentation functionality to perfflow_weave_common. Untested --- src/c/weaver/weave/perfflow_weave_common.cpp | 73 ++++++++++++++++++++ src/c/weaver/weave/perfflow_weave_common.hpp | 11 +++ 2 files changed, 84 insertions(+) diff --git a/src/c/weaver/weave/perfflow_weave_common.cpp b/src/c/weaver/weave/perfflow_weave_common.cpp index 8470388f..315122f9 100644 --- a/src/c/weaver/weave/perfflow_weave_common.cpp +++ b/src/c/weaver/weave/perfflow_weave_common.cpp @@ -26,6 +26,24 @@ bool weave_ns::WeaveCommon::modifyAnnotatedFunctions(Module &m) return false; } + // Support Caliper annotations by greating the cali_begin_region + // and cali_end_region functions. + #ifdef PERFFLOWASPECT_WITH_CALIPER + IRBuilder<> IRB(m.getContext()); + AttrBuilder AB; + AB.addAttribute(Attribute::AlwaysInline); + //It was not added in LLVM@10. + //AB.addAttribute(Attribute::ArgMemOnly); + AttributeList Attrs = AttributeList::get(m.getContext(), + AttributeList::FunctionIndex, AB); + // Insert Functions on the module + CaliBeginRegion = m.getOrInsertFunction("cali_begin_region", Attrs, + IRB.getVoidTy(), IRB.getInt8PtrTy()); + CaliEndRegion = m.getOrInsertFunction("cali_end_region", Attrs, IRB.getVoidTy(), + IRB.getInt8PtrTy()); +#endif + + bool changed = false; if (annotations->getNumOperands() <= 0) @@ -40,6 +58,12 @@ bool weave_ns::WeaveCommon::modifyAnnotatedFunctions(Module &m) auto *fn = dyn_cast (e->getOperand(0)); if (fn != NULL) { +#ifdef PERFFLOWASPECT_WITH_CALIPER + // We insert Caliper Instrumentation before weaver. + // Thus weaver will include Caliper overheads + changed |= instrumentCaliper(m, *fn); +#endif + auto anno = cast( cast(e->getOperand(1)) ->getOperand(0)) @@ -197,6 +221,55 @@ bool weave_ns::WeaveCommon::insertBefore(Module &m, Function &f, StringRef &a, return true; } +#ifdef PERFFLOWASPECT_WITH_CALIPER +bool WeavingPass::instrumentCaliper(Module &M, Function &F) +{ + IRBuilder<> IRB(M.getContext()); + BasicBlock &Entry = F.getEntryBlock(); + SplitBlock(&Entry, &*Entry.getFirstInsertionPt()); + + IRB.SetInsertPoint(Entry.getTerminator()); + std::string FunctionName = F.getName().str(); + auto *FnStr = IRB.CreateGlobalStringPtr(FunctionName); + IRB.CreateCall(CaliBeginRegion, {FnStr}); + + bool RetFound = false; + for (inst_iterator It = inst_begin(F), E = inst_end(F); It != E; ++It) + { + Instruction *I = &*It; + if (!isa(I) && !isa(I) && !isa(I)) + { + continue; + } + + if (isa(I)) + { + IRB.SetInsertPoint(I); + IRB.CreateCall(CaliEndRegion, {FnStr}); + RetFound = true; + } + + // This is a call instruction + CallBase *CB = dyn_cast(I); + if (CB && CB->doesNotReturn()) + { + IRB.SetInsertPoint(I); + IRB.CreateCall(CaliEndRegion, {FnStr}); + RetFound = true; + } + } + + // All functions need to have at least one exit block + if (!RetFound) + { + dbgs() << "Could not find return for " << FunctionName << "\n"; + abort(); + } + + return RetFound; +} +#endif + /* * vi:tabstop=4 shiftwidth=4 expandtab */ diff --git a/src/c/weaver/weave/perfflow_weave_common.hpp b/src/c/weaver/weave/perfflow_weave_common.hpp index 672766cf..12e6f4c8 100644 --- a/src/c/weaver/weave/perfflow_weave_common.hpp +++ b/src/c/weaver/weave/perfflow_weave_common.hpp @@ -20,6 +20,8 @@ #include "llvm/IR/Argument.h" #include "llvm/IR/IRBuilder.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Debug.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "../../parser/perfflow_parser.hpp" using namespace llvm; @@ -36,9 +38,18 @@ class WeaveCommon bool insertBefore(Module &m, Function &f, StringRef &a, int async, std::string &scope, std::string &flow, std::string pcut); +#ifdef PERFFLOWASPECT_WITH_CALIPER + bool instrumentCaliper(Module &m, Function &f); +#endif + public: bool modifyAnnotatedFunctions(Module &m); +#ifdef PERFFLOWASPECT_WITH_CALIPER + FunctionCallee CaliBeginRegion; + FunctionCallee CaliEndRegion; +#endif + }; } // End namespace From c39e520715284566b758c2ab1d4719ffd30c6c57 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 14 May 2025 14:00:55 -0700 Subject: [PATCH 09/34] Fix CMake typo in c/test/ --- src/c/test/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index 40f4e3c9..98df50e7 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -13,10 +13,11 @@ foreach(TEST ${SMOKETESTS}) add_executable(${TEST} ${TEST}.cpp) set_source_files_properties(${TEST}.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fpass-plugin=../weaver/weave/libWeavePass.so -fPIC") if(PERFFLOWASPECT_WITH_CALIPER) - target_link_libraries(${TEST} ${perfflow_deps} caliper) -else() - target_link_libraries(${TEST} ${perfflow_deps}) -endif()endforeach() + target_link_libraries(${TEST} ${perfflow_deps} caliper) + else() + target_link_libraries(${TEST} ${perfflow_deps}) + endif() +endforeach() # Build Options option(PERFFLOWASPECT_WITH_MULTITHREADS "Build multi-threaded smoketest" ON) From fdd6c9376f68496ad84d2661310ecd73784984ba Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 14 May 2025 15:42:28 -0700 Subject: [PATCH 10/34] Attempt to address some Clang18 build errors --- src/c/weaver/weave/perfflow_weave_common.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/c/weaver/weave/perfflow_weave_common.cpp b/src/c/weaver/weave/perfflow_weave_common.cpp index 315122f9..45db2a44 100644 --- a/src/c/weaver/weave/perfflow_weave_common.cpp +++ b/src/c/weaver/weave/perfflow_weave_common.cpp @@ -30,7 +30,7 @@ bool weave_ns::WeaveCommon::modifyAnnotatedFunctions(Module &m) // and cali_end_region functions. #ifdef PERFFLOWASPECT_WITH_CALIPER IRBuilder<> IRB(m.getContext()); - AttrBuilder AB; + AttrBuilder AB(m.getContext()); AB.addAttribute(Attribute::AlwaysInline); //It was not added in LLVM@10. //AB.addAttribute(Attribute::ArgMemOnly); @@ -38,9 +38,9 @@ bool weave_ns::WeaveCommon::modifyAnnotatedFunctions(Module &m) AttributeList::FunctionIndex, AB); // Insert Functions on the module CaliBeginRegion = m.getOrInsertFunction("cali_begin_region", Attrs, - IRB.getVoidTy(), IRB.getInt8PtrTy()); + IRB.getVoidTy(), IRB.getPtrTy()); CaliEndRegion = m.getOrInsertFunction("cali_end_region", Attrs, IRB.getVoidTy(), - IRB.getInt8PtrTy()); + IRB.getPtrTy()); #endif @@ -222,7 +222,7 @@ bool weave_ns::WeaveCommon::insertBefore(Module &m, Function &f, StringRef &a, } #ifdef PERFFLOWASPECT_WITH_CALIPER -bool WeavingPass::instrumentCaliper(Module &M, Function &F) +bool weave_ns::WeaveCommon::instrumentCaliper(Module &M, Function &F) { IRBuilder<> IRB(M.getContext()); BasicBlock &Entry = F.getEntryBlock(); From f6abbcdc8d5841475b97bf1eb00b01fe0b23bac3 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 14 May 2025 15:45:26 -0700 Subject: [PATCH 11/34] Code formatting --- src/c/weaver/weave/perfflow_weave_common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c/weaver/weave/perfflow_weave_common.cpp b/src/c/weaver/weave/perfflow_weave_common.cpp index 45db2a44..398aa648 100644 --- a/src/c/weaver/weave/perfflow_weave_common.cpp +++ b/src/c/weaver/weave/perfflow_weave_common.cpp @@ -26,9 +26,9 @@ bool weave_ns::WeaveCommon::modifyAnnotatedFunctions(Module &m) return false; } - // Support Caliper annotations by greating the cali_begin_region + // Support Caliper annotations by greating the cali_begin_region // and cali_end_region functions. - #ifdef PERFFLOWASPECT_WITH_CALIPER +#ifdef PERFFLOWASPECT_WITH_CALIPER IRBuilder<> IRB(m.getContext()); AttrBuilder AB(m.getContext()); AB.addAttribute(Attribute::AlwaysInline); From 2c318a061e49dfd2eae2431b089396762464f42e Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 14 May 2025 15:50:44 -0700 Subject: [PATCH 12/34] Attempt to fix InstIterator error --- src/c/weaver/weave/perfflow_weave_common.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/c/weaver/weave/perfflow_weave_common.hpp b/src/c/weaver/weave/perfflow_weave_common.hpp index 12e6f4c8..164b8e4c 100644 --- a/src/c/weaver/weave/perfflow_weave_common.hpp +++ b/src/c/weaver/weave/perfflow_weave_common.hpp @@ -21,6 +21,7 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Debug.h" +#include "llvm/IR/InstIterator.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "../../parser/perfflow_parser.hpp" From 505b97439e240f1403a335d71bd4be4b42333cd8 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 14 May 2025 16:25:16 -0700 Subject: [PATCH 13/34] Format rst file --- docs/CaliperIntegration.rst | 84 ++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/CaliperIntegration.rst b/docs/CaliperIntegration.rst index 879359d4..6fd597e5 100644 --- a/docs/CaliperIntegration.rst +++ b/docs/CaliperIntegration.rst @@ -10,68 +10,68 @@ ##################### PerfFlowAspect can be built with Caliper to leverage collection of additional -performance data, such as hardware performance counters on CPUs and GPU measurements on -NVIDIA GPUs. `Caliper `_ is an instrumentation and -performance annotation library. A Caliper install is required before building -PerfFlowAspect: +performance data, such as hardware performance counters on CPUs and GPU +measurements on NVIDIA GPUs. `Caliper `_ is an +instrumentation and performance annotation library. A Caliper install is +required before building PerfFlowAspect: .. code:: bash - cmake -Dcaliper_DIR=/share/lib/caliper ../ + cmake -Dcaliper_DIR=/share/lib/caliper ../ Caliper can be configured at runtime, for example: .. code:: bash - CALI_CONFIG=runtime-report ./smoketest - CALI_CONFIG=runtime-report,output=test.cali ./smoketest + CALI_CONFIG=runtime-report ./smoketest + CALI_CONFIG=runtime-report,output=test.cali ./smoketest .. code:: bash - Path Min time/rank Max time/rank Avg time/rank Time % - _Z3fooRKSs 0.004527 0.004527 0.004527 45.778137 - _Z3barv 0.004511 0.004511 0.004511 45.616341 - _Z3basv 0.000079 0.000079 0.000079 0.798867 + Path Min time/rank Max time/rank Avg time/rank Time % + _Z3fooRKSs 0.004527 0.004527 0.004527 45.778137 + _Z3barv 0.004511 0.004511 0.004511 45.616341 + _Z3basv 0.000079 0.000079 0.000079 0.798867 .. code:: bash - CALI_PAPI_COUNTERS=PAPI_TOT_CYC,PAPI_L2_DCM CALI_SERVICES_ENABLE=event,trace,papi,report ./smoketest + CALI_PAPI_COUNTERS=PAPI_TOT_CYC,PAPI_L2_DCM CALI_SERVICES_ENABLE=event,trace,papi,report ./smoketest .. code:: bash - event.begin#annotation papi.PAPI_TOT_CYC papi.PAPI_L2_DCM annotation region.count event.end#annotation - _Z3fooRKSs 118289 679 - _Z3barv 200050 765 _Z3fooRKSs - _Z3basv 115098 352 _Z3fooRKSs/_Z3barv - 66564 242 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv - 117061 385 _Z3fooRKSs/_Z3barv 1 _Z3barv - 93592 206 _Z3fooRKSs 1 _Z3fooRKSs - _Z3fooRKSs 146308 332 - _Z3barv 87811 255 _Z3fooRKSs - _Z3basv 84904 244 _Z3fooRKSs/_Z3barv - 34547 66 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv - 82540 168 _Z3fooRKSs/_Z3barv 1 _Z3barv - 80711 144 _Z3fooRKSs 1 _Z3fooRKSs - _Z3fooRKSs 127765 183 - _Z3barv 85440 241 _Z3fooRKSs - _Z3basv 82100 250 _Z3fooRKSs/_Z3barv - 33969 67 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv - 81511 161 _Z3fooRKSs/_Z3barv 1 _Z3barv - 77498 128 _Z3fooRKSs 1 _Z3fooRKSs - _Z3fooRKSs 119853 164 - _Z3barv 83285 227 _Z3fooRKSs - _Z3basv 82702 297 _Z3fooRKSs/_Z3barv - 34170 78 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv - 81589 149 _Z3fooRKSs/_Z3barv 1 _Z3barv - 78920 119 _Z3fooRKSs 1 _Z3fooRKSs + event.begin#annotation papi.PAPI_TOT_CYC papi.PAPI_L2_DCM annotation region.count event.end#annotation + _Z3fooRKSs 118289 679 + _Z3barv 200050 765 _Z3fooRKSs + _Z3basv 115098 352 _Z3fooRKSs/_Z3barv + 66564 242 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 117061 385 _Z3fooRKSs/_Z3barv 1 _Z3barv + 93592 206 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 146308 332 + _Z3barv 87811 255 _Z3fooRKSs + _Z3basv 84904 244 _Z3fooRKSs/_Z3barv + 34547 66 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 82540 168 _Z3fooRKSs/_Z3barv 1 _Z3barv + 80711 144 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 127765 183 + _Z3barv 85440 241 _Z3fooRKSs + _Z3basv 82100 250 _Z3fooRKSs/_Z3barv + 33969 67 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 81511 161 _Z3fooRKSs/_Z3barv 1 _Z3barv + 77498 128 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 119853 164 + _Z3barv 83285 227 _Z3fooRKSs + _Z3basv 82702 297 _Z3fooRKSs/_Z3barv + 34170 78 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 81589 149 _Z3fooRKSs/_Z3barv 1 _Z3barv + 78920 119 _Z3fooRKSs 1 _Z3fooRKSs .. code:: bash - PERFFLOW_OPTIONS='cpu-mem-usage=True:log-event=compact' CALI_CONFIG="load(time_exclusive.json),spot" ./smoketest + PERFFLOW_OPTIONS='cpu-mem-usage=True:log-event=compact' CALI_CONFIG="load(time_exclusive.json),spot" ./smoketest .. code:: bash - Path Min time/rank Max time/rank Avg time/rank Total time spot.channel - _Z3fooRKSs 0.018068 0.018068 0.018068 0.018068 regionprofile - _Z3barv 0.009124 0.009124 0.009124 0.009124 regionprofile - _Z3basv 0.000074 0.000074 0.000074 0.000074 regionprofile + Path Min time/rank Max time/rank Avg time/rank Total time spot.channel + _Z3fooRKSs 0.018068 0.018068 0.018068 0.018068 regionprofile + _Z3barv 0.009124 0.009124 0.009124 0.009124 regionprofile + _Z3basv 0.000074 0.000074 0.000074 0.000074 regionprofile From a5299daa85962bf8e4807261a512b3d25ed3c134 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Mon, 19 May 2025 14:21:12 -0700 Subject: [PATCH 14/34] Remove debug statement from Setup3rdParty.cmake --- src/c/cmake/Setup3rdParty.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c/cmake/Setup3rdParty.cmake b/src/c/cmake/Setup3rdParty.cmake index 28e7e088..d7744889 100644 --- a/src/c/cmake/Setup3rdParty.cmake +++ b/src/c/cmake/Setup3rdParty.cmake @@ -27,11 +27,11 @@ if(PERFFLOWASPECT_WITH_CALIPER) endif() if(caliper_DIR) - message(STATUS "PPP ${caliper_DIR}") + message(STATUS "${caliper_DIR}") include(cmake/thirdparty/FindCaliper.cmake) endif() if(CALIPER_FOUND) add_definitions(-DPERFFLOWASPECT_WITH_CALIPER) endif() -endif() \ No newline at end of file +endif() From 91cfb5a422851f50846e2870294540fde1880c1f Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Mon, 19 May 2025 14:22:32 -0700 Subject: [PATCH 15/34] Remove Adiak from this build. To be added with Spencer's build --- src/c/cmake/thirdparty/FindCaliper.cmake | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/c/cmake/thirdparty/FindCaliper.cmake b/src/c/cmake/thirdparty/FindCaliper.cmake index 585cd921..588bb8a7 100644 --- a/src/c/cmake/thirdparty/FindCaliper.cmake +++ b/src/c/cmake/thirdparty/FindCaliper.cmake @@ -1,19 +1,3 @@ -## most common case: caliper is built with adiak support -## and caliper needs us to find adiak, or else find_pacakge caliper -## will fail -# -## Check for ADIAK_DIR -# -#if(NOT ADIAK_DIR) -# MESSAGE(FATAL_ERROR "Caliper support needs explicit ADIAK_DIR") -#endif() -# -#message(STATUS "Looking for Adiak in: ${ADIAK_DIR}") -# -#find_package(adiak REQUIRED -# NO_DEFAULT_PATH -# PATHS ${ADIAK_DIR}/lib/cmake/adiak) - message(STATUS "Looking for Caliper in: ${caliper_DIR}") find_package(caliper REQUIRED From ef7d7f404bfd2a2686e830e4366bc4099d30db17 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Mon, 19 May 2025 14:23:29 -0700 Subject: [PATCH 16/34] Fix the build outpur msg for FOUND Caliper --- src/c/cmake/thirdparty/FindCaliper.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/cmake/thirdparty/FindCaliper.cmake b/src/c/cmake/thirdparty/FindCaliper.cmake index 588bb8a7..d4423736 100644 --- a/src/c/cmake/thirdparty/FindCaliper.cmake +++ b/src/c/cmake/thirdparty/FindCaliper.cmake @@ -8,7 +8,7 @@ find_package(caliper REQUIRED NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) -message(STATUS "FOUND Caliper: ${caliper_INSTALL_PREFIX}") +message(STATUS "FOUND Caliper: ${caliper_DIR}") #set(ADIAK_FOUND TRUE) set(CALIPER_FOUND TRUE) From ea34bea91d95f43c6a8a7ab6677ddfe88c42f41c Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Mon, 19 May 2025 14:42:59 -0700 Subject: [PATCH 17/34] Leave PERFFLOWASPECT_WITH_CALIPER OFF by default --- src/c/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/CMakeLists.txt b/src/c/CMakeLists.txt index fd87b485..8fe5976b 100644 --- a/src/c/CMakeLists.txt +++ b/src/c/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.12) project(PerfFlowAspect VERSION "0.1.0") # Higher-level build options. -option(PERFFLOWASPECT_WITH_CALIPER "Build with Caliper support" ON) +option(PERFFLOWASPECT_WITH_CALIPER "Build with Caliper support" OFF) # Fail if using Clang < 18.0 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") From b5329d9593bcacd2e95b0ae513af655868cf370c Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Mon, 19 May 2025 17:23:21 -0700 Subject: [PATCH 18/34] Add a comment in the host config files about Caliper options --- .../tioga-4.18.0-x86_64-rocm@6.3.1-amdclang@18.0.0.cmake | 5 +++++ .../tuolumne-4.18.0-x86_64-rocm@6.2.1-amdclang@18.0.0.cmake | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/c/host-configs/tioga-4.18.0-x86_64-rocm@6.3.1-amdclang@18.0.0.cmake b/src/c/host-configs/tioga-4.18.0-x86_64-rocm@6.3.1-amdclang@18.0.0.cmake index e23b4189..33fca384 100644 --- a/src/c/host-configs/tioga-4.18.0-x86_64-rocm@6.3.1-amdclang@18.0.0.cmake +++ b/src/c/host-configs/tioga-4.18.0-x86_64-rocm@6.3.1-amdclang@18.0.0.cmake @@ -10,3 +10,8 @@ set(CMAKE_C_COMPILER "/opt/rocm-6.3.1/lib/llvm/bin/amdclang" CACHE PATH "") set(CMAKE_CXX_COMPILER "/opt/rocm-6.3.1/lib/llvm/bin/amdclang++" CACHE PATH "") + +# To enable fine-grained profiling with Caliper, utilize the below options. +# Caliper should be built with the same compilers as the PerfFlowAspect. +# set(PERFFLOWASPECT_WITH_CALIPER ON CACHE BOOL "") +# set(caliper_DIR "path-to-caliper-install-directory" CACHE PATH "") diff --git a/src/c/host-configs/tuolumne-4.18.0-x86_64-rocm@6.2.1-amdclang@18.0.0.cmake b/src/c/host-configs/tuolumne-4.18.0-x86_64-rocm@6.2.1-amdclang@18.0.0.cmake index 53c825a2..39eda4fd 100644 --- a/src/c/host-configs/tuolumne-4.18.0-x86_64-rocm@6.2.1-amdclang@18.0.0.cmake +++ b/src/c/host-configs/tuolumne-4.18.0-x86_64-rocm@6.2.1-amdclang@18.0.0.cmake @@ -10,3 +10,8 @@ set(CMAKE_C_COMPILER "/opt/rocm-6.2.1/lib/llvm/bin/amdclang" CACHE PATH "") set(CMAKE_CXX_COMPILER "/opt/rocm-6.2.1/lib/llvm/bin/amdclang++" CACHE PATH "") + +# To enable fine-grained profiling with Caliper, utilize the below options. +# Caliper should be built with the same compilers as the PerfFlowAspect. +# set(PERFFLOWASPECT_WITH_CALIPER ON CACHE BOOL "") +# set(caliper_DIR "path-to-caliper-install-directory" CACHE PATH "") From 9793dc6d484b31e7c584906721720a9d52fc0472 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 12:02:03 -0700 Subject: [PATCH 19/34] Caliper + PFA Python integration, untested --- src/python/perfflowaspect/advice_chrome.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index 336d0848..44a57e00 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -21,6 +21,7 @@ import psutil from urllib.parse import urlparse from .aspect_base import perfflowaspect +from pycaliper.instrumentation import begin_region, end_region # TODO: move those into ChromeTracingAdvice counter_mutex = threading.Lock() @@ -43,6 +44,9 @@ def cannonicalize_perfflow_options(): perfflow_options["log-event"] = "Verbose" if perfflow_options.get("log-format") is None: perfflow_options["log-format"] = "Array" + # Caliper is disabled by default + if perfflow_options.get("caliper-enable") is None: + perfflow_options["caliper-enable"] = "False" def parse_perfflow_options(): @@ -207,6 +211,12 @@ class ChromeTracingAdvice: logger = None + caliper_flag = perfflow_options["caliper-enable"] + if caliper_flag in ["True", "true", "TRUE"]: + enable_caliper = True + elif caliper_flag in ["False", "false", "FALSE"]: + enable_caliper = False + def __init__(self): pass @@ -361,7 +371,7 @@ def trace(*args, **kwargs): def around(func): @functools.wraps(func) def trace(*args, **kwargs): - # Obtain start timestamp for tracing consistency. + # Obtain start timestamp for tracing consistency. This will inclide the Caliper overhead. ts_start = time.time() * 1000000 if not ChromeTracingAdvice.enable_compact_log_event: @@ -373,9 +383,17 @@ def trace(*args, **kwargs): cpu_start = cpu_start[0] time_start = time.time() + # If Caliper is enabled, call begin_region + if ChromeTracingAdvice.enable_caliper: + begin_region(str(func)) + rc = func(*args, **kwargs) + + # If Caliper is enabled, call end_region + if ChromeTracingAdvice.enable_caliper: + end_region(str(func)) - # Obtain end timestamp to calculate durations. + # Obtain end timestamp to calculate durations. This will include the Caliper overhead. ts_end = time.time() * 1000000 if ChromeTracingAdvice.enable_cpu_mem_usage: From adc2b607e22b6762116bb936718ffd5b35d34f5b Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 15:38:50 -0700 Subject: [PATCH 20/34] Update github actions to pick up Caliper python bindings --- .github/workflows/github-actions.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index c8202934..b2be49d8 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -75,7 +75,7 @@ jobs: run: | mkdir build && mkdir install cd build - cmake -DCMAKE_INSTALL_PREFIX=../install ../ + cmake -DWITH_PYTHON_BINDINGS=On -DCMAKE_INSTALL_PREFIX=../install ../ make VERBOSE=1 make install @@ -125,6 +125,8 @@ jobs: cd src/python python -m pip install -r requirements.txt python -m pip list + # Export path for caliper + export PYTHONPATH="/home/runner/work/PerfFlowAspect/PerfFlowAspect/Caliper/install/lib/${{ matrix.python-version }}/site-packages:$PYTHONPATH" - name: Run Python Smoke Tests run: | From 5afd49c32bbc556d5a5d73699b13bcb966496ab0 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 15:55:26 -0700 Subject: [PATCH 21/34] Update github actions to include pybind11 install --- .github/workflows/github-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index b2be49d8..79c7d415 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -61,7 +61,7 @@ jobs: - name: Setup Build Env run: | sudo apt-get update - sudo apt install clang-18 llvm-dev libjansson-dev libssl-dev bison flex make cmake mpich + sudo apt install clang-18 llvm-dev libjansson-dev libssl-dev bison flex make cmake mpich pybind11-dev clang++ --version - name: Clone Caliper From d6967e445e351c92557a8d37b23a3e6d8fb89157 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 16:04:18 -0700 Subject: [PATCH 22/34] Debug msg --- src/python/perfflowaspect/advice_chrome.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index 44a57e00..e9fe2d56 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -385,13 +385,15 @@ def trace(*args, **kwargs): # If Caliper is enabled, call begin_region if ChromeTracingAdvice.enable_caliper: - begin_region(str(func)) + print("Here in Caliper enabled region") + print("Function is" + str(func)) + pycaliper.instrumentation.begin_region(str(func)) rc = func(*args, **kwargs) # If Caliper is enabled, call end_region if ChromeTracingAdvice.enable_caliper: - end_region(str(func)) + pycaliper.instrumentation.end_region(str(func)) # Obtain end timestamp to calculate durations. This will include the Caliper overhead. ts_end = time.time() * 1000000 From 790277dd0c37739010f390143f5dee67f8f94b89 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 16:06:58 -0700 Subject: [PATCH 23/34] Debug msg --- src/python/perfflowaspect/advice_chrome.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index e9fe2d56..bf448a2e 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -387,13 +387,13 @@ def trace(*args, **kwargs): if ChromeTracingAdvice.enable_caliper: print("Here in Caliper enabled region") print("Function is" + str(func)) - pycaliper.instrumentation.begin_region(str(func)) + begin_region(str(func)) rc = func(*args, **kwargs) # If Caliper is enabled, call end_region if ChromeTracingAdvice.enable_caliper: - pycaliper.instrumentation.end_region(str(func)) + end_region(str(func)) # Obtain end timestamp to calculate durations. This will include the Caliper overhead. ts_end = time.time() * 1000000 From f9ec95469b41c4881b98df9693c962fe67c0c5f7 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 16:08:23 -0700 Subject: [PATCH 24/34] Tested and works, remove debug msgs. --- src/python/perfflowaspect/advice_chrome.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index bf448a2e..44a57e00 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -385,8 +385,6 @@ def trace(*args, **kwargs): # If Caliper is enabled, call begin_region if ChromeTracingAdvice.enable_caliper: - print("Here in Caliper enabled region") - print("Function is" + str(func)) begin_region(str(func)) rc = func(*args, **kwargs) From 7b9debc9c2ed74456801a43fb76d3f3950db4a95 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 16:18:30 -0700 Subject: [PATCH 25/34] Fix sharness test error caused due to PYTHONPATH updation --- src/python/test/t0001-pybinding-basic.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/test/t0001-pybinding-basic.t b/src/python/test/t0001-pybinding-basic.t index cd57b931..a2fe54db 100755 --- a/src/python/test/t0001-pybinding-basic.t +++ b/src/python/test/t0001-pybinding-basic.t @@ -4,7 +4,7 @@ test_description='Test basics of Perfflow Aspect python binding' . ../../common/sharness/sharness.sh -export PYTHONPATH=../../ +export PYTHONPATH=../../:$PYTHONPATH fixup_ctf_file(){ ifn=$1 && From 1cf1b72085645a04992cac6f1ee4bfc07f2d699c Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 17:18:10 -0700 Subject: [PATCH 26/34] Try a conditional import of the pycaliper module, to fix the CI error --- src/python/perfflowaspect/advice_chrome.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index 44a57e00..a850c534 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -21,7 +21,6 @@ import psutil from urllib.parse import urlparse from .aspect_base import perfflowaspect -from pycaliper.instrumentation import begin_region, end_region # TODO: move those into ChromeTracingAdvice counter_mutex = threading.Lock() @@ -214,6 +213,11 @@ class ChromeTracingAdvice: caliper_flag = perfflow_options["caliper-enable"] if caliper_flag in ["True", "true", "TRUE"]: enable_caliper = True + # Only include caliper when it is enabled. + # Importing this generally causes CI tests to fail, esp the t0001.t test + # which relies on relative PYTHOHPATH. + from pycaliper.instrumentation import begin_region, end_region + elif caliper_flag in ["False", "false", "FALSE"]: enable_caliper = False From 3ef542d8a7d57994ef3458438c457f521f2efe9a Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 17:23:35 -0700 Subject: [PATCH 27/34] Try a Conditional import for pycaliper --- src/python/perfflowaspect/advice_chrome.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index a850c534..0201b189 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -216,7 +216,11 @@ class ChromeTracingAdvice: # Only include caliper when it is enabled. # Importing this generally causes CI tests to fail, esp the t0001.t test # which relies on relative PYTHOHPATH. - from pycaliper.instrumentation import begin_region, end_region + try: + from pycaliper.instrumentation import begin_region, end_region + print("Caliper is enabled and pycaliper was imported succesfully.") + except ImportError: + print("Caliper is enabled but pycaliper could not be imported.") elif caliper_flag in ["False", "false", "FALSE"]: enable_caliper = False From 2495d606c43ac5b8153c23697163fd74917a6c58 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 17:43:03 -0700 Subject: [PATCH 28/34] Still attempting a conditional import --- src/python/perfflowaspect/advice_chrome.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index 0201b189..06236021 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -221,7 +221,8 @@ class ChromeTracingAdvice: print("Caliper is enabled and pycaliper was imported succesfully.") except ImportError: print("Caliper is enabled but pycaliper could not be imported.") - + begin_region = None + end_region = None elif caliper_flag in ["False", "false", "FALSE"]: enable_caliper = False From 2fe1307303c006cc5d3f6e4979b6786207e66bb0 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 17:43:35 -0700 Subject: [PATCH 29/34] Update PYTHONPATH again --- src/python/test/t0001-pybinding-basic.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/test/t0001-pybinding-basic.t b/src/python/test/t0001-pybinding-basic.t index a2fe54db..cd57b931 100755 --- a/src/python/test/t0001-pybinding-basic.t +++ b/src/python/test/t0001-pybinding-basic.t @@ -4,7 +4,7 @@ test_description='Test basics of Perfflow Aspect python binding' . ../../common/sharness/sharness.sh -export PYTHONPATH=../../:$PYTHONPATH +export PYTHONPATH=../../ fixup_ctf_file(){ ifn=$1 && From 4cb432b3b8df17702527effde8b72bb52aeb9144 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 17:47:37 -0700 Subject: [PATCH 30/34] Another attempt at a conditional import --- src/python/perfflowaspect/advice_chrome.py | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index 06236021..bcd17426 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -213,16 +213,6 @@ class ChromeTracingAdvice: caliper_flag = perfflow_options["caliper-enable"] if caliper_flag in ["True", "true", "TRUE"]: enable_caliper = True - # Only include caliper when it is enabled. - # Importing this generally causes CI tests to fail, esp the t0001.t test - # which relies on relative PYTHOHPATH. - try: - from pycaliper.instrumentation import begin_region, end_region - print("Caliper is enabled and pycaliper was imported succesfully.") - except ImportError: - print("Caliper is enabled but pycaliper could not be imported.") - begin_region = None - end_region = None elif caliper_flag in ["False", "false", "FALSE"]: enable_caliper = False @@ -394,12 +384,32 @@ def trace(*args, **kwargs): # If Caliper is enabled, call begin_region if ChromeTracingAdvice.enable_caliper: + # Only include caliper when it is enabled. + # Importing this generally causes CI tests to fail, esp the t0001.t test + # which relies on relative PYTHOHPATH. + try: + from pycaliper.instrumentation import begin_region + print("Caliper is enabled and pycaliper was imported succesfully.") + except ImportError: + print("Caliper is enabled but pycaliper could not be imported.") + begin_region = None + # Call Caliper's begin region begin_region(str(func)) rc = func(*args, **kwargs) # If Caliper is enabled, call end_region if ChromeTracingAdvice.enable_caliper: + # Only include caliper when it is enabled. + # Importing this generally causes CI tests to fail, esp the t0001.t test + # which relies on relative PYTHOHPATH. + try: + from pycaliper.instrumentation import end_region + print("Caliper is enabled and pycaliper was imported succesfully.") + except ImportError: + print("Caliper is enabled but pycaliper could not be imported.") + end_region = None + # Call Caliper's end region end_region(str(func)) # Obtain end timestamp to calculate durations. This will include the Caliper overhead. From d6918ab9b4f2da3ac98d81b4af185b8bc3ded896 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 17:49:03 -0700 Subject: [PATCH 31/34] Remove debug msgs --- src/python/perfflowaspect/advice_chrome.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index bcd17426..7996b155 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -389,7 +389,6 @@ def trace(*args, **kwargs): # which relies on relative PYTHOHPATH. try: from pycaliper.instrumentation import begin_region - print("Caliper is enabled and pycaliper was imported succesfully.") except ImportError: print("Caliper is enabled but pycaliper could not be imported.") begin_region = None @@ -405,7 +404,6 @@ def trace(*args, **kwargs): # which relies on relative PYTHOHPATH. try: from pycaliper.instrumentation import end_region - print("Caliper is enabled and pycaliper was imported succesfully.") except ImportError: print("Caliper is enabled but pycaliper could not be imported.") end_region = None From 349d00faafd63d10519de5bdfaa8d7eee0b0e628 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 20 May 2025 17:53:38 -0700 Subject: [PATCH 32/34] Formatted --- src/python/perfflowaspect/advice_chrome.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index 7996b155..c6fcc222 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -43,7 +43,7 @@ def cannonicalize_perfflow_options(): perfflow_options["log-event"] = "Verbose" if perfflow_options.get("log-format") is None: perfflow_options["log-format"] = "Array" - # Caliper is disabled by default + # Caliper is disabled by default if perfflow_options.get("caliper-enable") is None: perfflow_options["caliper-enable"] = "False" @@ -384,7 +384,7 @@ def trace(*args, **kwargs): # If Caliper is enabled, call begin_region if ChromeTracingAdvice.enable_caliper: - # Only include caliper when it is enabled. + # Only include caliper when it is enabled. # Importing this generally causes CI tests to fail, esp the t0001.t test # which relies on relative PYTHOHPATH. try: @@ -392,14 +392,14 @@ def trace(*args, **kwargs): except ImportError: print("Caliper is enabled but pycaliper could not be imported.") begin_region = None - # Call Caliper's begin region + # Call Caliper's begin region begin_region(str(func)) - + rc = func(*args, **kwargs) - + # If Caliper is enabled, call end_region if ChromeTracingAdvice.enable_caliper: - # Only include caliper when it is enabled. + # Only include caliper when it is enabled. # Importing this generally causes CI tests to fail, esp the t0001.t test # which relies on relative PYTHOHPATH. try: @@ -407,7 +407,7 @@ def trace(*args, **kwargs): except ImportError: print("Caliper is enabled but pycaliper could not be imported.") end_region = None - # Call Caliper's end region + # Call Caliper's end region end_region(str(func)) # Obtain end timestamp to calculate durations. This will include the Caliper overhead. From b92e3309a9112c16e272d2f17c9b92bbaf787c30 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 21 May 2025 16:47:45 -0700 Subject: [PATCH 33/34] Clean up commits, add docs --- docs/BasicTutorial.rst | 2 + docs/CaliperIntegration.rst | 57 ++++++++++++++++++++-- src/python/perfflowaspect/advice_chrome.py | 12 ++--- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/docs/BasicTutorial.rst b/docs/BasicTutorial.rst index 8f4d74e8..6d9f1c87 100644 --- a/docs/BasicTutorial.rst +++ b/docs/BasicTutorial.rst @@ -103,6 +103,8 @@ variable. Separate multiple variables with a colon as follows: +----------------------+--------------------------------------------------------------+---------------+---------------------------------+ | log-format | Dump JSON events in array or object format | Array | Array, Object | +----------------------+--------------------------------------------------------------+---------------+---------------------------------+ +| caliper-enable | Toggle Caliper data collection on/off (for Python only). | False | True, False | ++----------------------+--------------------------------------------------------------+---------------+---------------------------------+ ********************************************** Visualization of PerfFlowAspect Output Files diff --git a/docs/CaliperIntegration.rst b/docs/CaliperIntegration.rst index 6fd597e5..db8f5c1e 100644 --- a/docs/CaliperIntegration.rst +++ b/docs/CaliperIntegration.rst @@ -12,14 +12,32 @@ PerfFlowAspect can be built with Caliper to leverage collection of additional performance data, such as hardware performance counters on CPUs and GPU measurements on NVIDIA GPUs. `Caliper `_ is an -instrumentation and performance annotation library. A Caliper install is -required before building PerfFlowAspect: +instrumentation and performance annotation library. + +PerfFlowAspect supports the Caliper integration for both C/C++ and Python codebases. +This enables a single PerfFlowAspect annotation to generate both `.pfw` +trace files and `.cali` files, so users do not need any additional annotations to +obtain Caliper data. + +A Caliper install is required before building PerfFlowAspect in this case. +Caliper can be configured at runtime, as shown in examples below. + +************ + C/C++ Build +************ +Caliper needs to be is built with the same `clang` compiler chain as PerfFlowAspect. +These can be specified with the `-DCMAKE_C_COMPILER` and `-DCMAKE_CXX_COMPILER`. .. code:: bash - cmake -Dcaliper_DIR=/share/lib/caliper ../ + cmake -DCMAKE_C_COMPILER= \ + -DCMAKE_C_COMPILER= \ + -DWITH_PYTHON_BINDINGS=On \ + -Dcaliper_DIR=/share/lib/caliper ../ -Caliper can be configured at runtime, for example: +************** + C/C++ Example +************** .. code:: bash @@ -75,3 +93,34 @@ Caliper can be configured at runtime, for example: _Z3fooRKSs 0.018068 0.018068 0.018068 0.018068 regionprofile _Z3barv 0.009124 0.009124 0.009124 0.009124 regionprofile _Z3basv 0.000074 0.000074 0.000074 0.000074 regionprofile + + +**************** + Python Example +**************** + +For Python applications, Caliper can be enabled by setting the `caliper-enable` option. +In this case, `PYTHONPATH` needs to be set to include the `pycaliper` package from Caliper installation. + +.. code:: bash + + export PYTHONPATH=/lib/python/site-packages + PERFFLOW_OPTIONS="caliper-enable=True" CALI_CONFIG=runtime-report ./smoketest.py + + Inside main + foo + bar + bas + foo + bar + bas + foo + bar + bas + foo + bar + bas + Path Time (E) Time (I) Time % (E) Time % (I) + 0.004692 0.009423 47.547246 95.486397 + 0.004659 0.004731 47.213609 47.939151 + 0.000072 0.000072 0.725542 0.725542 \ No newline at end of file diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index c6fcc222..a1300f8b 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -382,11 +382,9 @@ def trace(*args, **kwargs): cpu_start = cpu_start[0] time_start = time.time() - # If Caliper is enabled, call begin_region + # If Caliper is enabled, import pycaliper and call begin_region + # Conditional import preserves current behavior of t0001.t if ChromeTracingAdvice.enable_caliper: - # Only include caliper when it is enabled. - # Importing this generally causes CI tests to fail, esp the t0001.t test - # which relies on relative PYTHOHPATH. try: from pycaliper.instrumentation import begin_region except ImportError: @@ -397,11 +395,9 @@ def trace(*args, **kwargs): rc = func(*args, **kwargs) - # If Caliper is enabled, call end_region + # If Caliper is enabled, import pycaliper and call end_region + # Conditional import preserves current behavior of t0001.t if ChromeTracingAdvice.enable_caliper: - # Only include caliper when it is enabled. - # Importing this generally causes CI tests to fail, esp the t0001.t test - # which relies on relative PYTHOHPATH. try: from pycaliper.instrumentation import end_region except ImportError: From 0010178d881748ea6985b16e0b8b996dafb9c218 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Wed, 21 May 2025 17:13:50 -0700 Subject: [PATCH 34/34] Formatted --- docs/CaliperIntegration.rst | 40 ++++++++++++---------- src/python/perfflowaspect/advice_chrome.py | 4 +-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/docs/CaliperIntegration.rst b/docs/CaliperIntegration.rst index db8f5c1e..52607ce2 100644 --- a/docs/CaliperIntegration.rst +++ b/docs/CaliperIntegration.rst @@ -12,21 +12,23 @@ PerfFlowAspect can be built with Caliper to leverage collection of additional performance data, such as hardware performance counters on CPUs and GPU measurements on NVIDIA GPUs. `Caliper `_ is an -instrumentation and performance annotation library. +instrumentation and performance annotation library. -PerfFlowAspect supports the Caliper integration for both C/C++ and Python codebases. -This enables a single PerfFlowAspect annotation to generate both `.pfw` -trace files and `.cali` files, so users do not need any additional annotations to -obtain Caliper data. +PerfFlowAspect supports the Caliper integration for both C/C++ and Python +codebases. This enables a single PerfFlowAspect annotation to generate both +`.pfw` trace files and `.cali` files, so users do not need any additional +annotations to obtain Caliper data. A Caliper install is required before building PerfFlowAspect in this case. Caliper can be configured at runtime, as shown in examples below. -************ +************* C/C++ Build -************ -Caliper needs to be is built with the same `clang` compiler chain as PerfFlowAspect. -These can be specified with the `-DCMAKE_C_COMPILER` and `-DCMAKE_CXX_COMPILER`. +************* + +Caliper needs to be is built with the same `clang` compiler chain as +PerfFlowAspect. These can be specified with the `-DCMAKE_C_COMPILER` and +`-DCMAKE_CXX_COMPILER`. .. code:: bash @@ -35,9 +37,9 @@ These can be specified with the `-DCMAKE_C_COMPILER` and `-DCMAKE_CXX_COMPILER` -DWITH_PYTHON_BINDINGS=On \ -Dcaliper_DIR=/share/lib/caliper ../ -************** +*************** C/C++ Example -************** +*************** .. code:: bash @@ -94,18 +96,18 @@ These can be specified with the `-DCMAKE_C_COMPILER` and `-DCMAKE_CXX_COMPILER` _Z3barv 0.009124 0.009124 0.009124 0.009124 regionprofile _Z3basv 0.000074 0.000074 0.000074 0.000074 regionprofile - **************** Python Example **************** -For Python applications, Caliper can be enabled by setting the `caliper-enable` option. -In this case, `PYTHONPATH` needs to be set to include the `pycaliper` package from Caliper installation. +For Python applications, Caliper can be enabled by setting the `caliper-enable` +option. In this case, `PYTHONPATH` needs to be set to include the `pycaliper` +package from Caliper installation. .. code:: bash export PYTHONPATH=/lib/python/site-packages - PERFFLOW_OPTIONS="caliper-enable=True" CALI_CONFIG=runtime-report ./smoketest.py + PERFFLOW_OPTIONS="caliper-enable=True" CALI_CONFIG=runtime-report ./smoketest.py Inside main foo @@ -120,7 +122,7 @@ In this case, `PYTHONPATH` needs to be set to include the `pycaliper` package fr foo bar bas - Path Time (E) Time (I) Time % (E) Time % (I) - 0.004692 0.009423 47.547246 95.486397 - 0.004659 0.004731 47.213609 47.939151 - 0.000072 0.000072 0.725542 0.725542 \ No newline at end of file + Path Time (E) Time (I) Time % (E) Time % (I) + 0.004692 0.009423 47.547246 95.486397 + 0.004659 0.004731 47.213609 47.939151 + 0.000072 0.000072 0.725542 0.725542 diff --git a/src/python/perfflowaspect/advice_chrome.py b/src/python/perfflowaspect/advice_chrome.py index a1300f8b..f7ffed2e 100644 --- a/src/python/perfflowaspect/advice_chrome.py +++ b/src/python/perfflowaspect/advice_chrome.py @@ -383,7 +383,7 @@ def trace(*args, **kwargs): time_start = time.time() # If Caliper is enabled, import pycaliper and call begin_region - # Conditional import preserves current behavior of t0001.t + # Conditional import preserves current behavior of t0001.t if ChromeTracingAdvice.enable_caliper: try: from pycaliper.instrumentation import begin_region @@ -396,7 +396,7 @@ def trace(*args, **kwargs): rc = func(*args, **kwargs) # If Caliper is enabled, import pycaliper and call end_region - # Conditional import preserves current behavior of t0001.t + # Conditional import preserves current behavior of t0001.t if ChromeTracingAdvice.enable_caliper: try: from pycaliper.instrumentation import end_region