Skip to content

Commit

Permalink
Integrating pmpmeas source straight into package
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanKierans committed Jul 7, 2024
1 parent f7e617e commit 3b532e5
Show file tree
Hide file tree
Showing 27 changed files with 1,872 additions and 38 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ jobs:
run: |
brew install zmq
# PACKAGE MANAGER PAPI INSTALL
- name: Install papi (linux)
if: runner.os == 'linux'
run: |
sudo apt-get install libpapi-dev papi-tools
# PACKAGE MANAGER PERF INSTALL
- name: Install perf (linux)
if: runner.os == 'linux'
run: |
sudo apt-get install linux-tools-generic
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
Expand Down
5 changes: 3 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#' @param max_nprocs Maximum number of R processes (ie evtWriters required)
#' @param archivePath Path to otf2 archive
#' @param archiveName Name of otf2 archive
#' @param collect_metrics Collect HWPC metrics via pmpmeas
#' @param flag_print_pids True to print pids of parent and child procs
#' @return <0 if error, 0 if R master, else >0 if child
init_otf2_logger <- function(max_nprocs, archivePath = "./rTrace", archiveName = "rTrace", flag_print_pids = FALSE) {
.Call('_rTrace_init_otf2_logger', PACKAGE = 'rTrace', max_nprocs, archivePath, archiveName, flag_print_pids)
init_otf2_logger <- function(max_nprocs, archivePath = "./rTrace", archiveName = "rTrace", collect_metrics = FALSE, flag_print_pids = FALSE) {
.Call('_rTrace_init_otf2_logger', PACKAGE = 'rTrace', max_nprocs, archivePath, archiveName, collect_metrics, flag_print_pids)
}

#' assign_regionRef_array_master
Expand Down
16 changes: 8 additions & 8 deletions R/rTrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ pkg.env$PRINT_FUNC_INDEXES <- FALSE
pkg.env$COLLECT_METRICS <- FALSE


# @name RTRACE_VARS
# @description List of all global rTrace variables
pkg.env$RTRACE_VARS <- c( "INSTRUMENTATION_INIT", "INSTRUMENTATION_ENABLED",
"INSTRUMENTATION_STATUS_SAVED", "MAX_FUNCTION_DEPTH",
"FUNCTION_DEPTH", "UNLOCK_ENVS", "PRINT_INSTRUMENTS",
"PRINT_SKIPS", "PRINT_FUNC_INDEXES",
"COLLECT_METRICS"
)
## @name RTRACE_VARS
## @description List of all global rTrace variables
#pkg.env$RTRACE_VARS <- c( "INSTRUMENTATION_INIT", "INSTRUMENTATION_ENABLED",
# "INSTRUMENTATION_STATUS_SAVED", "MAX_FUNCTION_DEPTH",
# "FUNCTION_DEPTH", "UNLOCK_ENVS", "PRINT_INSTRUMENTS",
# "PRINT_SKIPS", "PRINT_FUNC_INDEXES",
# "COLLECT_METRICS"
# )

3 changes: 2 additions & 1 deletion R/r_exception_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ get_function_exception_list <- function() {

# These functions contain on.exit() and blocks instrumentation insert
on.exit_functions <- c()
if (R.utils::isPackageLoaded("R.utils")){ on.exit_functions <- append(on.exit_functions, c(R.utils::read.table)) }
#if (R.utils::isPackageLoaded("R.utils")){ on.exit_functions <- append(on.exit_functions, c(R.utils::read.table)) }
if (R.utils::isPackageLoaded("utils")){ on.exit_functions <- append(on.exit_functions, c(utils::read.table)) }

function_exception_list <- append(function_exception_list, on.exit_functions)

Expand Down
8 changes: 8 additions & 0 deletions R/r_fork_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ master_init_slave <- function(cl) {
parallel::clusterExport(cl, c("pkg_cmd"), envir=environment())
parallel::clusterEvalQ(cl, eval(parse(text = pkg_cmd)))

## Attempted to store as pkg.env$RTRACE_VARS in rTrace.R, results in error
RTRACE_VARS <- c( "INSTRUMENTATION_INIT", "INSTRUMENTATION_ENABLED",
"INSTRUMENTATION_STATUS_SAVED", "MAX_FUNCTION_DEPTH",
"FUNCTION_DEPTH", "UNLOCK_ENVS", "PRINT_INSTRUMENTS",
"PRINT_SKIPS", "PRINT_FUNC_INDEXES",
"COLLECT_METRICS"
)

# Export rTrace variables
parallel::clusterExport(cl, c("RTRACE_VARS"), envir=environment())
parallel::clusterExport(cl, RTRACE_VARS, envir=pkg.env)
Expand Down
3 changes: 1 addition & 2 deletions R/r_instrument_hl.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ instrumentation_init <- function(flag_user_functions=T, collect_metrics=F, verbo
## Interface to pmpmeas
if (collect_metrics){
pkg.env$COLLECT_METRICS <- TRUE
pmpmeas_init()
}

## Initiate new proc - close R if not Master
ret <- init_otf2_logger(parallelly::availableCores()) # Master R proc returns 0
ret <- init_otf2_logger(parallelly::availableCores(), collect_metrics=collect_metrics) # Master R proc returns 0
if (ret != 0){ quit(save="no"); } # Unintended fork R proc for otf2 logger

## Assign array on logger proc for regionRef of each func
Expand Down
3 changes: 3 additions & 0 deletions man/init_otf2_logger.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/instrumentation_init.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/pkg.env.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ ZEROMQ_PKG_CPPFLAGS=-I${ZEROMQ_ROOT}/include
ZEROMQ_PKG_LIBS=-L${ZEROMQ_ROOT}/lib -lzmq

# pmpmeas - papi
PMPMEAS_PKG_CPPFLAGS=`pkg-config --cflags papi`
PMPMEAS_PKG_LIBS=`pkg-config --libs papi`
# num = PAPI_get_opt(PAPI_MAX_HWCTRS,NULL)
# papi_avail | grep "Number Hardware Counters :" | sed -e "s|Number Hardware Counters : ||g"
#PAPICNTMAX=3
#PAPICNTMAX=`papi_avail | grep "Number Hardware Counters :" | sed -e "s|Number Hardware Counters : ||"`
#PMPMEAS_PKG_CPPFLAGS=`pkg-config --cflags papi` -DUSEPAPI -DPAPICNTMAX=${PAPICNTMAX} -DRTRACE_SUPPORT -D_COLLECT_METRICS
#PMPMEAS_PKG_LIBS=`pkg-config --libs papi`
#
PAPICNTMAX=$(papi_avail | grep "Number Hardware Counters :" | sed -e "s|Number Hardware Counters : ||")
PMPMEAS_PKG_CPPFLAGS=$(pkg-config --cflags papi) -DUSEPAPI -DPAPICNTMAX=${PAPICNTMAX} -DRTRACE_SUPPORT -D_COLLECT_METRICS
PMPMEAS_PKG_LIBS=$(pkg-config --libs papi)

PKG_CPPFLAGS=-I. ${OTF2_PKG_CPPFLAGS} ${ZEROMQ_PKG_CPPFLAGS} ${PMPMEAS_PKG_CPPFLAGS}
PKG_LIBS=-L. ${OTF2_PKG_LIBS} ${ZEROMQ_PKG_LIBS} ${PMPMMEAS_PKG_LIBS}
PKG_LIBS=-L. ${OTF2_PKG_LIBS} ${ZEROMQ_PKG_LIBS} ${PMPMEAS_PKG_LIBS}

9 changes: 5 additions & 4 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// init_otf2_logger
RcppExport int init_otf2_logger(int max_nprocs, Rcpp::String archivePath, Rcpp::String archiveName, bool flag_print_pids);
RcppExport SEXP _rTrace_init_otf2_logger(SEXP max_nprocsSEXP, SEXP archivePathSEXP, SEXP archiveNameSEXP, SEXP flag_print_pidsSEXP) {
RcppExport int init_otf2_logger(int max_nprocs, Rcpp::String archivePath, Rcpp::String archiveName, bool collect_metrics, bool flag_print_pids);
RcppExport SEXP _rTrace_init_otf2_logger(SEXP max_nprocsSEXP, SEXP archivePathSEXP, SEXP archiveNameSEXP, SEXP collect_metricsSEXP, SEXP flag_print_pidsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< int >::type max_nprocs(max_nprocsSEXP);
Rcpp::traits::input_parameter< Rcpp::String >::type archivePath(archivePathSEXP);
Rcpp::traits::input_parameter< Rcpp::String >::type archiveName(archiveNameSEXP);
Rcpp::traits::input_parameter< bool >::type collect_metrics(collect_metricsSEXP);
Rcpp::traits::input_parameter< bool >::type flag_print_pids(flag_print_pidsSEXP);
rcpp_result_gen = Rcpp::wrap(init_otf2_logger(max_nprocs, archivePath, archiveName, flag_print_pids));
rcpp_result_gen = Rcpp::wrap(init_otf2_logger(max_nprocs, archivePath, archiveName, collect_metrics, flag_print_pids));
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -258,7 +259,7 @@ END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_rTrace_init_otf2_logger", (DL_FUNC) &_rTrace_init_otf2_logger, 4},
{"_rTrace_init_otf2_logger", (DL_FUNC) &_rTrace_init_otf2_logger, 5},
{"_rTrace_assign_regionRef_array_master", (DL_FUNC) &_rTrace_assign_regionRef_array_master, 1},
{"_rTrace_assign_regionRef_array_slave", (DL_FUNC) &_rTrace_assign_regionRef_array_slave, 1},
{"_rTrace_get_regionRef_from_array_slave", (DL_FUNC) &_rTrace_get_regionRef_from_array_slave, 1},
Expand Down
59 changes: 59 additions & 0 deletions src/m_pmpmeas.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
! -------
! PMPMEAS
! -------
!
! Copyright 2022 Dirk Pleiter ([email protected])
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions
! are met:
!
! 1. Redistributions of source code must retain the above copyright
! notice, this list of conditions and the following disclaimer.
!
! 2. The origin of this software must not be misrepresented; you must
! not claim that you wrote the original software. If you use this
! software in a product, an acknowledgment in the product
! documentation would be appreciated but is not required.
!
! 3. Altered source versions must be plainly marked as such, and must
! not be misrepresented as being the original software.
!
! 4. The name of the author may not be used to endorse or promote
! products derived from this software without specific prior written
! permission.
!
! THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
! OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
! DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
! GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module M_PMPMEAS
use ISO_C_BINDING, only : C_CHAR, C_FLOAT
interface

subroutine pmpmeas_init() bind(C,name='pmpmeas_init')
end subroutine

subroutine pmpmeas_start(tag) bind(C,name='pmpmeas_start')
import C_CHAR
character(kind=C_CHAR),dimension(*) :: tag
end subroutine

subroutine pmpmeas_stop(weight) bind(C,name='pmpmeas_stop_fortran')
import C_FLOAT
real(kind=C_FLOAT) :: weight
end subroutine

subroutine pmpmeas_finish() bind(C,name='pmpmeas_finish')
end subroutine

end interface
end module
Binary file added src/m_pmpmeas.mod
Binary file not shown.
76 changes: 76 additions & 0 deletions src/meas.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* -------
* PMPMEAS
* -------
*
* Copyright 2022 Dirk Pleiter ([email protected])
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. The origin of this software must not be misrepresented; you must
* not claim that you wrote the original software. If you use this
* software in a product, an acknowledgment in the product
* documentation would be appreciated but is not required.
*
* 3. Altered source versions must be plainly marked as such, and must
* not be misrepresented as being the original software.
*
* 4. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <cstdio>
#include "meas.h"

using namespace std;
using namespace PMPMEAS;

PapiInf Meas::_papi;
PerfInf Meas::_perf;

/*
* Dump measurement results
*/

void Meas::dump(FILE* fp)
{
fprintf(fp, "Tag: %s\n", _tag.c_str());
fprintf(fp,"Nmeas: %d\n", nmeas());
fprintf(fp, "Avg. Weight: %.4e\n", avweight());
for (int i = 0; i < _cnt; i++)
{
const char* prefix = "";
switch (_type())
{
case MeasType::PAPI:
prefix = "PAPI=";
break;
case MeasType::PERF:
prefix = "PERF=";
break;
}
fprintf(fp, "Type[%d]: %s%s\n", i, prefix, _type.typestr(i));

fprintf(fp, "Min[%d]: %.4e\n", i, min(i));
fprintf(fp, "Mean[%d]: %.4e\n", i, mean(i));
fprintf(fp, "Max[%d]: %.4e\n", i, max(i));
}
fprintf(fp, "\n");
}
Loading

0 comments on commit 3b532e5

Please sign in to comment.