Skip to content

Add CUDA-aware MPI halo exchange for MPMesh - #88

Closed
Shahrear2000 wants to merge 12 commits into
SCOREC:dn/Velocity_solver_improvementfrom
Shahrear2000:pmpo_MPMesh_improved
Closed

Shahrear2000 wants to merge 12 commits into
SCOREC:dn/Velocity_solver_improvementfrom
Shahrear2000:pmpo_MPMesh_improved

Conversation

@Shahrear2000

@Shahrear2000 Shahrear2000 commented Jun 29, 2026 •

Copy link
Copy Markdown

Main changes:

  • Adds a GPU-aware MPI halo-exchange path in MPMesh, compiled when GPU_AWARE_MPI is defined.
  • Keeps CPU-GPU staged (host copy) path as fallback.
  • MPI buffers are allocated with plain cudaMalloc rather than Kokkos, because Kokkos' async memory pools are rejected by the CUDA IPC calls that Cray MPICH/GTL uses.

Build option:

  • New CMake option polyMPO_ENABLE_GPU_AWARE_MPI. It is ON by default only when Kokkos has CUDA and Cray MPICH GTL is available; otherwise OFF.
  • Override with -DpolyMPO_ENABLE_GPU_AWARE_MPI=ON/OFF.
  • When OFF (for example CPU-only builds and GitHub CI), no CUDA or Cray code is compiled and the CPU-staged path is used.

Runtime notes:

  • The GPU-aware path is used only when MPICH_GPU_SUPPORT_ENABLED=1; otherwise it falls back to the CPU-staged path.
  • The selected path is printed once on rank 0 (polyMPO halo exchange: ...).

Testing:

  • New testGPUAwareHaloExchange (4 ranks, owner → halo assignment, exact values checked).
  • Passes on Perlmutter with 4 ranks in both modes: MPICH_GPU_SUPPORT_ENABLED=1 (GPU-aware) and =0 (CPU-staged).
  • In GitHub CI the test is skipped: mpiexec -n 4 on the runner starts four independent single-rank processes, so the test exits with CTest's skip code (77).

@cwsmith cwsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see anything that was CUDA specific so I'd suggest replacing 'CUDA' in the function/structure/etc. names with 'GPU' for portability to AMD and Intel GPUs.

It looked like one of the files was mostly formatting changes. Including them in the PR makes it hard to find the critical changes.

I also complained about the function names having a suffix with a number and another with 'improved'.

There was also no test case added for this functionality. Any unit test that exercises this code would be a significant improvement.

Note, I didn't read the gpu mpi exchange code in detail. If feedback at that level is needed I can take a look.

Comment thread src/CMakeLists.txt Outdated
)

add_library(polyMPO-core ${SOURCES})
target_compile_definitions(polyMPO-core PUBLIC CUDA_AWARE_MPI)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming this 'GPU_AWARE_MPI' would be more portable (i.e., to AMD and Intel GPUs).

Comment thread src/pmpo_c.cpp Outdated
int numVertices = p_mesh->getNumVertices();
auto vtxFieldVel = p_mesh->getMeshField<polyMPO::MeshF_Vel>();
mpMesh->communicate_and_take_halo_contributions1(vtxFieldVel, numVertices, 2, 1, 1);
mpMesh->communicate_and_take_halo_contributions1_improved(vtxFieldVel, numVertices, 2, 1, 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing the '1' and replacing 'improved' with something meaningful.

Comment thread src/pmpo_MPMesh.hpp Outdated
void startCommunication();

void communicate_and_take_halo_contributions(const Kokkos::View<double**>& meshField, int nEntities, int numEntries, int mode, int op);
void communicate_and_take_halo_contributions(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this API still in use?

Comment thread src/pmpo_MPMesh.hpp Outdated
//communicateFields1(fieldData1, nEntities, numEntries, mode, recvIDVec, recvDataVec);
communicateFields1(reconVals_host, nEntities, numEntries, mode, recvIDVec, recvDataVec);

communicateFields1(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, adding a number to an API (i.e., the 1 at the end) is just going to create problems in the long term for anyone but the person who wrote them.

Comment thread src/pmpo_MPMesh.hpp Outdated
Comment on lines +200 to +203
const ViewType& fieldData,
const int numEntities,
const int numEntries,
int mode,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these formatting only changes should ideally not be part of this PR

Comment thread src/pmpo_MPMesh.hpp Outdated
}
}

Kokkos::fence();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required?

Comment thread src/pmpo_MPMesh.hpp
const int vertex = recvIDGPU(i);

for(int k = 0; k < numEntries; k++){
#ifdef POLYMPO_ASSUME_UNIQUE_HALO_CONTRIBS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describing this flag in the docstring for the function would be a good idea

@Shahrear2000
Shahrear2000 force-pushed the pmpo_MPMesh_improved branch from c3622fd to fdb365e Compare July 13, 2026 22:58
@Shahrear2000
Shahrear2000 force-pushed the pmpo_MPMesh_improved branch 3 times, most recently from 37b4533 to 4d6dcda Compare August 4, 2026 05:22
@Shahrear2000

Copy link
Copy Markdown
Author

Superseded by #90, which contains the same changes opened from the polyMPO branch sj/gpu-aware-mpi-halo-exchange. Closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants