forked from dftfeDevelopers/dftfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPICommunicatorP2P.h
174 lines (138 loc) · 4.98 KB
/
MPICommunicatorP2P.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// ---------------------------------------------------------------------
//
// Copyright (c) 2017-2022 The Regents of the University of Michigan and DFT-FE
// authors.
//
// This file is part of the DFT-FE code.
//
// The DFT-FE code is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the DFT-FE distribution.
//
// ---------------------------------------------------------------------
//
/*
* @author Sambit Das
*/
#ifndef dftfeMPICommunicatorP2P_h
#define dftfeMPICommunicatorP2P_h
#include <MemorySpaceType.h>
#include <MPIPatternP2P.h>
#include <TypeConfig.h>
#include <MemoryStorage.h>
#include <DataTypeOverloads.h>
#include <dftfeDataTypes.h>
#ifdef DFTFE_WITH_DEVICE
# include <DeviceTypeConfig.h>
# if defined(DFTFE_WITH_CUDA_NCCL)
# include <nccl.h>
# elif defined(DFTFE_WITH_HIP_RCCL)
# include <rccl.h>
# endif
#endif
namespace dftfe
{
namespace utils
{
namespace mpi
{
enum class communicationProtocol
{
mpiHost,
mpiDevice,
nccl
};
enum class communicationPrecision
{
single,
full
};
template <typename T>
struct singlePrecType
{
typedef T type;
};
template <>
struct singlePrecType<double>
{
typedef float type;
};
template <>
struct singlePrecType<std::complex<double>>
{
typedef std::complex<float> type;
};
template <typename ValueType, MemorySpace memorySpace>
class MPICommunicatorP2P
{
public:
MPICommunicatorP2P(
std::shared_ptr<const MPIPatternP2P<memorySpace>> mpiPatternP2P,
const size_type blockSize);
void
updateGhostValues(MemoryStorage<ValueType, memorySpace> &dataArray,
const size_type communicationChannel = 0);
void
accumulateAddLocallyOwned(
MemoryStorage<ValueType, memorySpace> &dataArray,
const size_type communicationChannel = 0);
void
updateGhostValuesBegin(MemoryStorage<ValueType, memorySpace> &dataArray,
const size_type communicationChannel = 0);
void
updateGhostValuesEnd(MemoryStorage<ValueType, memorySpace> &dataArray);
void
accumulateAddLocallyOwnedBegin(
MemoryStorage<ValueType, memorySpace> &dataArray,
const size_type communicationChannel = 0);
void
accumulateAddLocallyOwnedEnd(
MemoryStorage<ValueType, memorySpace> &dataArray);
std::shared_ptr<const MPIPatternP2P<memorySpace>>
getMPIPatternP2P() const;
int
getBlockSize() const;
void
setCommunicationPrecision(communicationPrecision precision);
private:
std::shared_ptr<const MPIPatternP2P<memorySpace>> d_mpiPatternP2P;
size_type d_blockSize;
size_type d_locallyOwnedSize;
size_type d_ghostSize;
MemoryStorage<ValueType, memorySpace> d_sendRecvBuffer;
MemoryStorage<double, memorySpace> d_tempDoubleRealArrayForAtomics;
MemoryStorage<double, memorySpace> d_tempDoubleImagArrayForAtomics;
MemoryStorage<float, memorySpace> d_tempFloatRealArrayForAtomics;
MemoryStorage<float, memorySpace> d_tempFloatImagArrayForAtomics;
MemoryStorage<typename singlePrecType<ValueType>::type, memorySpace>
d_sendRecvBufferSinglePrec;
MemoryStorage<typename singlePrecType<ValueType>::type, memorySpace>
d_ghostDataCopySinglePrec;
#ifdef DFTFE_WITH_DEVICE
std::shared_ptr<MemoryStorage<ValueType, MemorySpace::HOST_PINNED>>
d_ghostDataCopyHostPinnedPtr;
std::shared_ptr<MemoryStorage<ValueType, MemorySpace::HOST_PINNED>>
d_sendRecvBufferHostPinnedPtr;
std::shared_ptr<MemoryStorage<typename singlePrecType<ValueType>::type,
MemorySpace::HOST_PINNED>>
d_ghostDataCopySinglePrecHostPinnedPtr;
std::shared_ptr<MemoryStorage<typename singlePrecType<ValueType>::type,
MemorySpace::HOST_PINNED>>
d_sendRecvBufferSinglePrecHostPinnedPtr;
#endif // DFTFE_WITH_DEVICE
std::vector<MPI_Request> d_requestsUpdateGhostValues;
std::vector<MPI_Request> d_requestsAccumulateAddLocallyOwned;
MPI_Comm d_mpiCommunicator;
#ifdef DFTFE_WITH_DEVICE
dftfe::utils::deviceStream_t d_deviceCommStream;
#endif
communicationProtocol d_commProtocol;
communicationPrecision d_commPrecision;
};
} // namespace mpi
} // namespace utils
} // namespace dftfe
#endif // dftfeMPICommunicatorP2P_h