From 17c4905804ced3652927bc51603e7ea9061aaf40 Mon Sep 17 00:00:00 2001 From: Konstantinos Parasyris Date: Tue, 22 Aug 2023 10:29:25 -0700 Subject: [PATCH 01/17] Caliper instrumentation --- src/c/runtime/CMakeLists.txt | 2 +- src/c/test/CMakeLists.txt | 4 +- src/c/weaver/weave/perfflow_weave.cpp | 67 +++++++++++++++++++++++++-- src/c/weaver/weave/perfflow_weave.hpp | 9 ++++ 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/c/runtime/CMakeLists.txt b/src/c/runtime/CMakeLists.txt index 12e4fba5..333ab80c 100644 --- a/src/c/runtime/CMakeLists.txt +++ b/src/c/runtime/CMakeLists.txt @@ -19,7 +19,7 @@ add_library(perfflow_runtime SHARED ${perfflow_runtime_headers} ) -target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto) +target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto caliper) install(TARGETS perfflow_runtime EXPORT perfflow_export diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index aae008c8..c0040238 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -12,7 +12,7 @@ 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 -fPIC") - target_link_libraries(${TEST} ${perfflow_deps}) + target_link_libraries(${TEST} ${perfflow_deps} caliper) endforeach() # Build Options @@ -50,7 +50,7 @@ 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") cuda_add_executable(smoketest_cuda smoketest_cuda_wrapper.cpp smoketest_cuda_kernel.cu) - target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES}) + target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES} caliper) endif() configure_file(t0001-cbinding-basic.t.in diff --git a/src/c/weaver/weave/perfflow_weave.cpp b/src/c/weaver/weave/perfflow_weave.cpp index 4e81003c..838434ca 100644 --- a/src/c/weaver/weave/perfflow_weave.cpp +++ b/src/c/weaver/weave/perfflow_weave.cpp @@ -20,6 +20,7 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Argument.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Support/raw_ostream.h" @@ -71,14 +72,14 @@ bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a, { IRBuilder<> builder(inst); Value *v1 = builder.CreateGlobalStringPtr(m.getName(), "str"); - Value *v2 = builder.CreateGlobalStringPtr(f.getName(), "str"); + Value *FnNameStr = builder.CreateGlobalStringPtr(f.getName(), "str"); Value *v3 = builder.CreateGlobalStringPtr(StringRef(scope), "str"); Value *v4 = builder.CreateGlobalStringPtr(StringRef(flow), "str"); Value *v5 = builder.CreateGlobalStringPtr(StringRef(pcut), "str"); std::vector args; args.push_back(ConstantInt::get(Type::getInt32Ty(context), async)); args.push_back(v1); - args.push_back(v2); + args.push_back(FnNameStr); args.push_back(v3); args.push_back(v4); args.push_back(v5); @@ -88,6 +89,46 @@ bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a, return true; } +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; +} + bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, int async, std::string &scope, std::string &flow, std::string pcut) { @@ -118,7 +159,7 @@ bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, auto &entry = f.getEntryBlock(); IRBuilder<> builder(&entry); Value *v1 = builder.CreateGlobalStringPtr(m.getName(), "str"); - Value *v2 = builder.CreateGlobalStringPtr(f.getName(), "str"); + Value *FnNameStr = builder.CreateGlobalStringPtr(f.getName(), "str"); Value *v3 = builder.CreateGlobalStringPtr(StringRef(scope), "str"); Value *v4 = builder.CreateGlobalStringPtr(StringRef(flow), "str"); Value *v5 = builder.CreateGlobalStringPtr(StringRef(pcut), "str"); @@ -126,7 +167,7 @@ bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, std::vector args; args.push_back(ConstantInt::get(Type::getInt32Ty(context), async)); args.push_back(v1); - args.push_back(v2); + args.push_back(FnNameStr); args.push_back(v3); args.push_back(v4); args.push_back(v5); @@ -152,6 +193,20 @@ bool WeavingPass::doInitialization(Module &m) return false; } + 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()); + + bool changed = false; auto a = cast (annotations->getOperand(0)); for (unsigned int i = 0; i < a->getNumOperands(); i++) @@ -159,6 +214,10 @@ bool WeavingPass::doInitialization(Module &m) auto e = cast (a->getOperand(i)); if (auto *fn = dyn_cast (e->getOperand(0)->getOperand(0))) { + // We insert Caliper Instrumentation before weaver. + // Thus weaver will include Caliper overheads + changed |= instrumentCaliper(m, *fn); + auto anno = cast( cast(e->getOperand(1)->getOperand(0)) ->getOperand(0)) diff --git a/src/c/weaver/weave/perfflow_weave.hpp b/src/c/weaver/weave/perfflow_weave.hpp index 3db17445..6b27094c 100644 --- a/src/c/weaver/weave/perfflow_weave.hpp +++ b/src/c/weaver/weave/perfflow_weave.hpp @@ -11,9 +11,13 @@ #ifndef PERFFLOW_WEAVE_H #define PERFFLOW_WEAVE_H +#include "llvm/IR/Attributes.h" #include "llvm/IR/Function.h" #include "llvm/IR/Module.h" +#include "llvm/IR/IRBuilder.h" #include "llvm/Pass.h" +#include "llvm/Support/Debug.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include @@ -24,6 +28,9 @@ namespace { class WeavingPass : public FunctionPass { public: + FunctionCallee CaliBeginRegion; + FunctionCallee CaliEndRegion; + static char ID; WeavingPass () : FunctionPass (ID) {} virtual bool doInitialization (Module &m); @@ -34,6 +41,8 @@ class WeavingPass : public FunctionPass int async, std::string &scope, std::string &flow, std::string pcut); bool insertBefore (Module &m, Function &f, StringRef &a, int async, std::string &scope, std::string &flow, std::string pcut); + + bool instrumentCaliper(Module &M, Function &F); }; } From 715281400e11ffab6f8d21a87ddb035fbe40a79d Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 2 Feb 2024 23:45:44 -0800 Subject: [PATCH 02/17] checkpoint..working for cmake needs updates for make build systems --- src/c/cmake/Setup3rdParty.cmake | 10 ++++++ src/c/cmake/thirdparty/SetupCaliper.cmake | 26 +++++++++++++++ src/c/config/CMakeLists.txt | 1 + src/c/config/perfflowaspect-config.cmake.in | 5 ++- src/c/config/perfflowaspect_setup_deps.cmake | 33 ++++++++++++++++++++ src/c/runtime/CMakeLists.txt | 6 ++++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/c/cmake/thirdparty/SetupCaliper.cmake create mode 100644 src/c/config/perfflowaspect_setup_deps.cmake diff --git a/src/c/cmake/Setup3rdParty.cmake b/src/c/cmake/Setup3rdParty.cmake index d7f203a6..2b22fd78 100644 --- a/src/c/cmake/Setup3rdParty.cmake +++ b/src/c/cmake/Setup3rdParty.cmake @@ -19,3 +19,13 @@ include(cmake/thirdparty/FindOpenSSL.cmake) if(PERFFLOWASPECT_WITH_MULTITHREADS) include(cmake/thirdparty/FindThreads.cmake) endif() + +# 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/SetupCaliper.cmake) +endif() diff --git a/src/c/cmake/thirdparty/SetupCaliper.cmake b/src/c/cmake/thirdparty/SetupCaliper.cmake new file mode 100644 index 00000000..673d9be0 --- /dev/null +++ b/src/c/cmake/thirdparty/SetupCaliper.cmake @@ -0,0 +1,26 @@ +## 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) + +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/CMakeLists.txt b/src/c/config/CMakeLists.txt index 455c4089..84912726 100644 --- a/src/c/config/CMakeLists.txt +++ b/src/c/config/CMakeLists.txt @@ -42,6 +42,7 @@ 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 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..fb4e6cfa 100644 --- a/src/c/config/perfflowaspect-config.cmake.in +++ b/src/c/config/perfflowaspect-config.cmake.in @@ -3,7 +3,10 @@ if (NOT PERFFLOWASPECT_CONFIG_LOADED) set(PERFFLOWASPECT_DIR "@CMAKE_INSTALL_PREFIX@") set(PERFFLOWASPECT_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@") - include(CMakeFindDependencyMacro) + set(PERFFLOWASPECT_CALIPER_ENABLED "@PERFFLOWASPECT_CALIPER_ENABLED@") + set(PERFFLOWASPECT_CALIPER_DIR "@caliper_DIR@") + + include(${PERFFLOWASPECT_INSTALL_PREFIX}/share/perfflowaspect_setup_deps.cmake) find_dependency(OpenSSL REQUIRED) diff --git a/src/c/config/perfflowaspect_setup_deps.cmake b/src/c/config/perfflowaspect_setup_deps.cmake new file mode 100644 index 00000000..b7afefd5 --- /dev/null +++ b/src/c/config/perfflowaspect_setup_deps.cmake @@ -0,0 +1,33 @@ +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") + endif() + +# if(NOT ADIAK_DIR) +# set(ADIAK_DIR ${ASCENT_ADIAK_DIR}) +# endif() +# +# if(ADIAK_DIR) +# if(NOT PerfFlowAspect_FIND_QUIETLY) +# message(STATUS "Looking for Adiak at: ${ADIAK_DIR}/lib/cmake/adiak") +# endif() +# # find adiak first +# find_package(adiak REQUIRED +# NO_DEFAULT_PATH +# PATHS ${ADIAK_DIR}/lib/cmake/adiak) +# endif() + if(NOT PerfFlowAspect_FIND_QUIETLY) + 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/runtime/CMakeLists.txt b/src/c/runtime/CMakeLists.txt index 333ab80c..708c7ab5 100644 --- a/src/c/runtime/CMakeLists.txt +++ b/src/c/runtime/CMakeLists.txt @@ -14,6 +14,12 @@ set(perfflow_runtime_sources include_directories(${JANSSON_INCLUDE_DIRS}) +find_package(caliper REQUIRED) + +message(STATUS "RRR ${caliper_LIB_DIR} ${caliper_CONFIG_LOADED}") + +include_directories(${caliper_INCLUDE_DIR}) + add_library(perfflow_runtime SHARED ${perfflow_runtime_sources} ${perfflow_runtime_headers} From 749f7f35d0bdabc3ed5ceaafb9f3aa4be0cecda2 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 10 May 2024 10:09:19 -0700 Subject: [PATCH 03/17] toggle caliper build on/off --- src/c/CMakeLists.txt | 6 ++++++ src/c/cmake/Setup3rdParty.cmake | 18 ++++++++++-------- .../{SetupCaliper.cmake => FindCaliper.cmake} | 0 src/c/runtime/CMakeLists.txt | 15 +++++++++------ src/c/test/CMakeLists.txt | 12 ++++++++++-- 5 files changed, 35 insertions(+), 16 deletions(-) rename src/c/cmake/thirdparty/{SetupCaliper.cmake => FindCaliper.cmake} (100%) diff --git a/src/c/CMakeLists.txt b/src/c/CMakeLists.txt index 0f001d9c..6fc1da05 100644 --- a/src/c/CMakeLists.txt +++ b/src/c/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.12) project(PerfFlowAspect VERSION "0.1.0") +# Build Options +option(PERFFLOWASPECT_WITH_CUDA "Build CUDA smoketest" ON) +option(PERFFLOWASPECT_WITH_MPI "Build MPI smoketest" ON) +option(PERFFLOWASPECT_WITH_MULTITHREADS "Build multi-threaded smoketest" ON) +option(PERFFLOWASPECT_WITH_CALIPER "Build with Caliper support" ON) + # Fail if using Clang < 9.0 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # require at least Clang 9.0 diff --git a/src/c/cmake/Setup3rdParty.cmake b/src/c/cmake/Setup3rdParty.cmake index 2b22fd78..168ee13b 100644 --- a/src/c/cmake/Setup3rdParty.cmake +++ b/src/c/cmake/Setup3rdParty.cmake @@ -20,12 +20,14 @@ if(PERFFLOWASPECT_WITH_MULTITHREADS) include(cmake/thirdparty/FindThreads.cmake) endif() -# 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/SetupCaliper.cmake) +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() endif() diff --git a/src/c/cmake/thirdparty/SetupCaliper.cmake b/src/c/cmake/thirdparty/FindCaliper.cmake similarity index 100% rename from src/c/cmake/thirdparty/SetupCaliper.cmake rename to src/c/cmake/thirdparty/FindCaliper.cmake diff --git a/src/c/runtime/CMakeLists.txt b/src/c/runtime/CMakeLists.txt index 708c7ab5..e8d8fd8d 100644 --- a/src/c/runtime/CMakeLists.txt +++ b/src/c/runtime/CMakeLists.txt @@ -14,18 +14,21 @@ set(perfflow_runtime_sources include_directories(${JANSSON_INCLUDE_DIRS}) -find_package(caliper REQUIRED) - -message(STATUS "RRR ${caliper_LIB_DIR} ${caliper_CONFIG_LOADED}") - -include_directories(${caliper_INCLUDE_DIR}) +if(PERFFLOWASPECT_WITH_CALIPER) + message(STATUS "RRR ${caliper_LIB_DIR} ${caliper_CONFIG_LOADED}") + 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 caliper) +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 diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index c0040238..e5fbe15b 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -12,7 +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 -fPIC") - target_link_libraries(${TEST} ${perfflow_deps} caliper) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(${TEST} ${perfflow_deps} caliper) + else() + target_link_libraries(${TEST} ${perfflow_deps}) + endif() endforeach() # Build Options @@ -50,7 +54,11 @@ 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") cuda_add_executable(smoketest_cuda smoketest_cuda_wrapper.cpp smoketest_cuda_kernel.cu) - target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES} caliper) + 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 a266d0d1c55037936aff61690aac448ae1dd4b64 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 10 May 2024 10:20:55 -0700 Subject: [PATCH 04/17] c formatting --- src/c/weaver/weave/perfflow_weave.cpp | 54 ++++++++++++++------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/c/weaver/weave/perfflow_weave.cpp b/src/c/weaver/weave/perfflow_weave.cpp index 838434ca..18f81d3e 100644 --- a/src/c/weaver/weave/perfflow_weave.cpp +++ b/src/c/weaver/weave/perfflow_weave.cpp @@ -29,7 +29,6 @@ using namespace llvm; - /****************************************************************************** * * * Private Methods of WeavingPass Class * @@ -89,7 +88,8 @@ bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a, return true; } -bool WeavingPass::instrumentCaliper(Module &M, Function &F){ +bool WeavingPass::instrumentCaliper(Module &M, Function &F) +{ IRBuilder<> IRB(M.getContext()); BasicBlock &Entry = F.getEntryBlock(); SplitBlock(&Entry, &*Entry.getFirstInsertionPt()); @@ -100,30 +100,36 @@ bool WeavingPass::instrumentCaliper(Module &M, Function &F){ 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; + 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; - } + 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; - } + // 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(); + if (!RetFound) + { + dbgs() << "Could not find return for " << FunctionName << "\n"; + abort(); } return RetFound; @@ -176,7 +182,6 @@ bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, return true; } - /****************************************************************************** * * * Public Methods of WeavingPass Class * @@ -199,14 +204,13 @@ bool WeavingPass::doInitialization(Module &m) //It was not added in LLVM@10. //AB.addAttribute(Attribute::ArgMemOnly); AttributeList Attrs = AttributeList::get(m.getContext(), - AttributeList::FunctionIndex, AB); + AttributeList::FunctionIndex, AB); // Insert Functions on the module CaliBeginRegion = m.getOrInsertFunction( - "cali_begin_region", Attrs, IRB.getVoidTy(), IRB.getInt8PtrTy()); + "cali_begin_region", Attrs, IRB.getVoidTy(), IRB.getInt8PtrTy()); CaliEndRegion = m.getOrInsertFunction("cali_end_region", Attrs, IRB.getVoidTy(), IRB.getInt8PtrTy()); - bool changed = false; auto a = cast (annotations->getOperand(0)); for (unsigned int i = 0; i < a->getNumOperands(); i++) From c856f6895717b331404890264cc001572ac6fed0 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 10 May 2024 10:32:08 -0700 Subject: [PATCH 05/17] add config to unit tests for building with 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 a7bb5a12..f6a39a86 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.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,30 +17,42 @@ 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: ON + PERFFLOWASPECT_WITH_MPI: ON + PERFFLOWASPECT_WITH_MULTITHREADS: ON + CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: ON steps: # Checkout PerfFlowAspect repository under $GITHUB_WORKSPACE @@ -52,6 +64,21 @@ jobs: sudo apt install clang 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 bdea46c796482b2826f4540fb57c4b3e46c01e86 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 10 May 2024 11:02:22 -0700 Subject: [PATCH 06/17] add wrapper for caliper annotations --- src/c/cmake/Setup3rdParty.cmake | 4 ++++ src/c/weaver/weave/perfflow_weave.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/c/cmake/Setup3rdParty.cmake b/src/c/cmake/Setup3rdParty.cmake index 168ee13b..ec83efb6 100644 --- a/src/c/cmake/Setup3rdParty.cmake +++ b/src/c/cmake/Setup3rdParty.cmake @@ -30,4 +30,8 @@ if(PERFFLOWASPECT_WITH_CALIPER) message(STATUS "PPP ${caliper_DIR}") include(cmake/thirdparty/FindCaliper.cmake) endif() + + if(CALIPER_FOUND) + add_definitions(-DPERFFLOWASPECT_WITH_CALIPER) + endif() endif() diff --git a/src/c/weaver/weave/perfflow_weave.cpp b/src/c/weaver/weave/perfflow_weave.cpp index 18f81d3e..507b5ee6 100644 --- a/src/c/weaver/weave/perfflow_weave.cpp +++ b/src/c/weaver/weave/perfflow_weave.cpp @@ -205,11 +205,13 @@ bool WeavingPass::doInitialization(Module &m) //AB.addAttribute(Attribute::ArgMemOnly); AttributeList Attrs = AttributeList::get(m.getContext(), AttributeList::FunctionIndex, AB); +#ifdef PERFFLOWASPECT_WITH_CALIPER // 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; auto a = cast (annotations->getOperand(0)); From 1f18b0b4fb659f46247634d72a326d4c631072da Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 10 May 2024 11:11:08 -0700 Subject: [PATCH 07/17] refine FindCaliper to ignore global caliper installs --- src/c/cmake/thirdparty/FindCaliper.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/c/cmake/thirdparty/FindCaliper.cmake b/src/c/cmake/thirdparty/FindCaliper.cmake index 673d9be0..585cd921 100644 --- a/src/c/cmake/thirdparty/FindCaliper.cmake +++ b/src/c/cmake/thirdparty/FindCaliper.cmake @@ -17,7 +17,12 @@ message(STATUS "Looking for Caliper in: ${caliper_DIR}") find_package(caliper REQUIRED - PATHS ${caliper_DIR}/share/cmake/caliper) + 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}") From f81c86ebfdb7662f65aba6a79478b51759979244 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 10 May 2024 11:27:33 -0700 Subject: [PATCH 08/17] fix ifdefs for caliper annotations --- src/c/weaver/weave/perfflow_weave.cpp | 4 ++++ src/c/weaver/weave/perfflow_weave.hpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/c/weaver/weave/perfflow_weave.cpp b/src/c/weaver/weave/perfflow_weave.cpp index 507b5ee6..a99f51f0 100644 --- a/src/c/weaver/weave/perfflow_weave.cpp +++ b/src/c/weaver/weave/perfflow_weave.cpp @@ -88,6 +88,7 @@ bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a, return true; } +#ifdef PERFFLOWASPECT_WITH_CALIPER bool WeavingPass::instrumentCaliper(Module &M, Function &F) { IRBuilder<> IRB(M.getContext()); @@ -134,6 +135,7 @@ bool WeavingPass::instrumentCaliper(Module &M, Function &F) return RetFound; } +#endif bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, int async, std::string &scope, std::string &flow, std::string pcut) @@ -220,9 +222,11 @@ bool WeavingPass::doInitialization(Module &m) auto e = cast (a->getOperand(i)); if (auto *fn = dyn_cast (e->getOperand(0)->getOperand(0))) { +#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)) diff --git a/src/c/weaver/weave/perfflow_weave.hpp b/src/c/weaver/weave/perfflow_weave.hpp index 6b27094c..a657e307 100644 --- a/src/c/weaver/weave/perfflow_weave.hpp +++ b/src/c/weaver/weave/perfflow_weave.hpp @@ -42,7 +42,9 @@ class WeavingPass : public FunctionPass 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 }; } From 7ec39ca1f3926761c7fad0dae04deffef6c334e7 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 10 May 2024 11:40:34 -0700 Subject: [PATCH 09/17] add caliper to multithreaded and mpi tests --- src/c/test/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index e5fbe15b..4ee796ef 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -39,7 +39,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 -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) @@ -47,7 +51,11 @@ 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 -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) From a697668bb7bcca4ef990060d4d750f8340d79f86 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 27 Sep 2024 16:46:32 -0700 Subject: [PATCH 10/17] remove finding of adiak package --- src/c/config/perfflowaspect_setup_deps.cmake | 16 ---------------- src/c/runtime/CMakeLists.txt | 1 - 2 files changed, 17 deletions(-) diff --git a/src/c/config/perfflowaspect_setup_deps.cmake b/src/c/config/perfflowaspect_setup_deps.cmake index b7afefd5..98f6ba02 100644 --- a/src/c/config/perfflowaspect_setup_deps.cmake +++ b/src/c/config/perfflowaspect_setup_deps.cmake @@ -7,22 +7,6 @@ endif() if(caliper_DIR) if(NOT PerfFlowAspect_FIND_QUIETLY) message(STATUS "PerfFlowAspect was built with Caliper Support") - endif() - -# if(NOT ADIAK_DIR) -# set(ADIAK_DIR ${ASCENT_ADIAK_DIR}) -# endif() -# -# if(ADIAK_DIR) -# if(NOT PerfFlowAspect_FIND_QUIETLY) -# message(STATUS "Looking for Adiak at: ${ADIAK_DIR}/lib/cmake/adiak") -# endif() -# # find adiak first -# find_package(adiak REQUIRED -# NO_DEFAULT_PATH -# PATHS ${ADIAK_DIR}/lib/cmake/adiak) -# endif() - if(NOT PerfFlowAspect_FIND_QUIETLY) message(STATUS "Looking for Caliper at: ${caliper_DIR}/share/cmake/caliper") endif() diff --git a/src/c/runtime/CMakeLists.txt b/src/c/runtime/CMakeLists.txt index e8d8fd8d..05130853 100644 --- a/src/c/runtime/CMakeLists.txt +++ b/src/c/runtime/CMakeLists.txt @@ -15,7 +15,6 @@ set(perfflow_runtime_sources include_directories(${JANSSON_INCLUDE_DIRS}) if(PERFFLOWASPECT_WITH_CALIPER) - message(STATUS "RRR ${caliper_LIB_DIR} ${caliper_CONFIG_LOADED}") include_directories(${caliper_INCLUDE_DIR}) endif() From 86dd7c35b6eba5a2cc4fc56fc083b90c58580f7e Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 27 Sep 2024 16:55:05 -0700 Subject: [PATCH 11/17] restore variable names, remove extra lines --- src/c/weaver/weave/perfflow_weave.cpp | 8 ++++---- src/c/weaver/weave/perfflow_weave.hpp | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/c/weaver/weave/perfflow_weave.cpp b/src/c/weaver/weave/perfflow_weave.cpp index a99f51f0..3d24d41d 100644 --- a/src/c/weaver/weave/perfflow_weave.cpp +++ b/src/c/weaver/weave/perfflow_weave.cpp @@ -71,14 +71,14 @@ bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a, { IRBuilder<> builder(inst); Value *v1 = builder.CreateGlobalStringPtr(m.getName(), "str"); - Value *FnNameStr = builder.CreateGlobalStringPtr(f.getName(), "str"); + Value *v2 = builder.CreateGlobalStringPtr(f.getName(), "str"); Value *v3 = builder.CreateGlobalStringPtr(StringRef(scope), "str"); Value *v4 = builder.CreateGlobalStringPtr(StringRef(flow), "str"); Value *v5 = builder.CreateGlobalStringPtr(StringRef(pcut), "str"); std::vector args; args.push_back(ConstantInt::get(Type::getInt32Ty(context), async)); args.push_back(v1); - args.push_back(FnNameStr); + args.push_back(v2); args.push_back(v3); args.push_back(v4); args.push_back(v5); @@ -167,7 +167,7 @@ bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, auto &entry = f.getEntryBlock(); IRBuilder<> builder(&entry); Value *v1 = builder.CreateGlobalStringPtr(m.getName(), "str"); - Value *FnNameStr = builder.CreateGlobalStringPtr(f.getName(), "str"); + Value *v2 = builder.CreateGlobalStringPtr(f.getName(), "str"); Value *v3 = builder.CreateGlobalStringPtr(StringRef(scope), "str"); Value *v4 = builder.CreateGlobalStringPtr(StringRef(flow), "str"); Value *v5 = builder.CreateGlobalStringPtr(StringRef(pcut), "str"); @@ -175,7 +175,7 @@ bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, std::vector args; args.push_back(ConstantInt::get(Type::getInt32Ty(context), async)); args.push_back(v1); - args.push_back(FnNameStr); + args.push_back(v2); args.push_back(v3); args.push_back(v4); args.push_back(v5); diff --git a/src/c/weaver/weave/perfflow_weave.hpp b/src/c/weaver/weave/perfflow_weave.hpp index a657e307..c29a5955 100644 --- a/src/c/weaver/weave/perfflow_weave.hpp +++ b/src/c/weaver/weave/perfflow_weave.hpp @@ -30,7 +30,6 @@ class WeavingPass : public FunctionPass public: FunctionCallee CaliBeginRegion; FunctionCallee CaliEndRegion; - static char ID; WeavingPass () : FunctionPass (ID) {} virtual bool doInitialization (Module &m); From d995b4783575055e2dcfbaec078438bdfbd0116f Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 27 Sep 2024 20:57:35 -0700 Subject: [PATCH 12/17] astyle format --- src/c/weaver/weave/perfflow_weave.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/c/weaver/weave/perfflow_weave.cpp b/src/c/weaver/weave/perfflow_weave.cpp index 3d24d41d..8cf17821 100644 --- a/src/c/weaver/weave/perfflow_weave.cpp +++ b/src/c/weaver/weave/perfflow_weave.cpp @@ -184,6 +184,7 @@ bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, return true; } + /****************************************************************************** * * * Public Methods of WeavingPass Class * @@ -209,10 +210,10 @@ bool WeavingPass::doInitialization(Module &m) AttributeList::FunctionIndex, AB); #ifdef PERFFLOWASPECT_WITH_CALIPER // 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()); + 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; From c656a9a69ddab63ff03f03ddce2ec0297aeed44a Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 27 Sep 2024 21:00:25 -0700 Subject: [PATCH 13/17] update CI config for caliper --- .github/workflows/github-actions.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index f6a39a86..2e73e5eb 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -48,9 +48,9 @@ jobs: PERFFLOWASPECT_WITH_CALIPER: OFF - config: boilerplate_caliper - PERFFLOWASPECT_WITH_CUDA: ON - PERFFLOWASPECT_WITH_MPI: ON - PERFFLOWASPECT_WITH_MULTITHREADS: ON + PERFFLOWASPECT_WITH_CUDA: OFF + PERFFLOWASPECT_WITH_MPI: OFF + PERFFLOWASPECT_WITH_MULTITHREADS: OFF CMAKE_BUILD_TYPE: Debug PERFFLOWASPECT_WITH_CALIPER: ON From e4c3f30081ae4c21405921e5301ed6272349434e Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 27 Sep 2024 21:10:47 -0700 Subject: [PATCH 14/17] CI only test caliper --- .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 2e73e5eb..b6440329 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - config: [boilerplate, release, debug_cuda_only, debug_mpi_only, debug_threads_only, boilerplate_caliper] + config: [boilerplate_caliper] include: - config: boilerplate From 923cc3022093ff0526731fe13e34629c7ec1d95b Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Sat, 28 Sep 2024 06:49:52 -0700 Subject: [PATCH 15/17] list all --- .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 b6440329..2e73e5eb 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - config: [boilerplate_caliper] + config: [boilerplate, release, debug_cuda_only, debug_mpi_only, debug_threads_only, boilerplate_caliper] include: - config: boilerplate From 57f498ffbdc707c27acc5e38c60fc1542b82428f Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Mon, 30 Sep 2024 09:20:23 -0700 Subject: [PATCH 16/17] add package config files, example builds with PFA built with caliper --- src/c/config/CMakeLists.txt | 1 + src/c/config/perfflowaspect-config.cmake.in | 2 +- .../config/perfflowaspect_setup_targets.cmake | 6 ++++ .../examples/using-with-cmake/CMakeLists.txt | 28 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/c/config/perfflowaspect_setup_targets.cmake diff --git a/src/c/config/CMakeLists.txt b/src/c/config/CMakeLists.txt index 84912726..959f6897 100644 --- a/src/c/config/CMakeLists.txt +++ b/src/c/config/CMakeLists.txt @@ -43,6 +43,7 @@ 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 fb4e6cfa..c8e7b809 100644 --- a/src/c/config/perfflowaspect-config.cmake.in +++ b/src/c/config/perfflowaspect-config.cmake.in @@ -6,7 +6,7 @@ if (NOT PERFFLOWASPECT_CONFIG_LOADED) set(PERFFLOWASPECT_CALIPER_ENABLED "@PERFFLOWASPECT_CALIPER_ENABLED@") set(PERFFLOWASPECT_CALIPER_DIR "@caliper_DIR@") - include(${PERFFLOWASPECT_INSTALL_PREFIX}/share/perfflowaspect_setup_deps.cmake) + include(${PERFFLOWASPECT_DIR}/share/perfflowaspect_setup_deps.cmake) find_dependency(OpenSSL REQUIRED) 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) diff --git a/src/c/examples/using-with-cmake/CMakeLists.txt b/src/c/examples/using-with-cmake/CMakeLists.txt index fc17f929..72c66743 100644 --- a/src/c/examples/using-with-cmake/CMakeLists.txt +++ b/src/c/examples/using-with-cmake/CMakeLists.txt @@ -23,6 +23,21 @@ cmake_minimum_required(VERSION 3.0) project(using_with_cmake) +# Fail if using Clang < 9.0 +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # require at least Clang 9.0 + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) + message(FATAL_ERROR "Clang++ version must be at least 9.0!") + elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11) + set(PERFFLOWASPECT_CLANG_11_NEWER TRUE CACHE BOOL "using >=clang11") + add_definitions(-DPERFFLOWASPECT_CLANG_11_NEWER) + elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11) + set(PERFFLOWASPECT_CLANG_11_NEWER FALSE CACHE BOOL "using >=clang11") + endif() +else() + message(WARNING "Unsupported CXX compiler: please use Clang >= 9.0") +endif() + # # Provide default for PERFFLOWASPECT_DIR that works for an PerfFlowAspect install # @@ -39,3 +54,16 @@ if(NOT EXISTS ${PERFFLOWASPECT_DIR}/share/perfflowaspect-config.cmake) endif() # +# Use CMake's find_package to import PerfFlowAspect's targets +# +find_package(PerfFlowAspect REQUIRED + NO_DEFAULT_PATH + PATHS ${PERFFLOWASPECT_DIR}/share) + +# create our example +add_executable(smoketest smoketest.cpp) + +# link to PerfFlowAspect +target_link_libraries(smoketest perfflowaspect::perfflowaspect) + +# From 1d0fd94de7c298172b012033026dfee5cdec496b Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Mon, 30 Sep 2024 19:55:36 -0700 Subject: [PATCH 17/17] add caliper docs --- 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::