Skip to content

Commit

Permalink
Phiprof support
Browse files Browse the repository at this point in the history
  • Loading branch information
Camille Coti committed Jan 13, 2023
1 parent a230050 commit 6c82784
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,23 @@ if (APEX_WITH_STARPU)
endif()
endif (APEX_WITH_STARPU)

###############################################################################
# PhiProf configuration
################################################################################

if (APEX_WITH_PHIPROF)
find_package(PHIPROF REQUIRED)
if (PHIPROF_FOUND )
add_definitions(-DAPEX_WITH_PHIPROF)
message(INFO " Using PhiProf include: ${PHIPROF_INCLUDE_DIR}")
include_directories(${PHIPROF_INCLUDE_DIR})
# We need MPI
if (NOT MPI_CXX_FOUND)
message( FATAL_ERROR "MPI is required with PhiProf" )
endif (PHIPROF_FOUND)
endif (PHIPROF_FOUND)
endif (APEX_WITH_PHIPROF)

###############################################################################
# MSR configuration
################################################################################
Expand Down Expand Up @@ -1111,6 +1128,7 @@ dump_cmake_variables("^OMPT")
dump_cmake_variables("^OTF2")
dump_cmake_variables("^PAPI")
dump_cmake_variables("^STARPU")
dump_cmake_variables("^PHIPROF")
dump_cmake_variables("^HWLOC")
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
MESSAGE(STATUS "Libraries: " ${LIBS})
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/APEX_DefaultOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ option (APEX_WITH_OTF2 "Enable Open Trace Format 2 (OTF2) support" FALSE)
option (APEX_WITH_PAPI "Enable PAPI support" FALSE)
option (APEX_WITH_PLUGINS "Enable APEX policy plugin support" FALSE)
option (APEX_WITH_STARPU "Enable APEX StarPU support" FALSE)
option (APEX_WITH_PHIPROF "Enable APEX PhiProf support" FALSE)
option (APEX_WITH_TCMALLOC "Enable TCMalloc heap management" FALSE)
option (APEX_WITH_JEMALLOC "Enable JEMalloc heap management" FALSE)
option (APEX_WITH_LM_SENSORS "Enable LM Sensors support" FALSE)
Expand Down
47 changes: 47 additions & 0 deletions cmake/Modules/FindPhiProf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# - Try to find PhiProf
# Once done this will define
# PHIPROF_FOUND - System has PhiProf
# STARPU_INCLUDE_DIRS - The include directories


find_package(PkgConfig)

if(NOT DEFINED $PHIPROF_ROOT)
if(DEFINED ENV{PHIPROF_ROOT})
# message(" env PHIPROF_ROOT is defined as $ENV{PHIPROF_ROOT}")
set(PHIPROF_ROOT $ENV{PHIPROF_ROOT})
endif()
endif()

if(NOT DEFINED $PHIPROF_ROOT)
if(DEFINED PHIPROF_DIR)
# message(" env PHIPROF_ROOT is defined as $ENV{PHIPROF_ROOT}")
set(PHIPROF_ROOT $PHIPROF_DIR)
endif()
endif()

message(INFO " will check ${PHIPROF_ROOT} for PHIPROF")
set(CMAKE_PREFIX_PATH} "${CMAKE_PREFIX_PATH} ${PHIPROF_ROOT}")
set(ENV{PKG_CONFIG_PATH} "${PHIPROF_ROOT}/libs/pkgconfig")
pkg_check_modules(PHIPROF QUIET libstarpu)

if(NOT PHIPROF_FOUND)
find_path(PHIPROF_INCLUDE_DIR NAMES phiprof.hpp
HINTS ${PHIPROF_ROOT}/include)

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set PHIPROF_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(PHIPROF DEFAULT_MSG
PHIPROF_INCLUDE_DIR)

mark_as_advanced(PHIPROF_INCLUDE_DIR)
message( "Using ${PHIPROF_INCLUDE_DIR} as PhiProf include dir" )

if(PHIPROF_FOUND)
set(PHIPROF_INCLUDE_DIRS ${PHIPROF_INCLUDE_DIR})
set(PHIPROF_DIR ${PHIPROF_ROOT})
add_definitions(-DAPEX_HAVE_PHIPROF)
endif()
endif()

5 changes: 5 additions & 0 deletions src/apex/CMakeLists.standalone
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ if (STARPU_FOUND)
SET(STARPU_SOURCE apex_starpu.cpp)
endif(STARPU_FOUND)

if (APEX_WITH_PHIPROF)
SET(PHIPROF_SOURCE apex_phiprof.cpp)
endif (APEX_WITH_PHIPROF)

if (OpenACC_CXX_FOUND AND OpenACCProfiling_FOUND)
set(OpenACC_SOURCE apex_openacc.cpp)
endif (OpenACC_CXX_FOUND AND OpenACCProfiling_FOUND)
Expand Down Expand Up @@ -110,6 +114,7 @@ ${OMPT_SOURCE}
${OpenACC_SOURCE}
${RAJA_SOURCE}
${STARPU_SOURCE}
${PHIPROF_SOURCE}
concurrency_handler.cpp
dependency_tree.cpp
event_listener.cpp
Expand Down
119 changes: 119 additions & 0 deletions src/apex/apex_phiprof.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include <map>
#include <mpi.h>
#include <mutex>
#include <stack>
#include "apex.hpp"
#include <phiprof.hpp>

#warning compiling phiprof

/* Correspondance between labels and ids */

std::mutex mut;

std::map<std::string, int> timers_labels;
std::map<int, std::string> timers_ids;

int insertOrGet( const std::string &label ){
int id;
mut.lock();
auto it = timers_labels.find( label );
if( it == timers_labels.end() ){
id = timers_labels.size();
timers_labels[ label ] = id;
timers_ids[ id ] = label;
} else {
id = it->second;
}
mut.unlock();
return id;
}


/* Simple initialization. Returns true if started succesfully */

bool phiprof::initialize(){
return true;
}

/* Initialize a timer, with a particular label
*
* Initialize a timer. This enables one to define groups, and to use
* the return id value for more efficient starts/stops in tight
* loops. If this function is called for an existing timer it will
* simply just return the id.
*/

int phiprof::initializeTimer(const std::string &label, const std::vector<std::string> &groups){
return insertOrGet( label );
}

int phiprof::initializeTimer(const std::string &label){
return insertOrGet( label );
}

int phiprof::initializeTimer(const std::string &label,const std::string &group1) {
return insertOrGet( label );
}

int phiprof::initializeTimer(const std::string &label,const std::string &group1,const std::string &group2){
return insertOrGet( label );
}

int phiprof::initializeTimer(const std::string &label,const std::string &group1,const std::string &group2,const std::string &group3){
return insertOrGet( label );
}

/* Get id number of an existing timer that is a child of the currently
* active one */

int phiprof::getChildId(const std::string &label){
/* TODO */
return -1;
}

/* Start-stop timers */

static thread_local std::stack<std::shared_ptr<apex::task_wrapper> > my_stack;


bool phiprof::start(const std::string &label){
auto t = apex::new_task( label );
apex::start( t );
my_stack.push(t);
return true;
}

bool phiprof::start(int id){
auto label = timers_ids[ id ];
auto t = apex::new_task( label );
apex::start( t );
my_stack.push(t);
return true;
}

bool phiprof::stop (const std::string &label, double workUnits, const std::string &workUnitLabel){
auto t = my_stack.top();
apex::stop(t);
my_stack.pop();
return true;
}

bool phiprof::stop (int id, double workUnits, const std::string &workUnitLabel){
auto t = my_stack.top();
apex::stop(t);
my_stack.pop();
return true;
}

bool phiprof::stop (int id){
auto t = my_stack.top();
apex::stop(t);
my_stack.pop();
return true;
}

bool phiprof::print(MPI_Comm comm, std::string fileNamePrefix){
return true;
}

0 comments on commit 6c82784

Please sign in to comment.