Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor how we interface with performance instrumentation #969

Merged
merged 19 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions benchmarks/burgers/burgers_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void CalculateDerived(MeshData<Real> *md) {

// provide the routine that estimates a stable timestep for this package
Real EstimateTimestepMesh(MeshData<Real> *md) {
Kokkos::Profiling::pushRegion("Task_burgers_EstimateTimestepMesh");
PARTHENON_INSTRUMENT
auto pm = md->GetParentPointer();
IndexRange ib = md->GetBoundsI(IndexDomain::interior);
IndexRange jb = md->GetBoundsJ(IndexDomain::interior);
Expand Down Expand Up @@ -155,14 +155,13 @@ Real EstimateTimestepMesh(MeshData<Real> *md) {
},
Kokkos::Min<Real>(min_dt));

Kokkos::Profiling::popRegion(); // Task_burgers_EstimateTimestepMesh
return cfl * min_dt;
}

TaskStatus CalculateFluxes(MeshData<Real> *md) {
using parthenon::ScratchPad1D;
using parthenon::team_mbr_t;
Kokkos::Profiling::pushRegion("Task_burgers_CalculateFluxes");
PARTHENON_INSTRUMENT

auto pm = md->GetParentPointer();
const int ndim = pm->ndim;
Expand Down Expand Up @@ -360,7 +359,6 @@ TaskStatus CalculateFluxes(MeshData<Real> *md) {
}
});

Kokkos::Profiling::popRegion(); // Task_burgers_CalculateFluxes
return TaskStatus::complete;
}

Expand Down
3 changes: 1 addition & 2 deletions example/advection/advection_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ Real EstimateTimestepBlock(MeshBlockData<Real> *rc) {
TaskStatus CalculateFluxes(std::shared_ptr<MeshBlockData<Real>> &rc) {
using parthenon::MetadataFlag;

Kokkos::Profiling::pushRegion("Task_Advection_CalculateFluxes");
PARTHENON_INSTRUMENT
auto pmb = rc->GetBlockPointer();

IndexRange ib = pmb->cellbounds.GetBoundsI(IndexDomain::interior);
Expand Down Expand Up @@ -581,7 +581,6 @@ TaskStatus CalculateFluxes(std::shared_ptr<MeshBlockData<Real>> &rc) {
});
}

Kokkos::Profiling::popRegion(); // Task_Advection_CalculateFluxes
return TaskStatus::complete;
}

Expand Down
15 changes: 5 additions & 10 deletions example/particles/particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Real EstimateTimestepBlock(MeshBlockData<Real> *rc) {
// first some helper tasks

TaskStatus DestroySomeParticles(MeshBlock *pmb) {
Kokkos::Profiling::pushRegion("Task_Particles_DestroySomeParticles");
PARTHENON_INSTRUMENT

auto pkg = pmb->packages.Get("particles_package");
auto swarm = pmb->swarm_data.Get()->Get("my_particles");
Expand All @@ -156,7 +156,6 @@ TaskStatus DestroySomeParticles(MeshBlock *pmb) {
// Remove marked particles
swarm->RemoveMarkedParticles();

Kokkos::Profiling::popRegion(); // Task_Particles_DestroySomeParticles
return TaskStatus::complete;
}

Expand All @@ -172,7 +171,7 @@ TaskStatus SortParticlesIfUsingPerCellDeposition(MeshBlock *pmb) {
}

TaskStatus DepositParticles(MeshBlock *pmb) {
Kokkos::Profiling::pushRegion("Task_Particles_DepositParticles");
PARTHENON_INSTRUMENT

auto swarm = pmb->swarm_data.Get()->Get("my_particles");

Expand Down Expand Up @@ -238,12 +237,11 @@ TaskStatus DepositParticles(MeshBlock *pmb) {
});
}

Kokkos::Profiling::popRegion(); // Task_Particles_DepositParticles
return TaskStatus::complete;
}

TaskStatus CreateSomeParticles(MeshBlock *pmb, const double t0) {
Kokkos::Profiling::pushRegion("Task_Particles_CreateSomeParticles");
PARTHENON_INSTRUMENT

auto pkg = pmb->packages.Get("particles_package");
auto swarm = pmb->swarm_data.Get()->Get("my_particles");
Expand Down Expand Up @@ -351,13 +349,12 @@ TaskStatus CreateSomeParticles(MeshBlock *pmb, const double t0) {
});
}

Kokkos::Profiling::popRegion(); // Task_Particles_CreateSomeParticles
return TaskStatus::complete;
}

TaskStatus TransportParticles(MeshBlock *pmb, const StagedIntegrator *integrator,
const double t0) {
Kokkos::Profiling::pushRegion("Task_Particles_TransportParticles");
PARTHENON_INSTRUMENT

auto swarm = pmb->swarm_data.Get()->Get("my_particles");
auto pkg = pmb->packages.Get("particles_package");
Expand Down Expand Up @@ -478,7 +475,6 @@ TaskStatus TransportParticles(MeshBlock *pmb, const StagedIntegrator *integrator
});
}

Kokkos::Profiling::popRegion(); // Task_Particles_TransportParticles
return TaskStatus::complete;
}

Expand Down Expand Up @@ -520,7 +516,7 @@ TaskListStatus ParticleDriver::Step() {
// TODO(BRR) This should really be in parthenon/src... but it can't just live in Swarm
// because of the loop over blocks
TaskStatus StopCommunicationMesh(const BlockList_t &blocks) {
Kokkos::Profiling::pushRegion("Task_Particles_StopCommunicationMesh");
PARTHENON_INSTRUMENT

int num_sent_local = 0;
for (auto &block : blocks) {
Expand Down Expand Up @@ -574,7 +570,6 @@ TaskStatus StopCommunicationMesh(const BlockList_t &blocks) {
}
}

Kokkos::Profiling::popRegion(); // Task_Particles_StopCommunicationMesh
return TaskStatus::complete;
}

Expand Down
6 changes: 2 additions & 4 deletions example/poisson/poisson_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ TaskStatus SumDeltaPhi(T *du, Real *reduce_sum) {
template <typename T>
TaskStatus UpdatePhi(T *u, T *du) {
using Stencil_t = parthenon::solvers::Stencil<Real>;
Kokkos::Profiling::pushRegion("Task_Poisson_UpdatePhi");
PARTHENON_INSTRUMENT
auto pm = u->GetParentPointer();

IndexRange ib = u->GetBoundsI(IndexDomain::interior);
Expand Down Expand Up @@ -274,13 +274,12 @@ TaskStatus UpdatePhi(T *u, T *du) {
v(b, iphi, k, j, i) += dv(b, idphi, k, j, i);
});

Kokkos::Profiling::popRegion(); // Task_Poisson_UpdatePhi
return TaskStatus::complete;
}

template <typename T>
TaskStatus CheckConvergence(T *u, T *du) {
Kokkos::Profiling::pushRegion("Task_Poisson_UpdatePhi");
PARTHENON_INSTRUMENT
auto pm = u->GetParentPointer();

IndexRange ib = u->GetBoundsI(IndexDomain::interior);
Expand Down Expand Up @@ -311,7 +310,6 @@ TaskStatus CheckConvergence(T *u, T *du) {

auto status = (max_err < err_tol ? TaskStatus::complete : TaskStatus::iterate);

Kokkos::Profiling::popRegion(); // Task_Poisson_CheckConvergence
return status;
}

Expand Down
3 changes: 1 addition & 2 deletions example/sparse_advection/sparse_advection_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Real EstimateTimestepBlock(MeshBlockData<Real> *rc) {
TaskStatus CalculateFluxes(std::shared_ptr<MeshBlockData<Real>> &rc) {
using parthenon::MetadataFlag;

Kokkos::Profiling::pushRegion("Task_Advection_CalculateFluxes");
PARTHENON_INSTRUMENT
auto pmb = rc->GetBlockPointer();

IndexRange ib = pmb->cellbounds.GetBoundsI(IndexDomain::interior);
Expand Down Expand Up @@ -257,7 +257,6 @@ TaskStatus CalculateFluxes(std::shared_ptr<MeshBlockData<Real>> &rc) {
PARTHENON_REQUIRE_THROWS(pmb->pmy_mesh->ndim == 2,
"Sparse Advection example must be 2D");

Kokkos::Profiling::popRegion(); // Task_Advection_CalculateFluxes
return TaskStatus::complete;
}

Expand Down
8 changes: 2 additions & 6 deletions example/stochastic_subgrid/stochastic_subgrid_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,9 @@ AmrTag CheckRefinement(MeshBlockData<Real> *rc) {
// randomly sample an interation number for each cell from the discrete power-law
// distribution
TaskStatus ComputeNumIter(std::shared_ptr<MeshData<Real>> &md, Packages_t &packages) {
Kokkos::Profiling::pushRegion("Task_ComputeNumIter");
PARTHENON_INSTRUMENT

Kokkos::Profiling::pushRegion("Task_ComputeNumIter_pack");
auto pack = md->PackVariables(std::vector<std::string>({"num_iter"}));
Kokkos::Profiling::popRegion();

auto pkg = packages.Get("stochastic_subgrid_package");
const auto &pool =
Expand All @@ -276,7 +274,6 @@ TaskStatus ComputeNumIter(std::shared_ptr<MeshData<Real>> &md, Packages_t &packa
pack(b, v, k, j, i) = num_iter;
});

Kokkos::Profiling::popRegion(); // Task_ComputeNumIter
return TaskStatus::complete;
}

Expand Down Expand Up @@ -364,7 +361,7 @@ Real EstimateTimestepBlock(MeshBlockData<Real> *rc) {
// some field "advected" that we are pushing around.
// This routine implements all the "physics" in this example
TaskStatus CalculateFluxes(std::shared_ptr<MeshBlockData<Real>> &rc) {
Kokkos::Profiling::pushRegion("Task_Advection_CalculateFluxes");
PARTHENON_INSTRUMENT
auto pmb = rc->GetBlockPointer();
const IndexRange ib = pmb->cellbounds.GetBoundsI(IndexDomain::interior);
const IndexRange jb = pmb->cellbounds.GetBoundsJ(IndexDomain::interior);
Expand Down Expand Up @@ -467,7 +464,6 @@ TaskStatus CalculateFluxes(std::shared_ptr<MeshBlockData<Real>> &rc) {
});
}

Kokkos::Profiling::popRegion(); // Task_Advection_CalculateFluxes
return TaskStatus::complete;
}

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ add_library(parthenon
utils/error_checking.cpp
utils/hash.hpp
utils/indexer.hpp
utils/instrument.hpp
utils/loop_utils.hpp
utils/morton_number.hpp
utils/mpi_types.hpp
Expand Down
6 changes: 2 additions & 4 deletions src/amr_criteria/refinement_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,17 @@ void SetRefinement_(MeshBlockData<Real> *rc) {

template <>
TaskStatus Tag(MeshBlockData<Real> *rc) {
Kokkos::Profiling::pushRegion("Task_Tag_Block");
PARTHENON_INSTRUMENT
SetRefinement_(rc);
Kokkos::Profiling::popRegion(); // Task_Tag_Block
return TaskStatus::complete;
}

template <>
TaskStatus Tag(MeshData<Real> *rc) {
Kokkos::Profiling::pushRegion("Task_Tag_Mesh");
PARTHENON_INSTRUMENT
for (int i = 0; i < rc->NumBlocks(); i++) {
SetRefinement_(rc->GetBlockData(i).get());
}
Kokkos::Profiling::popRegion(); // Task_Tag_Mesh
return TaskStatus::complete;
}

Expand Down
3 changes: 1 addition & 2 deletions src/bvals/boundary_conditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool DoPhysicalBoundary_(const BoundaryFlag flag, const BoundaryFace face,

TaskStatus ApplyBoundaryConditionsOnCoarseOrFine(std::shared_ptr<MeshBlockData<Real>> &rc,
bool coarse) {
Kokkos::Profiling::pushRegion("Task_ApplyBoundaryConditionsOnCoarseOrFine");
PARTHENON_INSTRUMENT
using namespace boundary_cond_impl;
std::shared_ptr<MeshBlock> pmb = rc->GetBlockPointer();
Mesh *pmesh = pmb->pmy_mesh;
Expand All @@ -47,7 +47,6 @@ TaskStatus ApplyBoundaryConditionsOnCoarseOrFine(std::shared_ptr<MeshBlockData<R
}
}

Kokkos::Profiling::popRegion(); // Task_ApplyBoundaryConditionsOnCoarseOrFine
return TaskStatus::complete;
}

Expand Down
5 changes: 1 addition & 4 deletions src/bvals/bvals_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ int BoundaryBase::CreateBvalsMPITag(int lid, int bufid) {
void BoundaryBase::SearchAndSetNeighbors(
MeshBlockTree &tree, int *ranklist, int *nslist,
const std::unordered_set<LogicalLocation> &newly_refined) {
Kokkos::Profiling::pushRegion("SearchAndSetNeighbors");
PARTHENON_INSTRUMENT
MeshBlockTree *neibt;
int myox1, myox2 = 0, myox3 = 0, myfx1, myfx2, myfx3;
myfx1 = ((loc.lx1() & 1LL) == 1LL);
Expand Down Expand Up @@ -371,7 +371,6 @@ void BoundaryBase::SearchAndSetNeighbors(
}
if (block_size_.nx(X2DIR) == 1) {
SetNeighborOwnership(newly_refined);
Kokkos::Profiling::popRegion(); // SearchAndSetNeighbors
return;
}

Expand Down Expand Up @@ -506,7 +505,6 @@ void BoundaryBase::SearchAndSetNeighbors(

if (block_size_.nx(X3DIR) == 1) {
SetNeighborOwnership(newly_refined);
Kokkos::Profiling::popRegion(); // SearchAndSetNeighbors
return;
}

Expand Down Expand Up @@ -629,7 +627,6 @@ void BoundaryBase::SearchAndSetNeighbors(
}

SetNeighborOwnership(newly_refined);
Kokkos::Profiling::popRegion(); // SearchAndSetNeighbors
}

void BoundaryBase::SetNeighborOwnership(
Expand Down
17 changes: 5 additions & 12 deletions src/bvals/comms/boundary_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ using namespace loops::shorthands;

template <BoundaryType bound_type>
TaskStatus SendBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
Kokkos::Profiling::pushRegion("Task_LoadAndSendBoundBufs");
PARTHENON_INSTRUMENT

Mesh *pmesh = md->GetMeshPointer();
auto &cache = md->GetBvarsCache().GetSubCache(bound_type, true);
Expand All @@ -59,11 +59,9 @@ TaskStatus SendBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
CheckSendBufferCacheForRebuild<bound_type, true>(md);

if (nbound == 0) {
Kokkos::Profiling::popRegion(); // Task_LoadAndSendBoundBufs
return TaskStatus::complete;
}
if (other_communication_unfinished) {
Kokkos::Profiling::popRegion(); // Task_LoadAndSendBoundBufs
return TaskStatus::incomplete;
}

Expand Down Expand Up @@ -144,7 +142,6 @@ TaskStatus SendBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
buf.SendNull();
}

Kokkos::Profiling::popRegion(); // Task_LoadAndSendBoundBufs
return TaskStatus::complete;
}

Expand All @@ -155,7 +152,7 @@ SendBoundBufs<BoundaryType::nonlocal>(std::shared_ptr<MeshData<Real>> &);

template <BoundaryType bound_type>
TaskStatus StartReceiveBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
Kokkos::Profiling::pushRegion("Task_StartReceiveBoundBufs");
PARTHENON_INSTRUMENT
Mesh *pmesh = md->GetMeshPointer();
auto &cache = md->GetBvarsCache().GetSubCache(bound_type, false);
if (cache.buf_vec.size() == 0)
Expand All @@ -165,7 +162,6 @@ TaskStatus StartReceiveBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
std::for_each(std::begin(cache.buf_vec), std::end(cache.buf_vec),
[](auto pbuf) { pbuf->TryStartReceive(); });

Kokkos::Profiling::popRegion(); // Task_StartReceiveBoundBufs
return TaskStatus::complete;
}

Expand All @@ -178,7 +174,7 @@ StartReceiveBoundBufs<BoundaryType::nonlocal>(std::shared_ptr<MeshData<Real>> &)

template <BoundaryType bound_type>
TaskStatus ReceiveBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
Kokkos::Profiling::pushRegion("Task_ReceiveBoundBufs");
PARTHENON_INSTRUMENT

Mesh *pmesh = md->GetMeshPointer();
auto &cache = md->GetBvarsCache().GetSubCache(bound_type, false);
Expand Down Expand Up @@ -209,7 +205,6 @@ TaskStatus ReceiveBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
++ibound;
});
}
Kokkos::Profiling::popRegion(); // Task_ReceiveBoundBufs
if (all_received) return TaskStatus::complete;
return TaskStatus::incomplete;
}
Expand All @@ -223,7 +218,7 @@ ReceiveBoundBufs<BoundaryType::nonlocal>(std::shared_ptr<MeshData<Real>> &);

template <BoundaryType bound_type>
TaskStatus SetBounds(std::shared_ptr<MeshData<Real>> &md) {
Kokkos::Profiling::pushRegion("Task_SetInternalBoundaries");
PARTHENON_INSTRUMENT

Mesh *pmesh = md->GetMeshPointer();
auto &cache = md->GetBvarsCache().GetSubCache(bound_type, false);
Expand Down Expand Up @@ -294,7 +289,6 @@ TaskStatus SetBounds(std::shared_ptr<MeshData<Real>> &md) {
refinement::Restrict(resolved_packages, cache.prores_cache, pmb->cellbounds,
pmb->c_cellbounds);
}
Kokkos::Profiling::popRegion(); // Task_SetInternalBoundaries
return TaskStatus::complete;
}

Expand All @@ -304,7 +298,7 @@ template TaskStatus SetBounds<BoundaryType::nonlocal>(std::shared_ptr<MeshData<R

template <BoundaryType bound_type>
TaskStatus ProlongateBounds(std::shared_ptr<MeshData<Real>> &md) {
Kokkos::Profiling::pushRegion("Task_ProlongateBoundaries");
PARTHENON_INSTRUMENT

Mesh *pmesh = md->GetMeshPointer();
auto &cache = md->GetBvarsCache().GetSubCache(bound_type, false);
Expand All @@ -323,7 +317,6 @@ TaskStatus ProlongateBounds(std::shared_ptr<MeshData<Real>> &md) {
refinement::ProlongateInternal(resolved_packages, cache.prores_cache, pmb->cellbounds,
pmb->c_cellbounds);
}
Kokkos::Profiling::popRegion(); // Task_ProlongateBoundaries
return TaskStatus::complete;
}

Expand Down
Loading