From 13bdcf5fdbf5b8e266c5e9c1eb360d6792daea86 Mon Sep 17 00:00:00 2001 From: David Boehme Date: Wed, 30 Oct 2024 20:06:40 +0100 Subject: [PATCH] Make caliper-tools-util private (#615) --- examples/apps/cali-memtracking-macros.cpp | 14 ++-- examples/apps/cali-memtracking.cpp | 69 ++++++++++--------- src/tools/cali-query/CMakeLists.txt | 8 +-- src/tools/cali-query/cali-query.cpp | 2 +- src/tools/cali-query/query_common.cpp | 2 +- src/tools/cali-stat/cali-stat.cpp | 2 +- src/tools/mpi-caliquery/CMakeLists.txt | 4 +- src/tools/mpi-caliquery/mpi-caliquery.cpp | 2 +- src/tools/util/Args.cpp | 2 +- .../tools-util => src/tools/util}/Args.h | 0 src/tools/util/CMakeLists.txt | 19 +---- test/cali-annotation-perftest.cpp | 3 +- test/cali-flush-perftest.cpp | 3 +- 13 files changed, 56 insertions(+), 74 deletions(-) rename {include/caliper/tools-util => src/tools/util}/Args.h (100%) diff --git a/examples/apps/cali-memtracking-macros.cpp b/examples/apps/cali-memtracking-macros.cpp index 3980bc8ef..b5be4776b 100644 --- a/examples/apps/cali-memtracking-macros.cpp +++ b/examples/apps/cali-memtracking-macros.cpp @@ -1,11 +1,11 @@ // Copyright (c) 2019, Lawrence Livermore National Security, LLC. // See top-level LICENSE file for details. -#include "caliper/tools-util/Args.h" - #include #include +#include "../../src/tools/util/Args.h" + #include size_t row_major(size_t x, size_t y, size_t width) @@ -67,9 +67,9 @@ void do_work(size_t M, size_t W, size_t N) CALI_MARK_END("sum"); CALI_MARK_BEGIN("free"); - CALI_DATATRACKER_FREE(matA); - CALI_DATATRACKER_FREE(matB); - CALI_DATATRACKER_FREE(matC); + CALI_DATATRACKER_UNTRACK(matA); + CALI_DATATRACKER_UNTRACK(matB); + CALI_DATATRACKER_UNTRACK(matC); CALI_MARK_END("free"); } @@ -84,7 +84,7 @@ int main(int argc, const char* argv[]) { "n_size", "n_size", 'n', true, "Height of input matrix B", "elements" }, { "iterations", "iterations", 'i', true, "Number of iterations", "iterations" }, - util::Args::Table::Terminator + util::Args::Terminator }; util::Args args(option_table); @@ -92,7 +92,7 @@ int main(int argc, const char* argv[]) int lastarg = args.parse(argc, argv); if (lastarg < argc) { - std::cerr << "cali-throughput-thread: unknown option: " << argv[lastarg] << '\n' << " Available options: "; + std::cerr << "cali-memtracking-macros: unknown option: " << argv[lastarg] << '\n' << " Available options: "; args.print_available_options(std::cerr); diff --git a/examples/apps/cali-memtracking.cpp b/examples/apps/cali-memtracking.cpp index f3a663c00..eec13d107 100644 --- a/examples/apps/cali-memtracking.cpp +++ b/examples/apps/cali-memtracking.cpp @@ -1,12 +1,10 @@ // Copyright (c) 2019, Lawrence Livermore National Security, LLC. // See top-level LICENSE file for details. -#include "caliper/tools-util/Args.h" +#include +#include -#include "caliper/cali_datatracker.h" - -#include -#include +#include "../../src/tools/util/Args.h" #include @@ -19,18 +17,22 @@ void do_work(size_t M, size_t W, size_t N) { size_t i, j, k; - cali::Annotation alloc_phase(cali::Annotation("phase").begin("allocate")); - const size_t dimA[] = { M, W }; const size_t dimB[] = { W, N }; const size_t dimC[] = { M, N }; - double* matA = (double*) cali_datatracker_allocate_dimensional("A", sizeof(double), dimA, 2); - double* matB = (double*) cali_datatracker_allocate_dimensional("B", sizeof(double), dimB, 2); - double* matC = (double*) cali_datatracker_allocate_dimensional("C", sizeof(double), dimC, 2); + CALI_MARK_BEGIN("allocate"); + + double* matA = new double[dimA[0]*dimA[1]]; + double* matB = new double[dimB[0]*dimB[1]]; + double* matC = new double[dimC[0]*dimC[1]]; - alloc_phase.end(); - cali::Annotation init_phase(cali::Annotation("phase").begin("initialize_values")); + cali_datatracker_track_dimensional(matA, "A", sizeof(double), dimA, 2); + cali_datatracker_track_dimensional(matB, "B", sizeof(double), dimB, 2); + cali_datatracker_track_dimensional(matC, "C", sizeof(double), dimC, 2); + + CALI_MARK_END("allocate"); + CALI_MARK_BEGIN("initialize_values"); // Initialize A and B randomly for (i = 0; i < M; i++) @@ -41,8 +43,8 @@ void do_work(size_t M, size_t W, size_t N) for (j = 0; j < N; j++) matB[row_major(k, j, W)] = rand(); - init_phase.end(); - cali::Annotation mul_phase(cali::Annotation("phase").begin("multiply")); + CALI_MARK_END("initialize_values"); + CALI_MARK_BEGIN("multiply"); // AB = C for (i = 0; i < M; i++) @@ -50,8 +52,8 @@ void do_work(size_t M, size_t W, size_t N) for (k = 0; k < W; k++) matC[row_major(i, j, M)] += matA[row_major(i, k, M)] * matB[row_major(k, j, W)]; - mul_phase.end(); - cali::Annotation sum_phase(cali::Annotation("phase").begin("sum")); + CALI_MARK_END("multiply"); + CALI_MARK_BEGIN("sum"); // Print sum of elems in C double cSum = 0; @@ -61,18 +63,24 @@ void do_work(size_t M, size_t W, size_t N) std::cout << "cSum = " << cSum << std::endl; - sum_phase.end(); - cali::Annotation free_phase(cali::Annotation("phase").begin("free")); + CALI_MARK_END("sum"); + CALI_MARK_BEGIN("free"); + + cali_datatracker_untrack(matA); + cali_datatracker_untrack(matB); + cali_datatracker_untrack(matC); - cali_datatracker_free(matA); - cali_datatracker_free(matB); - cali_datatracker_free(matC); + delete[] matA; + delete[] matB; + delete[] matC; - free_phase.end(); + CALI_MARK_END("free"); } int main(int argc, const char* argv[]) { + CALI_CXX_MARK_FUNCTION; + // parse command line arguments const util::Args::Table option_table[] = { @@ -81,7 +89,7 @@ int main(int argc, const char* argv[]) { "n_size", "n_size", 'n', true, "Height of input matrix B", "elements" }, { "iterations", "iterations", 'i', true, "Number of iterations", "iterations" }, - util::Args::Table::Terminator + util::Args::Terminator }; util::Args args(option_table); @@ -89,10 +97,8 @@ int main(int argc, const char* argv[]) int lastarg = args.parse(argc, argv); if (lastarg < argc) { - std::cerr << "cali-throughput-thread: unknown option: " << argv[lastarg] << '\n' << " Available options: "; - + std::cerr << "cali-memtracking: unknown option: " << argv[lastarg] << '\n' << " Available options: "; args.print_available_options(std::cerr); - return -1; } @@ -101,15 +107,10 @@ int main(int argc, const char* argv[]) size_t n_size = std::stoul(args.get("n_size", "512")); size_t num_iterations = std::stoul(args.get("iterations", "4")); - cali::Annotation phase_annotation("phase", CALI_ATTR_SCOPE_PROCESS); - - phase_annotation.begin("benchmark"); - - cali::Loop loop("loop"); + CALI_CXX_MARK_LOOP_BEGIN(loop, "loop"); for (size_t i = 0; i < num_iterations; i++) { - cali::Loop::Iteration iteration(loop.iteration((int) i)); + CALI_CXX_MARK_LOOP_ITERATION(loop, i); do_work(m_size, w_size, n_size); } - - phase_annotation.end(); + CALI_CXX_MARK_LOOP_END(loop); } diff --git a/src/tools/cali-query/CMakeLists.txt b/src/tools/cali-query/CMakeLists.txt index 8a080cdf0..34511cb97 100644 --- a/src/tools/cali-query/CMakeLists.txt +++ b/src/tools/cali-query/CMakeLists.txt @@ -1,8 +1,3 @@ -include_directories ("../../common") -include_directories ("../../reader") -include_directories ("../util") -include_directories ("../../caliper") - set(CALIPER_QUERY_COMMON_SOURCES query_common.cpp) @@ -15,9 +10,10 @@ target_compile_features(query-common PUBLIC cxx_std_11) add_executable(cali-query $ + $ ${CALIPER_QUERY_SOURCES}) -target_link_libraries(cali-query caliper-tools-util caliper) +target_link_libraries(cali-query caliper) target_link_libraries(cali-query Threads::Threads) install(TARGETS cali-query DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/tools/cali-query/cali-query.cpp b/src/tools/cali-query/cali-query.cpp index 332ed8418..fce1bc328 100644 --- a/src/tools/cali-query/cali-query.cpp +++ b/src/tools/cali-query/cali-query.cpp @@ -8,7 +8,7 @@ #include "AttributeExtract.h" #include "query_common.h" -#include "caliper/tools-util/Args.h" +#include "../util/Args.h" #include "caliper/cali.h" #include "caliper/cali-manager.h" diff --git a/src/tools/cali-query/query_common.cpp b/src/tools/cali-query/query_common.cpp index d8cb1b633..a5420e56a 100644 --- a/src/tools/cali-query/query_common.cpp +++ b/src/tools/cali-query/query_common.cpp @@ -9,7 +9,7 @@ #include "caliper/reader/Preprocessor.h" #include "caliper/reader/RecordSelector.h" -#include "caliper/tools-util/Args.h" +#include "../util/Args.h" #include "caliper/common/Log.h" diff --git a/src/tools/cali-stat/cali-stat.cpp b/src/tools/cali-stat/cali-stat.cpp index 72d9496d9..2ba08e746 100644 --- a/src/tools/cali-stat/cali-stat.cpp +++ b/src/tools/cali-stat/cali-stat.cpp @@ -5,7 +5,7 @@ #include "caliper/Annotation.h" -#include "caliper/tools-util/Args.h" +#include "../util/Args.h" #include "caliper/reader/Aggregator.h" #include "caliper/reader/CaliReader.h" diff --git a/src/tools/mpi-caliquery/CMakeLists.txt b/src/tools/mpi-caliquery/CMakeLists.txt index d8c5e15f6..70ce2fa61 100644 --- a/src/tools/mpi-caliquery/CMakeLists.txt +++ b/src/tools/mpi-caliquery/CMakeLists.txt @@ -3,9 +3,9 @@ include_directories(${MPI_CXX_INCLUDE_PATH}) add_executable(mpi-caliquery $ + $ mpi-caliquery.cpp) -target_link_libraries(mpi-caliquery caliper caliper-tools-util) -target_link_libraries(mpi-caliquery ${MPI_CXX_LIBRARIES}) +target_link_libraries(mpi-caliquery caliper ${MPI_CXX_LIBRARIES}) install(TARGETS mpi-caliquery DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/tools/mpi-caliquery/mpi-caliquery.cpp b/src/tools/mpi-caliquery/mpi-caliquery.cpp index d2c04e273..9fb60fc00 100644 --- a/src/tools/mpi-caliquery/mpi-caliquery.cpp +++ b/src/tools/mpi-caliquery/mpi-caliquery.cpp @@ -7,7 +7,7 @@ #include "caliper/cali.h" #include "caliper/cali-manager.h" -#include "caliper/tools-util/Args.h" +#include "../util/Args.h" #include "caliper/reader/Aggregator.h" #include "caliper/reader/CaliReader.h" diff --git a/src/tools/util/Args.cpp b/src/tools/util/Args.cpp index c918d6f23..58d0f0da9 100644 --- a/src/tools/util/Args.cpp +++ b/src/tools/util/Args.cpp @@ -4,7 +4,7 @@ ///@file Args.cpp /// Argument parsing implementation -#include "caliper/tools-util/Args.h" +#include "Args.h" #include #include diff --git a/include/caliper/tools-util/Args.h b/src/tools/util/Args.h similarity index 100% rename from include/caliper/tools-util/Args.h rename to src/tools/util/Args.h diff --git a/src/tools/util/CMakeLists.txt b/src/tools/util/CMakeLists.txt index 2e76a4f35..965815fc6 100644 --- a/src/tools/util/CMakeLists.txt +++ b/src/tools/util/CMakeLists.txt @@ -1,22 +1,5 @@ set(CALIPER_TOOLS_UTIL_SOURCES Args.cpp) -add_library(caliper-tools-util ${CALIPER_TOOLS_UTIL_SOURCES}) - +add_library(caliper-tools-util OBJECT ${CALIPER_TOOLS_UTIL_SOURCES}) target_compile_features(caliper-tools-util PUBLIC cxx_std_11) - -set_target_properties(caliper-tools-util PROPERTIES SOVERSION ${CALIPER_MAJOR_VERSION}) -set_target_properties(caliper-tools-util PROPERTIES VERSION ${CALIPER_VERSION}) - -install( - TARGETS - caliper-tools-util - EXPORT - caliper-targets - ARCHIVE DESTINATION - ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION - ${CMAKE_INSTALL_LIBDIR} - INCLUDES DESTINATION - ${CMAKE_INSTALL_INCLUDEDIR} -) diff --git a/test/cali-annotation-perftest.cpp b/test/cali-annotation-perftest.cpp index caa4d8fb9..3b11a729c 100644 --- a/test/cali-annotation-perftest.cpp +++ b/test/cali-annotation-perftest.cpp @@ -28,7 +28,8 @@ #include #include -#include + +#include "../src/tools/util/Args.h" #include #include diff --git a/test/cali-flush-perftest.cpp b/test/cali-flush-perftest.cpp index ecf030dd0..9bc82aa71 100644 --- a/test/cali-flush-perftest.cpp +++ b/test/cali-flush-perftest.cpp @@ -17,7 +17,8 @@ #include #include -#include + +#include "../src/tools/util/Args.h" #include #include