Skip to content

Commit f6bf6e2

Browse files
committed
gpu-direct: fix nvcc warning about host function used in device one
1 parent f24de7d commit f6bf6e2

4 files changed

Lines changed: 57 additions & 25 deletions

File tree

src/mpi/buffer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ class Buffer {
3131
}
3232

3333
void* deviceData() {
34-
return(array.data());
34+
return(array.deviceView().data());
3535
}
3636

3737
IdefixArray1D<real> & deviceView(void) {
38-
return this->array;
38+
return this->array.deviceView();
3939
}
4040

4141
idefix::IdefixCommArray1D<real> & commView(void) {
4242
return this->array;
4343
}
4444

4545
int Size() {
46-
return(array.size());
46+
return(array.deviceView().size());
4747
}
4848

4949
void ResetPointer() {
@@ -62,7 +62,7 @@ class Buffer {
6262
const int kend = box[KDIR][1];
6363
const int offset = this->pointer;
6464

65-
auto arr = this->array;
65+
auto arr = this->array.deviceView();
6666
idefix_for("LoadBuffer3D",kbeg,kend,jbeg,jend,ibeg,iend,
6767
KOKKOS_LAMBDA (int k, int j, int i) {
6868
arr(i-ibeg + (j-jbeg)*ni + (k-kbeg)*ninj + offset ) = in(k,j,i);

src/mpi/commArray.hpp

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@ namespace idefix {
2929
* if we have access to WITH_MPI_GPU_DIRECT or not.
3030
*/
3131
template <class T>
32-
class IdefixCommArrayGpuDirect : public T {
32+
class IdefixCommArrayGpuDirect {
3333
public:
34-
//inherit constructors
35-
using T::T;
34+
template <class... Args>
35+
explicit IdefixCommArrayGpuDirect(Args... args)
36+
:deviceArray(args...)
37+
{}
3638

3739
/**
3840
* Accès it as a simple device view for usiage in kokkos kernels
3941
* (because need to not carry the host part).
4042
*/
4143
T & deviceView(void) {
42-
return *this;
44+
return this->deviceArray;
45+
}
46+
47+
/**
48+
* Acces it as a simple communication view for usiage in communication routines.
49+
*/
50+
T commView(void) {
51+
return this->deviceArray;
4352
}
4453

4554
/**
@@ -71,8 +80,16 @@ class IdefixCommArrayGpuDirect : public T {
7180
* depending on the WITH_MPI_GPU_DIRECT configuration.
7281
*/
7382
void * commData(void) {
74-
return this->data();
83+
return this->deviceArray.data();
7584
}
85+
86+
private:
87+
/**
88+
* Device buffer containing the device side of the data to use for communications.
89+
* This where the computation are done. Then it is transfered to/from the communication
90+
* buffer if needed.
91+
*/
92+
T deviceArray;
7693
};
7794

7895
/**
@@ -81,49 +98,59 @@ class IdefixCommArrayGpuDirect : public T {
8198
* if we have access to WITH_MPI_GPU_DIRECT or not.
8299
*/
83100
template <class T>
84-
class IdefixCommArrayNoGpuDirect : public T {
101+
class IdefixCommArrayNoGpuDirect {
85102
public:
86-
//inherit constructors
87-
using T::T;
103+
template <class... Args>
104+
explicit IdefixCommArrayNoGpuDirect(Args... args)
105+
:deviceArray(args...)
106+
,commArray(initCommArray(this->deviceArray))
107+
{}
88108

89109
/**
90-
* Accès it as a simple device view for usiage in kokkos kernels
110+
* Acces it as a simple device view for usiage in kokkos kernels
91111
* (because need to not carry the host part).
92112
*/
93113
T & deviceView(void) {
94-
return *this;
114+
return this->deviceArray;
115+
}
116+
117+
/**
118+
* Acces it as a simple communication view for usiage in communication routines.
119+
*/
120+
typename T::host_mirror_type & commView(void) {
121+
return this->commArray;
95122
}
96123

97124
/**
98125
* If needed, transfers the data from the device to the host to be ready to make
99126
* a communication.
100127
*/
101128
void syncCommData(void) {
102-
Kokkos::deep_copy(this->commArray, *this);
129+
Kokkos::deep_copy(this->commArray, this->deviceArray);
103130
}
104131

105132
/**
106133
* If needed, transfers the data from the device to the host to be ready to make
107134
* a communication.
108135
*/
109136
void syncCommDataAsync(void) {
110-
Kokkos::deep_copy(Kokkos::DefaultExecutionSpace(), this->commArray, *this);
137+
Kokkos::deep_copy(Kokkos::DefaultExecutionSpace(), this->commArray, this->deviceArray);
111138
}
112139

113140
/**
114141
* If needed, transerts the data to the device after a communication to be ready
115142
* to use it.
116143
*/
117144
void syncDeviceData(void) {
118-
Kokkos::deep_copy(*this, this->commArray);
145+
Kokkos::deep_copy(this->deviceArray, this->commArray);
119146
}
120147

121148
/**
122149
* If needed, transerts the data to the device after a communication to be ready
123150
* to use it.
124151
*/
125152
void syncDeviceDataAsync(void) {
126-
Kokkos::deep_copy(Kokkos::DefaultExecutionSpace(), *this, this->commArray);
153+
Kokkos::deep_copy(Kokkos::DefaultExecutionSpace(), this->deviceArray, this->commArray);
127154
}
128155

129156
/**
@@ -147,11 +174,17 @@ class IdefixCommArrayNoGpuDirect : public T {
147174
}
148175

149176
private:
177+
/**
178+
* Device buffer containing the device side of the data to use for communications.
179+
* This where the computation are done. Then it is transfered to/from the communication
180+
* buffer if needed.
181+
*/
182+
T deviceArray;
150183
/**
151184
* Buffer to contain a copy of the data on host if required. If WITH_MPI_GPU_DIRECT
152185
* is enabled it directly points the device buffer as no copy is required.
153186
*/
154-
typename T::host_mirror_type commArray{initCommArray(*this)};
187+
typename T::host_mirror_type commArray;
155188
};
156189

157190
#ifdef WITH_MPI_GPU_DIRECT

src/mpi/mpi.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ void Mpi::CheckConfig() {
131131

132132
// Run-time check that we can do a reduce on device arrays
133133
idefix::IdefixCommArray1D<int64_t> src("MPIChecksrc",1);
134-
IdefixArray1D<int64_t>::host_mirror_type srcHost = Kokkos::create_mirror_view(src);
134+
IdefixArray1D<int64_t>::host_mirror_type srcHost = Kokkos::create_mirror_view(src.deviceView());
135135

136136
if(idfx::prank == 0) {
137137
srcHost(0) = 0;
138-
Kokkos::deep_copy(src, srcHost);
138+
Kokkos::deep_copy(src.deviceView(), srcHost);
139139
}
140140

141141
if(idfx::psize > 1) {
@@ -160,9 +160,9 @@ void Mpi::CheckConfig() {
160160
} else {
161161
ierrRecv = idefix::MPI_Recv(src, 1, MPI_INT64_T, idfx::prank-1, 1, MPI_COMM_WORLD, &status);
162162
// Add our own rank to the data
163-
Kokkos::deep_copy(srcHost, src);
163+
Kokkos::deep_copy(srcHost, src.deviceView());
164164
srcHost(0) += idfx::prank;
165-
Kokkos::deep_copy(src, srcHost);
165+
Kokkos::deep_copy(src.deviceView(), srcHost);
166166
ierrSend = idefix::MPI_Send(src, 1, MPI_INT64_T, (idfx::prank+1)%idfx::psize, 1,
167167
MPI_COMM_WORLD);
168168
}
@@ -199,7 +199,7 @@ void Mpi::CheckConfig() {
199199
}
200200

201201
// Check that we have the proper end result
202-
Kokkos::deep_copy(srcHost, src);
202+
Kokkos::deep_copy(srcHost, src.deviceView());
203203
int64_t size = static_cast<int64_t>(idfx::psize);
204204
int64_t rank = static_cast<int64_t>(idfx::prank);
205205
int64_t result = rank == 0 ? size*(size-1)/2 : rank*(rank+1)/2;

src/mpi/mpiView.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include "idefix.hpp"
2020
#include "commArray.hpp"
21-
#include "buffer.hpp"
2221

2322
namespace idefix {
2423

0 commit comments

Comments
 (0)