Skip to content

Commit

Permalink
Fixing CMake issues with IntelLLVM, memory wrapper output file naming…
Browse files Browse the repository at this point in the history
… and not ld_preloading when calling env during apex_exec.
  • Loading branch information
khuck committed Jun 29, 2023
1 parent 58ecc26 commit c6531c8
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 57 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ if (APEX_USE_PEDANTIC)
endif(APEX_WITH_CUDA)
endif (APEX_USE_PEDANTIC)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "IntelLLVM")
set(APEX_STDCXX_LIB "" CACHE STRING "C++ library for linking")
message("IntelLLVM compiler detected, no stdc++ library needed")
else()
set(APEX_STDCXX_LIB stdc++ CACHE STRING "C++ library for linking")
endif()

# PGI and Intel don't like the concurrentqueue code.
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
Expand Down
18 changes: 13 additions & 5 deletions src/apex/memory_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "apex.hpp"
#include <execinfo.h>
#include "address_resolution.hpp"
#include <stdio.h>

namespace apex {

Expand Down Expand Up @@ -192,15 +193,16 @@ void apex_report_leaks() {
if (once) return;
once = true;
static book_t& book = getBook();
book.saved_node_id = apex::apex::instance()->get_node_id();
std::stringstream ss;
ss << "memory_report." << book.saved_node_id << ".txt";
std::string tmp{ss.str()};
std::ofstream report (tmp);
std::string outfile{ss.str()};
std::ofstream report (outfile);
// Declare vector of pairs
std::vector<std::pair<void*, record_t> > sorted;

if (book.saved_node_id == 0) {
std::cout << "APEX Memory Report: (see " << tmp << ")" << std::endl;
std::cout << "APEX Memory Report: (see " << outfile << ")" << std::endl;
std::cout << "sorting " << book.memoryMap.size() << " leaks by size..." << std::endl;
}

Expand All @@ -217,9 +219,10 @@ void apex_report_leaks() {

if (book.saved_node_id == 0) {
std::cout << "Aggregating leaks by task and writing report..." << std::endl;
if (!apex_options::use_cuda()) {
if (apex_options::use_cuda()) {
std::cout << "Ignoring known leaks in CUDA/CUPTI..." << std::endl;
}
std::cout << "If there are no leaks, there won't be a file..." << std::endl;
}
size_t actual_leaks{0};
// Print the sorted value
Expand Down Expand Up @@ -282,7 +285,12 @@ void apex_report_leaks() {
actual_leaks++;
}
report.close();
std::cout << "Reported " << actual_leaks << " 'actual' leaks.\nExpect false positives if memory was freed after exit." << std::endl;
if (book.saved_node_id == 0) {
std::cout << "Reported " << actual_leaks << " 'actual' leaks.\nExpect false positives if memory was freed after exit." << std::endl;
}
if (actual_leaks == 0) {
remove(outfile.c_str());
}

/*
std::cout << "sorting task leaks by size..." << std::endl;
Expand Down
16 changes: 8 additions & 8 deletions src/examples/DemoC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Make sure the compiler can find include files from our Apex library.
include_directories (${APEX_SOURCE_DIR}/src/apex)
# Make sure the compiler can find include files from our Apex library.
include_directories (${APEX_SOURCE_DIR}/src/apex)

# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)
# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)

# Add executable called "apexCDemo" that is built from the source file
# "demo.c". The extensions are automatically found.
add_executable (apexCDemo demo.c)
# "demo.c". The extensions are automatically found.
add_executable (apexCDemo demo.c)

# Link the executable to the Apex library.
target_link_libraries (apexCDemo apex ${LIBS} stdc++ m)
# Link the executable to the Apex library.
target_link_libraries (apexCDemo apex ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(apexCDemo PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/examples/LuleshMPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DAPEX_ENABLE_MPI=1")

# Link the executable to the Apex library.
target_link_libraries (lulesh_MPI_2.0 apex apex_mpi apex_global_mpi
${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} stdc++ m)
${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(lulesh_MPI_2.0 PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/examples/MPIGlobalTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_dependencies (mpi_global_test apex apex_mpi apex_global_mpi)
add_dependencies (examples mpi_global_test)

# Link the executable to the Apex library.
target_link_libraries (mpi_global_test apex apex_mpi apex_global_mpi ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} stdc++ m)
target_link_libraries (mpi_global_test apex apex_mpi apex_global_mpi ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(mpi_global_test PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/examples/MPIImbalancePolicy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_dependencies (mpi_imbalance_test apex apex_mpi apex_global_mpi)
add_dependencies (examples mpi_imbalance_test)

# Link the executable to the Apex library.
target_link_libraries (mpi_imbalance_test apex apex_mpi apex_global_mpi ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} stdc++ m)
target_link_libraries (mpi_imbalance_test apex apex_mpi apex_global_mpi ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(mpi_imbalance_test PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/examples/MPITest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_dependencies (mpi_test apex)
add_dependencies (examples mpi_test)

# Link the executable to the Apex library.
target_link_libraries (mpi_test apex apex_mpi ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} stdc++ m)
target_link_libraries (mpi_test apex apex_mpi ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(mpi_test PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
16 changes: 8 additions & 8 deletions src/examples/Matmult/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Make sure the compiler can find include files from our Apex library.
include_directories (. ${APEX_SOURCE_DIR}/src/apex)
# Make sure the compiler can find include files from our Apex library.
include_directories (. ${APEX_SOURCE_DIR}/src/apex)

# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)
# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)

# Add executable called "apexCDemo" that is built from the source file
# "demo.c". The extensions are automatically found.
add_executable (matmult matmult_initialize.cpp matmult.cpp)
# "demo.c". The extensions are automatically found.
add_executable (matmult matmult_initialize.cpp matmult.cpp)
add_dependencies (matmult apex)
add_dependencies (examples matmult)

# Link the executable to the Apex library.
target_link_libraries (matmult apex ${LIBS} stdc++ m)
# Link the executable to the Apex library.
target_link_libraries (matmult apex ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(matmult PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/examples/OpenMPOverhead/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ add_dependencies (examples openmp_overhead)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")

# Link the executable to the Apex library.
target_link_libraries (openmp_overhead apex ${LIBS} ${OMPT_LIBRARIES} stdc++)
target_link_libraries (openmp_overhead apex ${LIBS} ${OMPT_LIBRARIES} ${APEX_STDCXX_LIB})
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(openmp_overhead PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
12 changes: 6 additions & 6 deletions src/examples/PolicyEngineExample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Make sure the compiler can find include files from our Apex library.
# Make sure the compiler can find include files from our Apex library.
include_directories (${APEX_SOURCE_DIR}/src/apex)

# Make sure the linker can find the Apex library once it is built.
# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)

# Add executable called "testPolicyEngine" that is built from the source file
# "testPolicyEngine.c". The extensions are automatically found.
add_executable (testPolicyEngine testPolicyEngine.c)
# "testPolicyEngine.c". The extensions are automatically found.
add_executable (testPolicyEngine testPolicyEngine.c)
add_dependencies (testPolicyEngine apex)
add_dependencies (examples testPolicyEngine)

# Link the executable to the Apex library.
target_link_libraries (testPolicyEngine apex ${LIBS} stdc++ m)
# Link the executable to the Apex library.
target_link_libraries (testPolicyEngine apex ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(testPolicyEngine PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
12 changes: 6 additions & 6 deletions src/examples/PolicyUnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Make sure the compiler can find include files from our Apex library.
# Make sure the compiler can find include files from our Apex library.
include_directories (${APEX_SOURCE_DIR}/src/apex)

# Make sure the linker can find the Apex library once it is built.
# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)

# Add executable called "policyUnitTest" that is built from the source file
# "policyUnitTest.c". The extensions are automatically found.
add_executable (policyUnitTest policyUnitTest.c)
# "policyUnitTest.c". The extensions are automatically found.
add_executable (policyUnitTest policyUnitTest.c)
add_dependencies (policyUnitTest apex)
add_dependencies (examples policyUnitTest)

# Link the executable to the Apex library.
target_link_libraries (policyUnitTest apex ${LIBS} stdc++ m)
# Link the executable to the Apex library.
target_link_libraries (policyUnitTest apex ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(policyUnitTest PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/examples/TestOpenMP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_dependencies (examples openmp_test)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")

# Link the executable to the Apex library.
target_link_libraries (openmp_test apex ${LIBS} ${OMPT_LIBRARIES} stdc++)
target_link_libraries (openmp_test apex ${LIBS} ${OMPT_LIBRARIES} ${APEX_STDCXX_LIB})
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(openmp_test PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
12 changes: 6 additions & 6 deletions src/examples/Throttling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Make sure the compiler can find include files from our Apex library.
# Make sure the compiler can find include files from our Apex library.
include_directories (${APEX_SOURCE_DIR}/src/apex)

# Make sure the linker can find the Apex library once it is built.
# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)

# Add executable called "testThrottling" that is built from the source file
# "testThrottling.c". The extensions are automatically found.
add_executable (testThrottling testThrottling.c)
# "testThrottling.c". The extensions are automatically found.
add_executable (testThrottling testThrottling.c)
add_dependencies (testThrottling apex)
add_dependencies (examples testThrottling)

# Link the executable to the Apex library.
target_link_libraries (testThrottling apex ${LIBS} stdc++ m)
# Link the executable to the Apex library.
target_link_libraries (testThrottling apex ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(testThrottling PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
12 changes: 6 additions & 6 deletions src/examples/ThrottlingActiveHarmony/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Make sure the compiler can find include files from our Apex library.
# Make sure the compiler can find include files from our Apex library.
include_directories (${APEX_SOURCE_DIR}/src/apex)

# Make sure the linker can find the Apex library once it is built.
# Make sure the linker can find the Apex library once it is built.
link_directories (${APEX_BINARY_DIR}/src/apex)

# Add executable called "testThrottlingActiveHarmony" that is built from the source file
# "testThrottlingActiveHarmony.c". The extensions are automatically found.
add_executable (testThrottlingActiveHarmony testThrottlingActiveHarmony.c)
# "testThrottlingActiveHarmony.c". The extensions are automatically found.
add_executable (testThrottlingActiveHarmony testThrottlingActiveHarmony.c)
add_dependencies (testThrottlingActiveHarmony apex)
add_dependencies (examples testThrottlingActiveHarmony)

# Link the executable to the Apex library.
target_link_libraries (testThrottlingActiveHarmony apex ${LIBS} stdc++ m)
# Link the executable to the Apex library.
target_link_libraries (testThrottlingActiveHarmony apex ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(testThrottlingActiveHarmony PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ foreach(example_program ${example_programs})
# Use the tool-enabled OpenMP runtime
target_compile_options(${example_program} PRIVATE "-mp=ompt")
target_link_options(${example_program} PRIVATE "-mp=ompt")
target_link_libraries (${example_program} apex ${LIBS} stdc++ m)
target_link_libraries (${example_program} apex ${LIBS} ${APEX_STDCXX_LIB} m)
else()
target_link_libraries (${example_program} ${OMPT_LIBRARIES} apex ${LIBS} OpenMP::OpenMP_CXX stdc++ m)
target_link_libraries (${example_program} ${OMPT_LIBRARIES} apex ${LIBS} OpenMP::OpenMP_CXX ${APEX_STDCXX_LIB} m)
endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "NVHPC")
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(${example_program} PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
Expand Down
3 changes: 3 additions & 0 deletions src/scripts/apex_exec
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,16 @@ fi
# and iterate over them, setting different output directories for each.

# Print out all APEX environment variables that have been set.
APEX_SAVE_LD_PRELOAD=${LD_PRELOAD}
unset LD_PRELOAD
env | while IFS= read -r line; do
value=${line#*=}
name=${line%%=*}
if [[ $value == APEX* ]] ; then
echo "$value: $name"
fi
done
export LD_PRELOAD=${APEX_SAVE_LD_PRELOAD}

delim=";"
long_metrics=${APEX_PAPI_METRICS}
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/C++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ add_dependencies (apex_hpx_annotated_functions_mpi apex)
add_dependencies (examples apex_hpx_annotated_functions_mpi)

# Link the executable to the Apex library.
target_link_libraries (apex_hpx_annotated_functions_mpi apex ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} stdc++ m)
target_link_libraries (apex_hpx_annotated_functions_mpi apex ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(apex_hpx_annotated_functions_mpi PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ foreach(example_program ${example_programs})
source_group("Source Files" FILES ${sources})

add_executable(${example_program} ${sources})
target_link_libraries (${example_program} apex ${LIBS} stdc++ m)
target_link_libraries (${example_program} apex ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(${example_program} PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/MPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ add_dependencies (mpi_cpi apex)
add_dependencies (tests mpi_cpi)

# Link the executable to the Apex library.
target_link_libraries (mpi_cpi apex ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} stdc++ m)
target_link_libraries (mpi_cpi apex ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES} ${LIBS} ${APEX_STDCXX_LIB} m)
if (BUILD_STATIC_EXECUTABLES)
set_target_properties(mpi_cpi PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ foreach(util_program ${util_programs})
set(sources ${util_program}.cpp)
source_group("Source Files" FILES ${sources})
add_executable("${util_program}" ${sources})
target_link_libraries ("${util_program}" apex stdc++ ${LIBS})
target_link_libraries ("${util_program}" apex ${APEX_STDCXX_LIB} ${LIBS})
if (BUILD_STATIC_EXECUTABLES)
set_target_properties("${util_program}" PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
endif()
Expand Down

0 comments on commit c6531c8

Please sign in to comment.