-
Notifications
You must be signed in to change notification settings - Fork 34
/
deviceDirectCCLWrapper.h
203 lines (175 loc) · 7.81 KB
/
deviceDirectCCLWrapper.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// ---------------------------------------------------------------------
//
// 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, David M. Rogers
#if defined(DFTFE_WITH_DEVICE)
# ifndef deviceDirectCCLWrapper_h
# define deviceDirectCCLWrapper_h
# include <complex>
# include <mpi.h>
# include <DeviceTypeConfig.h>
# if defined(DFTFE_WITH_CUDA_NCCL)
# include <nccl.h>
# include <DeviceTypeConfig.h>
# elif defined(DFTFE_WITH_HIP_RCCL)
# include <rccl.h>
# include <DeviceTypeConfig.h>
# endif
namespace dftfe
{
namespace utils
{
# if defined(DFTFE_WITH_CUDA_NCCL) || defined(DFTFE_WITH_HIP_RCCL)
# define NCCLCHECK(cmd) \
do \
{ \
ncclResult_t r = cmd; \
if (r != ncclSuccess) \
{ \
printf("Failed, NCCL error %s:%d '%s'\n", \
__FILE__, \
__LINE__, \
ncclGetErrorString(r)); \
exit(EXIT_FAILURE); \
} \
} \
while (0)
# endif
/**
* @brief Wrapper class for Device Direct collective communications library.
* Adapted from
* https://code.ornl.gov/99R/olcf-cookbook/-/blob/develop/comms/nccl_allreduce.rst
*
* @author Sambit Das, David M. Rogers
*/
class DeviceCCLWrapper
{
public:
DeviceCCLWrapper();
void
init(const MPI_Comm &mpiComm, const bool useDCCL);
~DeviceCCLWrapper();
int
deviceDirectAllReduceWrapper(const float * send,
float * recv,
int size,
deviceStream_t &stream);
int
deviceDirectAllReduceWrapper(const double * send,
double * recv,
int size,
deviceStream_t &stream);
int
deviceDirectAllReduceWrapper(const std::complex<double> *send,
std::complex<double> * recv,
int size,
double * tempReal,
double * tempImag,
deviceStream_t & stream);
int
deviceDirectAllReduceWrapper(const std::complex<float> *send,
std::complex<float> * recv,
int size,
float * tempReal,
float * tempImag,
deviceStream_t & stream);
int
deviceDirectAllReduceMixedPrecGroupWrapper(const double * send1,
const float * send2,
double * recv1,
float * recv2,
int size1,
int size2,
deviceStream_t &stream);
int
deviceDirectAllReduceMixedPrecGroupWrapper(
const std::complex<double> *send1,
const std::complex<float> * send2,
std::complex<double> * recv1,
std::complex<float> * recv2,
int size1,
int size2,
double * tempReal1,
float * tempReal2,
double * tempImag1,
float * tempImag2,
deviceStream_t & stream);
inline void
deviceDirectAllReduceWrapper(const std::complex<float> *send,
std::complex<float> * recv,
int size,
deviceStream_t & stream)
{}
inline void
deviceDirectAllReduceWrapper(const std::complex<double> *send,
std::complex<double> * recv,
int size,
deviceStream_t & stream)
{}
inline void
deviceDirectAllReduceMixedPrecGroupWrapper(
const std::complex<double> *send1,
const std::complex<float> * send2,
std::complex<double> * recv1,
std::complex<float> * recv2,
int size1,
int size2,
deviceStream_t & stream)
{}
inline void
deviceDirectAllReduceWrapper(const double * send,
double * recv,
int size,
double * tempReal,
double * tempImag,
deviceStream_t &stream)
{}
inline void
deviceDirectAllReduceWrapper(const float * send,
float * recv,
int size,
float * tempReal,
float * tempImag,
deviceStream_t &stream)
{}
inline void
deviceDirectAllReduceMixedPrecGroupWrapper(const double * send1,
const float * send2,
double * recv1,
float * recv2,
int size1,
int size2,
double * tempReal1,
float * tempReal2,
double * tempImag1,
float * tempImag2,
deviceStream_t &stream)
{}
# if defined(DFTFE_WITH_CUDA_NCCL) || defined(DFTFE_WITH_HIP_RCCL)
inline static ncclUniqueId *ncclIdPtr;
inline static ncclComm_t * ncclCommPtr;
# endif
inline static bool ncclCommInit;
inline static dftfe::utils::deviceStream_t d_deviceCommStream;
inline static bool commStreamCreated;
private:
int myRank;
int totalRanks;
MPI_Comm d_mpiComm;
};
} // namespace utils
} // namespace dftfe
# endif
#endif