Skip to content

Commit

Permalink
Merge pull request #51 from august-knox/gpu-opt
Browse files Browse the repository at this point in the history
Adding caliper annotations
  • Loading branch information
vladotomov authored Jan 7, 2025
2 parents f102edb + 7770136 commit 5725b01
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
20 changes: 17 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ TEST_MK = $(MFEM_DIR)/config/test.mk
MFEM_DIR1 := $(MFEM_DIR)
MFEM_DIR2 := $(realpath $(MFEM_DIR))

# Use Caliper annotations

ifdef CALIPER_DIR
CALIPER_DIR = $(spack location --install-dir caliper)
ADIAK_DIR = $(spack location --install-dir adiak)
CALIPER_FLAGS = -I${CALIPER_DIR}/include -DUSE_CALIPER
ADIAK_INCLUDE = -I${ADIAK_DIR}/include
ADIAK_LDFLAGS = -L${ADIAK_DIR}/lib -ladiak
CALIPER_LDFLAGS = -L${CALIPER_DIR}/lib64 -lcaliper
endif


# Use the compiler used by MFEM. Get the compiler and the options for compiling
# and linking from MFEM's config.mk. (Skip this if the target does not require
# building.)
Expand All @@ -73,15 +85,16 @@ ifeq (,$(filter help clean distclean style,$(MAKECMDGOALS)))
endif

CXX = $(MFEM_CXX)
CPPFLAGS = $(MFEM_CPPFLAGS)
CPPFLAGS = $(MFEM_CPPFLAGS) $(CALIPER_FLAGS) $(ADIAK_FLAGS)
CXXFLAGS = $(MFEM_CXXFLAGS)

# MFEM config does not define C compiler
CC = gcc
CFLAGS = -O3

# Optional link flags
LDFLAGS =
LDFLAGS = $(CALIPER_LDFLAGS) $(ADIAK_LDFLAGS)


OPTIM_OPTS = -O3
DEBUG_OPTS = -g -Wall -std=c++11
Expand All @@ -102,7 +115,8 @@ ifeq ($(REMHOS_DEBUG),YES)
endif

LIBS = $(strip $(REMHOS_LIBS) $(LDFLAGS))
CCC = $(strip $(CXX) $(REMHOS_FLAGS))
EXTRA_INC_DIR = $(or $(wildcard $(MFEM_DIR)/include/mfem),$(MFEM_DIR))
CCC = $(strip $(CXX) $(REMHOS_FLAGS) $(if $(EXTRA_INC_DIR),-I$(EXTRA_INC_DIR)))
Ccc = $(strip $(CC) $(CFLAGS) $(GL_OPTS))

SOURCE_FILES = remhos.cpp remhos_tools.cpp remhos_lo.cpp remhos_ho.cpp \
Expand Down
55 changes: 54 additions & 1 deletion remhos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
#include "remhos_tools.hpp"
#include "remhos_sync.hpp"

#ifdef USE_CALIPER
#include <caliper/cali.h>
#include <caliper/cali-manager.h>
//#include <adiak.hpp>
#ifdef HAVE_MPI
#include <caliper/cali-mpi.h>
#endif
#endif

using namespace std;
using namespace mfem;

Expand Down Expand Up @@ -76,6 +85,9 @@ double inflow_function(const Vector &x);
// Mesh bounding box
Vector bb_min, bb_max;

//Caliper setup
void setupCaliper();

class AdvectionOperator : public TimeDependentOperator
{
private:
Expand Down Expand Up @@ -279,6 +291,19 @@ MFEM_EXPORT int remhos(int argc, char *argv[], double &final_mass_u)
}
if (myid == 0) { args.PrintOptions(cout); }

//setup caliper config manager
#ifdef USE_CALIPER
setupCaliper();

cali::ConfigManager calimgr;
if (calimgr.error())
std::cerr << "caliper config error: " << calimgr.error_msg() << std::endl;
calimgr.start();
//adiak::init(nullptr);
//adiak::cmdline();
//adiak::hostname();
#endif

#ifdef REMHOS_GPU_SETUP
MFEM_VERIFY(ho_type == HOSolverType::LocalInverse &&
lo_type == LOSolverType::MassBased &&
Expand Down Expand Up @@ -415,14 +440,24 @@ MFEM_EXPORT int remhos(int argc, char *argv[], double &final_mass_u)
v.ProjectCoefficient(vcoeff);

double t = 0.0;
#ifdef USE_CALIPER
CALI_CXX_MARK_LOOP_BEGIN(mainloop, "rem.mainloop");
#endif
while (t < t_final)
{
#ifdef USE_CALIPER
CALI_CXX_MARK_LOOP_ITERATION(mainloop, t);
#endif
t += dt;
// Move the mesh nodes.
x.Add(std::min(dt, t_final-t), v);
// Update the node velocities.
v.ProjectCoefficient(vcoeff);
}
#ifdef USE_CALIPER
CALI_CXX_MARK_LOOP_END(mainloop);
#endif


// Pseudotime velocity.
add(x, -1.0, x0, v_gf);
Expand Down Expand Up @@ -1325,7 +1360,9 @@ MFEM_EXPORT int remhos(int argc, char *argv[], double &final_mass_u)
delete lom.SubFes1;
delete lom.VolumeTerms;
}

#ifdef USE_CALIPER
calimgr.flush();
#endif
return 0;
}

Expand Down Expand Up @@ -2017,3 +2054,19 @@ double inflow_function(const Vector &x)
}
else { return 0.0; }
}

void setupCaliper()
{
#ifdef USE_CALIPER
#ifdef HAVE_MPI
cali_mpi_init();
#endif

cali_config_preset("CALI_LOG_VERBOSITY", "0");
cali_config_preset("CALI_CALIPER_ATTRIBUTE_DEFAULT_SCOPE", "process");

//cali_set_global_string_byname("rem.git_vers", GIT_VERS);
//cali_set_global_string_byname("rem.git_hash", GIT_HASH);
#endif
}

0 comments on commit 5725b01

Please sign in to comment.