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

GPU Mapping #4326

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,
}
#endif

Machine::Initialize();

#ifdef AMREX_USE_GPU
// Initialize after ParmParse so that we can read inputs.
Gpu::Device::Initialize();
Expand Down Expand Up @@ -670,8 +672,6 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,
BL_PROFILE_INITPARAMS();
#endif // ifndef BL_AMRPROF

machine::Initialize();

#ifdef AMREX_USE_HYPRE
if (init_hypre) {
HYPRE_Init();
Expand Down
23 changes: 21 additions & 2 deletions Src/Base/AMReX_GpuDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

#include <AMReX_GpuDevice.H>
#include <AMReX_GpuLaunch.H>
#include <AMReX_Machine.H>
#include <AMReX_ParallelDescriptor.H>
#include <AMReX_ParmParse.H>
#include <AMReX_Print.H>
#include <AMReX_GpuLaunch.H>

#ifdef AMREX_USE_HYPRE
# include <_hypre_utilities.h>
Expand Down Expand Up @@ -208,7 +209,11 @@ Device::Initialize ()
}
else {
if (amrex::Verbose() && ParallelDescriptor::IOProcessor()) {
amrex::Warning("Multiple GPUs are visible to each MPI rank. This is usually not an issue. But this may lead to incorrect or suboptimal rank-to-GPU mapping.");
if ((Machine::name() != "nersc.perlmutter") &&
(Machine::name() != "olcf.frontier"))
{
amrex::Warning("Multiple GPUs are visible to each MPI rank. This is usually not an issue. But this may lead to incorrect or suboptimal rank-to-GPU mapping.");
}
}
if (ParallelDescriptor::NProcsPerNode() == gpu_device_count) {
device_id = ParallelDescriptor::MyRankInNode();
Expand All @@ -219,6 +224,20 @@ Device::Initialize ()
}
}

if (gpu_device_count > 1){
if (Machine::name() == "nersc.perlmutter") {
// The CPU/GPU mapping on perlmutter has the reverse order.
device_id = gpu_device_count - device_id - 1;
} else if (Machine::name() == "olcf.frontier") {
// The CPU/GPU mapping on fronter is documented at
// https://docs.olcf.ornl.gov/systems/frontier_user_guide.html
if (gpu_device_count == 8) {
constexpr std::array<int,8> gpu_order = {4,5,2,3,6,7,0,1};
device_id = gpu_order[device_id];
}
}
}

AMREX_HIP_OR_CUDA(AMREX_HIP_SAFE_CALL (hipSetDevice(device_id));,
AMREX_CUDA_SAFE_CALL(cudaSetDevice(device_id)); );

Expand Down
13 changes: 4 additions & 9 deletions Src/Base/AMReX_Machine.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
#define AMREX_MACHINE_H
#include <AMReX_Config.H>

#include <AMReX_Vector.H>
#include <string>

namespace amrex::machine {
namespace amrex::Machine {

void Initialize (); //!< called in amrex::Initialize()

#ifdef AMREX_USE_MPI
void Finalize ();
/**
* find the best topologically close neighborhood of ranks
* returns a vector of global or local rank IDs based on flag_local_ranks
*/
Vector<int> find_best_nbh (int rank_n, bool flag_local_ranks = false);
#endif

std::string const& name ();

}

Expand Down
Loading
Loading