Skip to content

Commit 18a0da0

Browse files
authored
Fix CUDA-aware MPI send synchronization in PGemm (deepmodeling#7688)
1 parent dba674b commit 18a0da0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

source/source_base/para_gemm.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,28 @@
33
#include "kernels/math_kernel_op.h"
44
#include "parallel_device.h"
55
#include "source_base/timer.h"
6+
7+
#if defined(__CUDA_MPI) && defined(__CUDA)
8+
#include "source_base/module_device/device_check.h"
9+
10+
#include <cuda_runtime.h>
11+
#endif
12+
613
namespace ModuleBase
714
{
15+
#if defined(__CUDA_MPI) && defined(__CUDA)
16+
template <typename Device>
17+
void synchronize_before_mpi_send()
18+
{
19+
}
20+
21+
template <>
22+
void synchronize_before_mpi_send<base_device::DEVICE_GPU>()
23+
{
24+
CHECK_CUDA(cudaStreamSynchronize(nullptr));
25+
}
26+
#endif
27+
828
template <typename T, typename Device>
929
PGemmCN<T, Device>::PGemmCN()
1030
{
@@ -192,6 +212,10 @@ void PGemmCN<T, Device>::multiply_col(const T alpha, const T* A, const T* B, con
192212
{
193213
const Device* ctx = {};
194214

215+
#if defined(__CUDA_MPI) && defined(__CUDA)
216+
synchronize_before_mpi_send<Device>();
217+
#endif
218+
195219
// send A to other procs
196220
T* isend_tmp = isend_tmp_.data();
197221
for (int ip = 0; ip < col_nproc; ip++)
@@ -313,6 +337,10 @@ void PGemmCN<T, Device>::multiply_row(const T alpha, const T* A, const T* B, con
313337
{
314338
const Device* ctx = {};
315339

340+
#if defined(__CUDA_MPI) && defined(__CUDA)
341+
synchronize_before_mpi_send<Device>();
342+
#endif
343+
316344
// Send B to other procs
317345
for (int ip = 0; ip < col_nproc; ip++)
318346
{

0 commit comments

Comments
 (0)