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( "Trying to pack data type (" << LvArray::system::demangleType< T >() << ") on device but type is not packable." );
67  return 0;
68 }
69 
70 //------------------------------------------------------------------------------
71 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_INDICES >
72 typename std::enable_if< can_memcpy< T >, localIndex >::type
73 PackByIndexDevice( buffer_unit_type * & buffer,
74  ArrayView< T const, NDIM, USD > const & var,
75  T_INDICES const & indices,
76  parallelDeviceEvents & events );
77 
78 //------------------------------------------------------------------------------
79 template< bool DO_PACKING, typename T, typename T_INDICES >
81 PackByIndexDevice( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
82  T const & GEOS_UNUSED_PARAM( var ),
83  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
84  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
85 {
86  GEOS_ERROR( "Trying to pack data type (" << LvArray::system::demangleType< T >() << ") on device but type is not packable by index." );
87  return 0;
88 }
89 
90 //------------------------------------------------------------------------------
91 template< typename T, int NDIM, int USD >
92 typename std::enable_if< can_memcpy< T >, localIndex >::type
93 UnpackDevice( buffer_unit_type const * & buffer,
94  ArrayView< T, NDIM, USD > const & var,
95  parallelDeviceEvents & events );
96 
97 //------------------------------------------------------------------------------
98 template< typename T >
100 UnpackDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
101  T & GEOS_UNUSED_PARAM( var ),
102  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
103 {
104  GEOS_ERROR( "Trying to unpack data type (" << LvArray::system::demangleType< T >() << ") on device but type is not packable." );
105  return 0;
106 }
107 
108 //------------------------------------------------------------------------------
109 template< typename T, int NDIM, int USD, typename T_INDICES >
110 typename std::enable_if< can_memcpy< T >, localIndex >::type
111 UnpackByIndexDevice ( buffer_unit_type const * & buffer,
112  ArrayView< T, NDIM, USD > const & var,
113  T_INDICES const & indices,
114  parallelDeviceEvents & events,
115  MPI_Op op=MPI_REPLACE );
116 
117 //------------------------------------------------------------------------------
118 template< typename T, typename T_INDICES >
120 UnpackByIndexDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
121  T & GEOS_UNUSED_PARAM( var ),
122  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
123  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ),
124  MPI_Op GEOS_UNUSED_PARAM( op ) )
125 {
126  GEOS_ERROR( "Trying to unpack data type (" << LvArray::system::demangleType< T >() << ") but type is not packable by index." );
127  return 0;
128 }
129 
130 
131 //------------------------------------------------------------------------------
132 template< bool DO_PACKING, typename T >
135 PackDataPointerDevice( buffer_unit_type * & buffer,
136  T const * const GEOS_RESTRICT var,
137  localIndex const length,
138  parallelDeviceEvents & events );
139 
140 //------------------------------------------------------------------------------
141 template< typename T >
144 UnpackDataPointerDevice( buffer_unit_type const * & buffer,
145  T * const GEOS_RESTRICT var,
146  localIndex const expectedLength,
147  parallelDeviceEvents & events );
148 
149 //------------------------------------------------------------------------------
150 template< bool DO_PACKING, typename T, int NDIM, int USD >
151 typename std::enable_if< can_memcpy< T >, localIndex >::type
152 PackDataDevice( buffer_unit_type * & buffer,
153  ArrayView< T const, NDIM, USD > const & var,
154  parallelDeviceEvents & events );
155 
156 //------------------------------------------------------------------------------
157 template< bool DO_PACKING, typename T >
160 PackDataDevice( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
161  T const & GEOS_UNUSED_PARAM( var ),
162  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
163 {
164  GEOS_ERROR( "Trying to pack data type (" << LvArray::system::demangleType< T >() << ") on device but type is not packable." );
165  return 0;
166 }
167 
168 //------------------------------------------------------------------------------
169 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_INDICES >
170 typename std::enable_if< can_memcpy< T >, localIndex >::type
171 PackDataByIndexDevice ( buffer_unit_type * & buffer,
172  ArrayView< T const, NDIM, USD > const & var,
173  T_INDICES const & indices,
174  parallelDeviceEvents & events );
175 
176 //------------------------------------------------------------------------------
177 template< bool DO_PACKING, typename T, typename T_INDICES >
179 PackDataByIndexDevice( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
180  T const & GEOS_UNUSED_PARAM( var ),
181  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
182  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
183 {
184  GEOS_ERROR( "Trying to pack data type (" << LvArray::system::demangleType< T >() << ") on device but type is not packable by index." );
185  return 0;
186 }
187 
188 //------------------------------------------------------------------------------
189 template< typename T, int NDIM, int USD >
190 typename std::enable_if< can_memcpy< T >, localIndex >::type
191 UnpackDataDevice( buffer_unit_type const * & buffer,
192  ArrayView< T, NDIM, USD > const & var,
193  parallelDeviceEvents & events );
194 
195 //------------------------------------------------------------------------------
196 template< typename T >
198 UnpackDataDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
199  T & GEOS_UNUSED_PARAM( var ),
200  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ) )
201 {
202  GEOS_ERROR( "Trying to unpack data type (" << LvArray::system::demangleType< T >() << ") on device but type is not packable." );
203  return 0;
204 }
205 
206 //------------------------------------------------------------------------------
207 template< typename T, int NDIM, int USD, typename T_INDICES >
208 typename std::enable_if< can_memcpy< T >, localIndex >::type
209 UnpackDataByIndexDevice ( buffer_unit_type const * & buffer,
210  ArrayView< T, NDIM, USD > const & var,
211  T_INDICES const & indices,
212  parallelDeviceEvents & events,
213  MPI_Op op=MPI_REPLACE );
214 
215 //------------------------------------------------------------------------------
216 template< typename T, typename T_INDICES >
218 UnpackDataByIndexDevice( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
219  T & GEOS_UNUSED_PARAM( var ),
220  T_INDICES const & GEOS_UNUSED_PARAM( indices ),
221  parallelDeviceEvents & GEOS_UNUSED_PARAM( events ),
222  MPI_Op GEOS_UNUSED_PARAM( op ) )
223 {
224  GEOS_ERROR( "Trying to unpack data type (" << LvArray::system::demangleType< T >() << ") but type is not packable by index." );
225  return 0;
226 }
227 
228 } // namespace bufferOps
229 } // namespace geos
230 
231 #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(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:109