GEOS
BufferOpsDevice.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 #ifndef GEOS_DATAREPOSITORY_BUFFEROPSDEVICE_H_
17 #define GEOS_DATAREPOSITORY_BUFFEROPSDEVICE_H_
18 
19 #include "common/DataTypes.hpp"
20 #include "codingUtilities/Utilities.hpp"
21 #include "codingUtilities/traits.hpp"
22 #include "LvArray/src/limits.hpp"
23 #include "BufferOps.hpp"
24 
25 #include "common/GEOS_RAJA_Interface.hpp"
26 
27 #include <type_traits>
28 
29 namespace geos
30 {
31 
32 namespace bufferOps
33 {
34 
35 //------------------------------------------------------------------------------
36 template< bool DO_PACKING, typename T >
39 PackPointerDevice( buffer_unit_type * & buffer,
40  T const * const GEOS_RESTRICT var,
41  localIndex const length );
42 
43 //------------------------------------------------------------------------------
44 template< typename T >
47 UnpackPointerDevice( buffer_unit_type const * & buffer,
48  T * const GEOS_RESTRICT var,
49  localIndex const expectedLength );
50 
51 //------------------------------------------------------------------------------
52 template< bool DO_PACKING, typename T, int NDIM, int USD >
53 typename std::enable_if< can_memcpy< T >, localIndex >::type
54 PackDevice( buffer_unit_type * & buffer,
55  ArrayView< T const, NDIM, USD > const & var,
56  parallelDeviceEvents & events );
57 
58 //------------------------------------------------------------------------------
59 template< bool DO_PACKING, typename T >
62 PackDevice( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
63  T const & GEOS_UNUSED_PARAM( var ),
64  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
65 {
66  GEOS_ERROR( GEOS_FMT( "Trying to pack data type ({}) on device but type is not packable.",
67  LvArray::system::demangleType< T >() ) );
68  return 0;
69 }
70 
71 //------------------------------------------------------------------------------
72 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_INDICES >
73 typename std::enable_if< can_memcpy< T >, localIndex >::type
74 PackByIndexDevice( buffer_unit_type * & buffer,
75  ArrayView< T const, NDIM, USD > const & var,
76  T_INDICES const & indices,
77  parallelDeviceEvents & events );
78 
79 //------------------------------------------------------------------------------
80 template< bool DO_PACKING, typename T, typename T_INDICES >
82 PackByIndexDevice( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
83  T const & GEOS_UNUSED_PARAM( var ),
84  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
85  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
86 {
87  GEOS_ERROR( GEOS_FMT( "Trying to pack data type ({}) on device but type is not packable by index.",
88  LvArray::system::demangleType< T >() ) );
89  return 0;
90 }
91 
92 //------------------------------------------------------------------------------
93 template< typename T, int NDIM, int USD >
94 typename std::enable_if< can_memcpy< T >, localIndex >::type
95 UnpackDevice( buffer_unit_type const * & buffer,
96  ArrayView< T, NDIM, USD > const & var,
97  parallelDeviceEvents & events );
98 
99 //------------------------------------------------------------------------------
100 template< typename T >
102 UnpackDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
103  T & GEOS_UNUSED_PARAM( var ),
104  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
105 {
106  GEOS_ERROR( GEOS_FMT( "Trying to unpack data type ({}) on device but type is not packable.",
107  LvArray::system::demangleType< T >() ) );
108  return 0;
109 }
110 
111 //------------------------------------------------------------------------------
112 template< typename T, int NDIM, int USD, typename T_INDICES >
113 typename std::enable_if< can_memcpy< T >, localIndex >::type
114 UnpackByIndexDevice ( buffer_unit_type const * & buffer,
115  ArrayView< T, NDIM, USD > const & var,
116  T_INDICES const & indices,
117  parallelDeviceEvents & events,
118  MPI_Op op=MPI_REPLACE );
119 
120 //------------------------------------------------------------------------------
121 template< typename T, typename T_INDICES >
123 UnpackByIndexDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
124  T & GEOS_UNUSED_PARAM( var ),
125  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
126  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ),
127  MPI_Op GEOS_UNUSED_PARAM( op ) )
128 {
129  GEOS_ERROR( GEOS_FMT( "Trying to unpack data type ({}) but type is not packable by index.",
130  LvArray::system::demangleType< T >() ) );
131  return 0;
132 }
133 
134 
135 //------------------------------------------------------------------------------
136 template< bool DO_PACKING, typename T >
139 PackDataPointerDevice( buffer_unit_type * & buffer,
140  T const * const GEOS_RESTRICT var,
141  localIndex const length,
142  parallelDeviceEvents & events );
143 
144 //------------------------------------------------------------------------------
145 template< typename T >
148 UnpackDataPointerDevice( buffer_unit_type const * & buffer,
149  T * const GEOS_RESTRICT var,
150  localIndex const expectedLength,
151  parallelDeviceEvents & events );
152 
153 //------------------------------------------------------------------------------
154 template< bool DO_PACKING, typename T, int NDIM, int USD >
155 typename std::enable_if< can_memcpy< T >, localIndex >::type
156 PackDataDevice( buffer_unit_type * & buffer,
157  ArrayView< T const, NDIM, USD > const & var,
158  parallelDeviceEvents & events );
159 
160 //------------------------------------------------------------------------------
161 template< bool DO_PACKING, typename T >
164 PackDataDevice( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
165  T const & GEOS_UNUSED_PARAM( var ),
166  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
167 {
168  GEOS_ERROR( GEOS_FMT( "Trying to pack data type ({}) on device but type is not packable.",
169  LvArray::system::demangleType< T >() ) );
170  return 0;
171 }
172 
173 //------------------------------------------------------------------------------
174 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_INDICES >
175 typename std::enable_if< can_memcpy< T >, localIndex >::type
176 PackDataByIndexDevice ( buffer_unit_type * & buffer,
177  ArrayView< T const, NDIM, USD > const & var,
178  T_INDICES const & indices,
179  parallelDeviceEvents & events );
180 
181 //------------------------------------------------------------------------------
182 template< bool DO_PACKING, typename T, typename T_INDICES >
184 PackDataByIndexDevice( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
185  T const & GEOS_UNUSED_PARAM( var ),
186  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
187  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
188 {
189  GEOS_ERROR( GEOS_FMT( "Trying to pack data type ({}) on device but type is not packable by index.",
190  LvArray::system::demangleType< T >() ) );
191  return 0;
192 }
193 
194 //------------------------------------------------------------------------------
195 template< typename T, int NDIM, int USD >
196 typename std::enable_if< can_memcpy< T >, localIndex >::type
197 UnpackDataDevice( buffer_unit_type const * & buffer,
198  ArrayView< T, NDIM, USD > const & var,
199  parallelDeviceEvents & events );
200 
201 //------------------------------------------------------------------------------
202 template< typename T >
204 UnpackDataDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
205  T & GEOS_UNUSED_PARAM( var ),
206  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
207 {
208  GEOS_ERROR( GEOS_FMT( "Trying to unpack data type ({}) on device but type is not packable.",
209  LvArray::system::demangleType< T >() ) );
210  return 0;
211 }
212 
213 //------------------------------------------------------------------------------
214 template< typename T, int NDIM, int USD, typename T_INDICES >
215 typename std::enable_if< can_memcpy< T >, localIndex >::type
216 UnpackDataByIndexDevice ( buffer_unit_type const * & buffer,
217  ArrayView< T, NDIM, USD > const & var,
218  T_INDICES const & indices,
219  parallelDeviceEvents & events,
220  MPI_Op op=MPI_REPLACE );
221 
222 //------------------------------------------------------------------------------
223 template< typename T, typename T_INDICES >
225 UnpackDataByIndexDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
226  T & GEOS_UNUSED_PARAM( var ),
227  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
228  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ),
229  MPI_Op GEOS_UNUSED_PARAM( op ) )
230 {
231  GEOS_ERROR( GEOS_FMT( "Trying to unpack data type ({}) but type is not packable by index.",
232  LvArray::system::demangleType< T >() ) );
233  return 0;
234 }
235 
236 } // namespace bufferOps
237 } // namespace geos
238 
239 #endif // GEOS_DATAREPOSITORY_BUFFEROPSDEVICE_H_
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
#define GEOS_RESTRICT
preprocessor variable for the C99 restrict keyword for use with pointers
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:72
#define GEOS_ERROR(...)
Raise a hard error and terminate the program.
Definition: Logger.hpp:226
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:108