@@ -29,17 +29,26 @@ namespace idefix {
2929 * if we have access to WITH_MPI_GPU_DIRECT or not.
3030 */
3131template <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 */
83100template <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
0 commit comments